告警清理

Signed-off-by:wenlong12 <wenlong12@huawei.com>

Signed-off-by: wenlong12 <wenlong12@huawei.com>
This commit is contained in:
wenlong12 2024-11-14 19:02:51 +08:00
parent 5da5a213eb
commit 6933aa9204
10 changed files with 53 additions and 11 deletions

View File

@ -310,6 +310,7 @@ bool IsBeta();
bool IsAllowProfilingUid();
bool IsHiviewCall();
bool PowerOfTwo(uint64_t n);
bool IsNumberic(const std::string& str);
const std::string HMKERNEL = "HongMeng";

View File

@ -14,6 +14,7 @@
*/
#include "hiperf_client_napi.h"
#include <cstdio>
#include <sstream>
#include <string>
#include "hiperf_hilog.h"
#include "hiperf_client.h"
@ -51,6 +52,20 @@ static std::vector<std::string> StringSplit(std::string source, const std::strin
return result;
}
static bool IsNumberic(const std::string& str)
{
std::istringstream iss(str);
int number;
char trailingCharacter;
if (!(iss >> number)) {
return false;
}
if (iss >> trailingCharacter) {
return false;
}
return true;
}
static std::vector<int> StringSplitToInt(std::string source, const std::string &split = ",")
{
size_t pos = 0;
@ -60,13 +75,13 @@ static std::vector<int> StringSplitToInt(std::string source, const std::string &
while ((pos = source.find(split)) != std::string::npos) {
// split
std::string token = source.substr(0, pos);
if (!token.empty()) {
if (IsNumberic(token)) {
result.push_back(std::stoi(token));
}
source.erase(0, pos + split.length());
}
// add last token
if (!source.empty()) {
if (IsNumberic(source)) {
result.push_back(std::stoi(source));
}
return result;
@ -85,7 +100,10 @@ static std::string GetJsStringFromOption(const napi_env &env, const napi_callbac
char value[PATH_MAX] = {0};
size_t valueLen = 0;
napi_get_value_string_utf8(env, args[0], value, sizeof(value), &valueLen);
if (napi_get_value_string_utf8(env, args[0], value, sizeof(value), &valueLen) != napi_ok) {
HIPERF_HILOGE(MODULE_JS_NAPI, "napi_get_value_string_utf8 failed.");
return "";
}
HIPERF_HILOGD(MODULE_JS_NAPI, "%{public}s", value);
return std::string(value);
}

View File

@ -215,7 +215,7 @@ int ReportProtobufFileReader::Read(void *buffer, int size)
return protobufFileStream_->gcount();
}
printf("read file %d bytes failed %s : %s\n", size, fileName_.c_str(), readErr.what());
HLOGW("read file %d bytes failed %s : %s\n", size, fileName_.c_str(), readErr.what());
}
} else {
printf("no file open for read (request %d bytes).\n", size);

View File

@ -41,7 +41,7 @@ size_t RingBuffer::GetFreeSize() const
uint8_t *RingBuffer::AllocForWrite(size_t writeSize)
{
if (buf_ == nullptr || buf_.get() == nullptr) {
if (buf_ == nullptr) {
return nullptr;
}
size_t writeHead = head_.load(std::memory_order_relaxed);

View File

@ -592,7 +592,7 @@ void SubCommandDump::SetHM()
if (isHM_) {
pid_t devhost = -1;
std::string str = reader_->GetFeatureString(FEATURE::HIPERF_HM_DEVHOST);
if (str != EMPTY_STRING) {
if (IsNumberic(str)) {
devhost = std::stoll(str);
}
vr_.SetDevhostPid(devhost);

View File

@ -181,7 +181,7 @@ bool SubCommandRecord::GetSpeOptions()
for (auto item: valueExpressions) {
std::vector<std::string> expressions = StringSplit(item, "=");
size_t itemNum = 2;
if (expressions.size() == itemNum) {
if (expressions.size() == itemNum && IsNumberic(expressions[1])) {
std::string name = expressions[0];
unsigned long long num = std::stoull(expressions[1]);
if (speOptMap_.find(name) != speOptMap_.end()) {
@ -397,7 +397,12 @@ bool SubCommandRecord::CheckDataLimitOption()
bool SubCommandRecord::CheckSelectCpuPidOption()
{
if (!selectCpus_.empty()) {
int maxCpuid = sysconf(_SC_NPROCESSORS_CONF) - 1;
int cpuCount = sysconf(_SC_NPROCESSORS_CONF);
if (cpuCount == -1) {
printf("sysconf failed.\n");
return false;
}
int maxCpuid = cpuCount - 1;
for (auto cpu : selectCpus_) {
if (cpu < 0 || cpu > maxCpuid) {
printf("Invalid -c value '%d', the CPU ID should be in 0~%d \n", cpu, maxCpuid);

View File

@ -360,7 +360,7 @@ void SubCommandReport::LoadEventDesc()
{
const PerfFileSection *featureSection =
recordFileReader_->GetFeatureSection(FEATURE::EVENT_DESC);
CHECK_TRUE(featureSection == nullptr, NO_RETVAL, 0, "");
CHECK_TRUE(featureSection == nullptr, NO_RETVAL, 1, "featureSection invalid");
const PerfFileSectionEventDesc &sectionEventdesc =
*static_cast<const PerfFileSectionEventDesc *>(featureSection);
HLOGV("Event descriptions: %zu", sectionEventdesc.eventDesces_.size());

View File

@ -351,7 +351,7 @@ std::string SubCommandStat::GetCommentConfigName(
const std::unique_ptr<PerfEvents::CountEvent> &countEvent, std::string eventName)
{
std::string commentConfigName = "";
CHECK_TRUE(countEvent == nullptr || eventName.length() == 0, commentConfigName, 0, "");
CHECK_TRUE(countEvent == nullptr || eventName.length() == 0, commentConfigName, 1, "countEvent is nullptr");
if (countEvent->userOnly) {
commentConfigName = eventName + ":u";
} else if (countEvent->kernelOnly) {

View File

@ -102,6 +102,10 @@ std::string SymbolsFile::SearchReadableFile(const std::vector<std::string> &sear
return filePath;
}
for (auto searchPath : searchPaths) {
if (searchPath.empty()) {
HLOGW("searchPath is empty.");
continue;
}
if (searchPath.back() != PATH_SEPARATOR) {
searchPath += PATH_SEPARATOR;
}
@ -307,7 +311,7 @@ private:
bool GetHDRSectionInfo(uint64_t &ehFrameHdrElfOffset, uint64_t &fdeTableElfOffset,
uint64_t &fdeTableSize) override
{
CHECK_TRUE(elfFile_ == nullptr, false, 0, "");
CHECK_TRUE(elfFile_ == nullptr, false, 1, "elfFile_ is nullptr");
ShdrInfo shinfo;
if (!elfFile_->GetSectionInfo(shinfo, ".eh_frame_hdr")) {
return false;

View File

@ -844,6 +844,20 @@ bool IsHiviewCall()
return false;
#endif
}
bool IsNumberic(const std::string& str)
{
std::istringstream iss(str);
int number;
char trailingCharacter;
if (!(iss >> number)) {
return false;
}
if (iss >> trailingCharacter) {
return false;
}
return true;
}
} // namespace HiPerf
} // namespace Developtools
} // namespace OHOS