fix OH3.1 hiperf codecheck issue

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

Signed-off-by: wenlong12 <wenlong12@huawei.com>
This commit is contained in:
wenlong12 2022-03-09 17:52:17 +08:00
parent 6be68d66fe
commit a2129d07ec
39 changed files with 156 additions and 117 deletions

View File

@ -141,7 +141,7 @@ hiperf\demo\cpp\hiperf_example_cmd.cpp
```
./hiperf_example_cmd --help
this is a demo test comand
this is a demo test command
Use the following commands to simulate different scenarios
--help
this page

View File

@ -362,7 +362,7 @@ void WaitStart()
void Help()
{
printf("this is a demo test comand\n");
printf("this is a demo test command\n");
printf(" Use the following commands to simulate different scenarios\n");
printf(" --help\n");
printf(" this page\n");
@ -389,7 +389,7 @@ void Help()
printf(" --boundcpu <cpu>\n");
printf(" the process will bound to <cpu>\n");
printf(" --sleep <milliseconds>\n");
printf(" threads will sleep <milliseconds> per second, defaut is 0.\n");
printf(" threads will sleep <milliseconds> per second, default is 0.\n");
}
bool GetIntFromArg(std::vector<std::string> &args, int &value)
@ -399,7 +399,7 @@ bool GetIntFromArg(std::vector<std::string> &args, int &value)
value = std::stoi(args[0]);
args.erase(args.begin());
} else {
printf("unknow format '%s'\n", args[0].c_str());
printf("unknown format '%s'\n", args[0].c_str());
return false;
}
}
@ -472,7 +472,7 @@ USED_FUNCTION int main(int argc, char *argv[])
} else if (GetBoolFromArg(args, "--nofunc", option.nofunc)) {
continue;
} else {
printf("unknow format '%s'\n", args[0].c_str());
printf("unknown format '%s'\n", args[0].c_str());
return -1;
}
}
@ -484,7 +484,7 @@ USED_FUNCTION int main(int argc, char *argv[])
if (sched_setaffinity(0, sizeof(cpu_set_t), &mask) == -1) {
char errInfo[ERRINFOLEN] = { 0 };
strerror_r(errno, errInfo, ERRINFOLEN);
printf("Set CPU(%d) affinity failue, ERROR:%s\n", option.boundCpu, errInfo);
printf("Set CPU(%d) affinity failure, ERROR:%s\n", option.boundCpu, errInfo);
}
}
if (!option.noWait) {

View File

@ -41,7 +41,7 @@ namespace HiPerf {
const int MAX_CALL_FRAME_EXPAND_CYCLE = 10;
const size_t MAX_CALL_FRAME_EXPAND_CACHE_SIZE = 10;
const size_t MAX_CALL_FRAME_UNWIND_SIZE = 256;
// if ip is 0 , 1 both not usefule
// if ip is 0 , 1 both not useful
const uint64_t BAD_IP_ADDRESS = 2;
#if HAVE_LIBUNWIND

View File

@ -27,7 +27,7 @@
#define FILENAME \
(__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__)
#define FORMATED(fmt, ...) \
#define FORMATTED(fmt, ...) \
"[%" HILOG_PUBLIC "s:%" HILOG_PUBLIC "d] %" HILOG_PUBLIC "s# " fmt HILOG_NEWLINE, FILENAME, \
__LINE__, __FUNCTION__, ##__VA_ARGS__
@ -73,22 +73,22 @@ static constexpr OHOS::HiviewDFX::HiLogLabel HIPERF_HILOG_LABLE[] = {
// In order to improve performance, do not check the module range
#define HIPERF_HILOGF(module, ...) \
(void)OHOS::HiviewDFX::HiLog::Fatal(HIPERF_HILOG_LABLE[module], FORMATED(__VA_ARGS__))
(void)OHOS::HiviewDFX::HiLog::Fatal(HIPERF_HILOG_LABLE[module], FORMATTED(__VA_ARGS__))
#define HIPERF_HILOGE(module, ...) \
(void)OHOS::HiviewDFX::HiLog::Error(HIPERF_HILOG_LABLE[module], FORMATED(__VA_ARGS__))
(void)OHOS::HiviewDFX::HiLog::Error(HIPERF_HILOG_LABLE[module], FORMATTED(__VA_ARGS__))
#define HIPERF_HILOGW(module, ...) \
(void)OHOS::HiviewDFX::HiLog::Warn(HIPERF_HILOG_LABLE[module], FORMATED(__VA_ARGS__))
(void)OHOS::HiviewDFX::HiLog::Warn(HIPERF_HILOG_LABLE[module], FORMATTED(__VA_ARGS__))
#define HIPERF_HILOGI(module, ...) \
(void)OHOS::HiviewDFX::HiLog::Info(HIPERF_HILOG_LABLE[module], FORMATED(__VA_ARGS__))
(void)OHOS::HiviewDFX::HiLog::Info(HIPERF_HILOG_LABLE[module], FORMATTED(__VA_ARGS__))
#define HIPERF_HILOGD(module, ...) \
(void)OHOS::HiviewDFX::HiLog::Debug(HIPERF_HILOG_LABLE[module], FORMATED(__VA_ARGS__))
(void)OHOS::HiviewDFX::HiLog::Debug(HIPERF_HILOG_LABLE[module], FORMATTED(__VA_ARGS__))
#else
#define HIPERF_HILOGF(module, ...) printf(FORMATED(__VA_ARGS__))
#define HIPERF_HILOGE(module, ...) printf(FORMATED(__VA_ARGS__))
#define HIPERF_HILOGW(module, ...) printf(FORMATED(__VA_ARGS__))
#define HIPERF_HILOGI(module, ...) printf(FORMATED(__VA_ARGS__))
#define HIPERF_HILOGD(module, ...) printf(FORMATED(__VA_ARGS__))
#define HIPERF_HILOGF(module, ...) printf(FORMATTED(__VA_ARGS__))
#define HIPERF_HILOGE(module, ...) printf(FORMATTED(__VA_ARGS__))
#define HIPERF_HILOGW(module, ...) printf(FORMATTED(__VA_ARGS__))
#define HIPERF_HILOGI(module, ...) printf(FORMATTED(__VA_ARGS__))
#define HIPERF_HILOGD(module, ...) printf(FORMATTED(__VA_ARGS__))
#endif // CONFIG_NO_HILOG

View File

@ -91,7 +91,7 @@ DLL_EXPORT const char *CDECL ReportGetBuildId(const char *elfPath);
// will return the arch in this elf
// now support "arm","arm64","x86","x86_64"
// return machine id(const char in ascii) when not support
// return "unknow" when failed happend
// return "unknown" when failed happend
DLL_EXPORT const char *CDECL ReportGetElfArch(const char *elfPath);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@ -81,7 +81,7 @@ bool GetOptionValue(argsVector &args, std::string optionName, T &value)
// if the last one we request is empty , we remove it
localValues.pop_back();
// nothing more needed
// we dont allow empty value
// we don't allow empty value
break;
}
}
@ -105,9 +105,9 @@ bool GetOptionValue(argsVector &args, std::string optionName, T &value)
return true; // not found but also not error
} else {
it = args.erase(it);
// some specail case
// some special case
if constexpr (std::is_same<T, bool>::value) {
// for bool we dont need get value.
// for bool we don't need get value.
// this always return true
GetValueFromString(optionName, optionName, value);
return true;
@ -121,7 +121,7 @@ bool GetOptionValue(argsVector &args, std::string optionName, T &value)
args.erase(it);
return true;
} else {
// have value but conver failed.
// have value but convert failed.
printf("incorrect option value '%s'. View the usage with the --help option.\n",
(*it).c_str());
return false;

View File

@ -312,7 +312,7 @@ public:
lostNonSamples = lostNonSamples_;
}
// review: remvoe this funcion.
// review: remove this function.
static const std::string GetStaticConfigName(perf_type_id type_id, __u64 config_id)
{
auto typeConfigs = TYPE_CONFIGS.find(type_id);
@ -474,7 +474,7 @@ private:
SampleStackType sampleStackType_ = SampleStackType::NONE;
uint32_t dwarfSampleStackSize_ = MAX_SAMPLE_STACK_SIZE;
// read records from the ring buffer singlton
// read records from the ring buffer singleton
void ReadRecordFromBuffer();
void ReadRecordFromBufferThread();

View File

@ -521,7 +521,7 @@ private:
const std::string TEXT_RESET = "\033[0m";
const unsigned int ConsoleDefaultWidth = 80;
// sometime caller dont give the option
// sometime caller don't give the option
ReportOption defaultOption_;
std::vector<std::string> displayKeyNames_;

View File

@ -66,7 +66,7 @@ public:
" --exclude-hiperf\n"
" Don't record events issued by hiperf itself.\n"
" -c <cpuid>[<,cpuid>]...\n"
" cpuid shoule be 0,1,2...\n"
" cpuid should be 0,1,2...\n"
" Limit the CPU that collects data.\n"
" 0 means cpu0, 1 means cpu1 ...\n"
" --cpu-limit <percent>\n"
@ -74,7 +74,7 @@ public:
" percent is in range [1-100], default is 25.\n"
" -d <sec>\n"
" stop in <sec> seconds. floating point number. seconds is in range [0.100-10000.0]\n"
" defalut is 10000.0\n"
" default is 10000.0\n"
" -f <freq>\n"
" Set event sampling frequency. default is 4000 samples every second.\n"
" check /proc/sys/kernel/perf_event_max_sample_rate for maximum allowed frequency\n"

View File

@ -68,9 +68,9 @@ public:
" default file name is perf.data.\n"
" --diff <target file>\n"
" show the diff result from -i to -diff .\n"
" exapmle: \"report -i a.data --diff b.data\"\n"
" example: \"report -i a.data --diff b.data\"\n"
" --branch\n"
" show the branch from address instead of ip adress\n"
" show the branch from address instead of ip address\n"
" --<keys> <keyname1>[,keyname2][,...]\n"
" select able keys: comms,pids,tids,dsos,funcs,from_dsos,from_funcs\n"
" example: --comms hiperf\n"
@ -97,7 +97,7 @@ public:
" --hide_count\n"
" will not show count in report\n"
"\n"
), recordFile_ {"perf.data", ""} // dafault file path is perf.data
), recordFile_ {"perf.data", ""} // default file path is perf.data
// clang-format on
{
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@ -37,13 +37,13 @@ public:
" CAP_SYS_ADMIN capability or a\n"
" /proc/sys/kernel/perf_event_paranoid value of less than 1.\n"
" -c <cpuid>[<,cpuid>]\n"
" cpuid shoule be 0,1,2...\n"
" cpuid should be 0,1,2...\n"
" Limit the CPU that collects data.\n"
" 0 means cpu0, 1 means cpu1 ...\n"
" -d <sec>\n"
" stop in <sec> seconds.\n"
" floating point number.\n"
" defalut is 10000.0\n"
" default is 10000.0\n"
" -i <ms>\n"
" print stat info every <ms>.\n"
" -e event1[:<u|k>][,event1[:<u|k>]]...\n"

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@ -261,7 +261,7 @@ public:
symbolsLoaded_ = true;
return false;
};
// load debug infor for unwind
// load debug info for unwind
virtual bool LoadDebugInfo([[maybe_unused]] const std::string &symbolFilePath = EMPTY_STRING)
{
HLOGV("virtual dummy function called");

View File

@ -223,12 +223,12 @@ std::string PlatformPathConvert(const std::string &path);
uint32_t RoundUp(uint32_t x, const int align);
// data convert funcion
// data convert function
template<class T>
std::string ToHex(const T &source, int size = sizeof(T), bool perfix = false)
std::string ToHex(const T &source, int size = sizeof(T), bool prefix = false)
{
std::stringstream ss;
if (perfix) {
if (prefix) {
ss << "0x";
}
ss << std::hex << std::setw(BYTE_PRINT_WIDTH * size) << std::setfill('0') << (uint64_t)source;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@ -115,7 +115,7 @@ public:
std::chrono::microseconds threadParseMapsTimes_ = std::chrono::microseconds::zero();
std::chrono::microseconds threadCreateMmapTimes_ = std::chrono::microseconds::zero();
#endif
const bool loadSymboleWhenNeeded_ = true; // thie is a feature config
const bool loadSymboleWhenNeeded_ = true; // this is a feature config
private:
bool disableUnwind_ = true;

View File

@ -156,7 +156,7 @@ int CallStack::FindUnwindTable(SymbolsFile *symbolsFile, const MemMapItem &mmap,
UnwindInfo *unwindInfoPtr, unw_addr_space_t as, unw_word_t ip,
unw_proc_info_t *pi, int need_unwind_info, void *arg)
{
HLOGM("try seach debug info at %s", symbolsFile->filePath_.c_str());
HLOGM("try search debug info at %s", symbolsFile->filePath_.c_str());
auto &dynInfoProcessMap = unwindInfoPtr->callStack.unwindDynInfoMap_;
// all the thread in same process have same mmap and symbols
if (dynInfoProcessMap.find(unwindInfoPtr->thread.pid_) == dynInfoProcessMap.end()) {
@ -166,7 +166,10 @@ int CallStack::FindUnwindTable(SymbolsFile *symbolsFile, const MemMapItem &mmap,
// find use dso name as key
if (dynFileMap.find(symbolsFile->filePath_) == dynFileMap.end()) {
unw_dyn_info_t newdi;
memset_s(&newdi, sizeof(unw_dyn_info_t), 0, sizeof(unw_dyn_info_t));
if (memset_s(&newdi, sizeof(unw_dyn_info_t), 0, sizeof(unw_dyn_info_t)) == nullptr) {
HLOGE("memset_s() failed");
return -UNW_EUNSPEC;
}
#ifdef target_cpu_arm
// arm use .ARM.exidx , not use ehframe
newdi.format = UNW_INFO_FORMAT_ARM_EXIDX;
@ -194,7 +197,7 @@ int CallStack::FindUnwindTable(SymbolsFile *symbolsFile, const MemMapItem &mmap,
if (odi.has_value()) {
unw_dyn_info_t &di = odi.value();
/*
we dont use dwarf_search_unwind_table
we don't use dwarf_search_unwind_table
because in arm it will search two function:
1 arm_search_unwind_table first
2 dwarf_search_unwind_table
@ -548,7 +551,7 @@ size_t CallStack::DoExpandCallStack(std::vector<CallFrame> &newCallFrames,
HLOGM("try find new call chain bottom %s for limit %zu", newIt->ToString().c_str(),
expandLimit);
// first frame earch, from called - > caller
// first frame search, from called - > caller
// for case 2 it should found B
size_t distances = expandLimit - 1;
auto cachedIt = find(cachedCallFrames.begin(), cachedCallFrames.end(), *newIt);
@ -607,7 +610,7 @@ size_t CallStack::ExpandCallStack(pid_t tid, std::vector<CallFrame> &callFrames,
if (callFrames.size() >= 1u) {
// get top (Earliest caller)
HashList<uint64_t, std::vector<CallFrame>> &cachedCallFrames = cachedCallFramesMap_[tid];
HLOGV("find call stack frames in cahce size %zu", cachedCallFrames.size());
HLOGV("find call stack frames in cache size %zu", cachedCallFrames.size());
// compare
using namespace std::rel_ops; // enable complement comparing operators
for (auto itr = cachedCallFrames.begin(); itr < cachedCallFrames.end(); ++itr) {

View File

@ -75,7 +75,7 @@ bool Command::DispatchCommands(std::vector<std::string> arguments)
return false;
}
} else {
// we dont support this command
// we don't support this command
printf("unknown args: %s\n", arguments.front().c_str());
return false;
}

View File

@ -250,7 +250,7 @@ bool DebugLogger::OpenLog(const std::string &tempLogPath, const std::string &fla
std::lock_guard<std::recursive_mutex> lock(logMutex_);
if (logDisabled_) {
// don't reopen it when we crash or soemthing else.
// don't reopen it when we crash or something else.
return false;
}
if (!tempLogPath.empty()) {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@ -134,7 +134,7 @@ const std::string DwarfEncoding::FormatName() const
case DW_EH_PE_omit:
return "DW_EH_PE_omit";
default:
return "unknow format";
return "unknown format";
}
}
const std::string DwarfEncoding::ApplicationName() const
@ -155,7 +155,7 @@ const std::string DwarfEncoding::ApplicationName() const
case DW_EH_PE_nothing:
return "DW_EH_PE_empty";
default:
return "unknow format";
return "unknown format";
}
}
} // namespace HiPerf

View File

@ -129,7 +129,10 @@ bool ElfFile::ParsePrgHeaders()
HLOGE("Error in ELF::ElfFile::ParsePrgHeaders(): new failed");
return false;
}
memset_s(phdrsBuf, phdrSize * numPhdrs, 0, phdrSize * numPhdrs);
if (memset_s(phdrsBuf, phdrSize * numPhdrs, 0, phdrSize * numPhdrs) == nullptr) {
HLOGE("memset_s() in ElfFile::ParsePrgHeaders");
return false;
}
ret = ReadFile(phdrsBuf, phdrSize * numPhdrs);
if (ret != static_cast<int64_t>(phdrSize * numPhdrs)) {
return false;
@ -164,7 +167,10 @@ bool ElfFile::ParseSecNamesStr()
HLOGE("Error in ElfFile::ParseSecNamesStr(): new failed");
return false;
}
memset_s(shdrBuf, shdrSize, 0, shdrSize);
if (memset_s(shdrBuf, shdrSize, 0, shdrSize) == nullptr) {
HLOGE("Error in ElfFile::ParseSecNamesStr(): memset_s failed");
return false;
}
ret = ReadFile(shdrBuf, shdrSize);
HLOG_ASSERT(ret == static_cast<int64_t>(shdrSize));
const std::string secName {".shstrtab"};
@ -188,7 +194,10 @@ bool ElfFile::ParseSecNamesStr()
HLOGE("Error in ElfFile::ParseSecNamesStr(): new secNamesBuf failed");
return false;
}
memset_s(secNamesBuf, secSize, '\0', secSize);
if (memset_s(secNamesBuf, secSize, '\0', secSize) == nullptr) {
HLOGE("Error in ElfFile::ParseSecNamesStr(): memset_s failed");
return false;
}
ret = ReadFile(secNamesBuf, secSize);
if (ret != static_cast<int64_t>(secSize)) {
delete[] secNamesBuf;
@ -213,7 +222,10 @@ bool ElfFile::ParseSecHeaders()
HLOGE("Error in ELF::ElfFile::ParseSecHeaders(): new failed");
return false;
}
memset_s(shdrsBuf, shdrSize * numShdrs, '\0', shdrSize * numShdrs);
if (memset_s(shdrsBuf, shdrSize * numShdrs, '\0', shdrSize * numShdrs) == nullptr) {
HLOGE("Error in ELF::ElfFile::ParseSecHeaders(): memset_s failed");
return false;
}
ret = ReadFile(shdrsBuf, shdrSize * numShdrs);
HLOG_ASSERT(ret == static_cast<int64_t>(shdrSize * numShdrs));
char *shdrBuf = shdrsBuf;
@ -292,7 +304,10 @@ bool ElfFile::ParseSymNamesStr()
HLOGE("Error in ElfFile::ParsesymNamesStr(): new failed");
return false;
}
memset_s(secBuf, secSize, '\0', secSize);
if (memset_s(secBuf, secSize, '\0', secSize) == nullptr) {
HLOGE("Error in ElfFile::ParsesymNamesStr(): memset_s failed");
return false;
}
ret = ReadFile(secBuf, secSize);
HLOG_ASSERT(ret == static_cast<int64_t>(secSize));
symNamesStr_ = std::string(secBuf, secSize);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@ -243,7 +243,7 @@ const char *ReportGetBuildId(const char *elfPath)
const char *ReportGetElfArch(const char *elfPath)
{
const char *machineName = "unknow";
const char *machineName = "unknown";
static std::string buildId; // statci for hold the c_str buffer
std::unique_ptr<ElfFile> elfFile = ElfFile::MakeUnique(elfPath);
static std::string result; // statci for hold the c_str buffer
@ -265,7 +265,7 @@ const char *ReportGetElfArch(const char *elfPath)
machineName = "x86_64";
break;
default:
machineName = "unknow";
machineName = "unknown";
break;
}
HLOGD("elf '%s' mache value is '%x'(%s) \n", elfPath, elfFile->ehdr_->machine_,

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@ -95,7 +95,7 @@ static bool OnHiLog(const std::vector<std::string> &args)
#endif
void RegisterMainCommandDebug()
{
Option::RegisterMainOption("--nodebug", "disbale debug log, usage format: --nodebug [command] [args]",
Option::RegisterMainOption("--nodebug", "disable debug log, usage format: --nodebug [command] [args]",
OnNoDebug);
Option::RegisterMainOption("--debug", "show debug log, usage format: --debug [command] [args]",
OnDebugLevel);

View File

@ -62,7 +62,7 @@ std::unique_ptr<PerfEventRecord> GetPerfEventRecord(const int type, uint8_t *p,
case PERF_RECORD_SWITCH_CPU_WIDE:
return std::make_unique<PerfRecordSwitchCpuWide>(data);
default:
HLOGE("unknow record type %d\n", type);
HLOGE("unknown record type %d\n", type);
return nullptr;
}
}

View File

@ -96,7 +96,7 @@ bool PerfEvents::CheckOhosPermissions()
perfHarden = OHOS::system::GetParameter(PERF_DISABLE_PARAM, perfHarden);
HLOGD("%s is %s", PERF_DISABLE_PARAM.c_str(), perfHarden.c_str());
if (perfHarden == "1") {
printf("param '%s' is disbaled, try to enable it\n", PERF_DISABLE_PARAM.c_str());
printf("param '%s' is disabled, try to enable it\n", PERF_DISABLE_PARAM.c_str());
// we will try to set it as 0
perfHarden = OHOS::system::SetParameter(PERF_DISABLE_PARAM, "0");
// wait init config the param
@ -148,7 +148,7 @@ bool PerfEvents::CheckPermissions(PerfEventParanoid request)
} else if (perfEventParanoid_ == PerfEventParanoid::KERNEL_USER_CPU) {
printf("allow access to CPU-specific data but not raw tracepoint samples.\n");
} else if (perfEventParanoid_ <= PerfEventParanoid::NOLIMIT) {
printf("unable to read anthing\n");
printf("unable to read anything\n");
}
printf("request level is %d\n", request);
return perfEventParanoid_ <= request;
@ -371,7 +371,10 @@ bool PerfEvents::AddEvent(perf_type_id type, __u64 config, bool excludeUser, boo
}
// attr
memset_s(&eventItem.attr, sizeof(perf_event_attr), 0, sizeof(perf_event_attr));
if (memset_s(&eventItem.attr, sizeof(perf_event_attr), 0, sizeof(perf_event_attr)) == nullptr) {
HLOGE("memset_s failed in PerfEvents::AddEvent");
return false;
}
eventItem.attr.size = sizeof(perf_event_attr);
eventItem.attr.type = type;
eventItem.attr.config = config;
@ -451,7 +454,10 @@ bool PerfEvents::AddEvent(perf_type_id type, __u64 config, bool excludeUser, boo
std::unique_ptr<perf_event_attr> PerfEvents::CreateDefaultAttr(perf_type_id type, __u64 config)
{
unique_ptr<perf_event_attr> attr = make_unique<perf_event_attr>();
memset_s(attr.get(), sizeof(perf_event_attr), 0, sizeof(perf_event_attr));
if (memset_s(attr.get(), sizeof(perf_event_attr), 0, sizeof(perf_event_attr)) == nullptr) {
HLOGE("memset_s failed in PerfEvents::CreateDefaultAttr");
return nullptr;
}
attr->size = sizeof(perf_event_attr);
attr->type = type;
attr->config = config;
@ -489,7 +495,7 @@ static void RecoverCaptureSig()
}
// split to two part
// beacuse WriteAttrAndId need fd id before start tracking
// because WriteAttrAndId need fd id before start tracking
bool PerfEvents::PrepareTracking(void)
{
HLOGV("enter");
@ -1117,7 +1123,7 @@ bool PerfEvents::StatReport(const __u64 &durationInSec)
readNoGroupValue.time_running, readNoGroupValue.value);
}
} else {
printf("read faild from event '%s'\n", eventItem.configName.c_str());
printf("read failed from event '%s'\n", eventItem.configName.c_str());
}
}
}

View File

@ -117,7 +117,7 @@ bool PerfFileSection::Read(std::string &value)
return false;
}
// if size large than buf size or 0 size ?
// dont assert for fuzz test
// don't assert for fuzz test
if (size == 0 or size > maxSize_) {
return false;
}
@ -145,7 +145,10 @@ bool PerfFileSection::Read(char *buf, size_t size)
return false;
} else if (offset_ + size > maxSize_) {
HLOGE("read out of size!!! offset_ %zu size %zu max %zu", offset_, size, maxSize_);
memset_s(buf, size, 0, size); // make sure the content return is 0 when failed
if (memset_s(buf, size, 0, size) == nullptr) { // make sure the content return is 0 when failed
HLOGE("memset_s failed in PerfFileSection::Read");
return false;
}
return false;
}
HLOGD("PerfFileSection::Read offset_ %zu size %zu maxSize_ %zu", offset_, size, maxSize_);
@ -260,9 +263,9 @@ PerfFileSectionSymbolsFiles::PerfFileSectionSymbolsFiles(FEATURE id, const char
Read(symbolStruct.len_);
Read(symbolStruct.symbolName_);
}
HLOGV(" %zu SymbolStruct readed.", symbolFileStruct.symbolStructs_.size());
HLOGV(" %zu SymbolStruct read.", symbolFileStruct.symbolStructs_.size());
}
HLOGV(" %zu SymbolFileStruct readed.", symbolFileStructs_.size());
HLOGV(" %zu SymbolFileStruct read.", symbolFileStructs_.size());
}
bool PerfFileSectionSymbolsFiles::GetBinary(char *buf, size_t size)

View File

@ -264,7 +264,7 @@ void Report::MergeCallFrameCount(ReportItem &leftItem, ReportItem &rightItem)
// all the child in rightFrame has been copy to left.
break;
} else {
// alread have , add count
// already have , add count
leftFrameIt->eventCount_ += rightFrame.eventCount_;
leftFrameIt->selfEventCount_ += rightFrame.selfEventCount_;
// left move to next
@ -342,7 +342,7 @@ void Report::OutputStdStatistics(ReportEventConfigItem &config)
bool Report::OutputStdStatistics(ReportEventConfigItem &config, ReportEventConfigItem &otherConfig)
{
if (config != otherConfig) {
fprintf(output_, "diff config unable comapre\n");
fprintf(output_, "diff config unable compare\n");
return false;
}
fprintf(output_, "Event: %s (type %" PRIu32 " id %" PRIu64 ")", config.eventName_.c_str(),
@ -406,7 +406,7 @@ bool Report::OutputStdCallFrame(int indent, const std::string_view &funcName, ui
HLOGV("frame %f indent %d at %s", heat, indent, funcName.data());
if (heat < option_.callStackHeatLimit_) {
// dont print this three anymore
// don't print this three anymore
return false;
}
@ -477,7 +477,7 @@ void Report::OutputStdCallFrames(int indent, const ReportItemCallFrame &callFram
if (callFrame.childs.size() == 1u and
callFrame.childs[0].eventCount_ == callFrame.eventCount_) {
HLOGV("childCallFream %*c %s", indent, ' ', callFrame.childs[0].func_.data());
// dont indent if same count (only one 100% children)
// don't indent if same count (only one 100% children)
OutputStdCallFrames(indent, callFrame.childs[0], callFrame.eventCount_);
} else {
// else a lot children

View File

@ -81,7 +81,7 @@ int ReportJsonFile::GetFuncionID(int libId, std::string_view function)
return it - functionList_.begin();
} else {
HLOGW("'%s' not found in function list in lib %d", function.data(), libId);
// make a new functin for unknow name
// make a new function for unknown name
addNewFunction(libId, function);
// retuen the last index
return functionList_.size() - 1;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@ -174,7 +174,7 @@ bool SubCommandDump::DumpElfFile()
printf("dump elf: '%s'\n", elfFileName_.c_str());
auto elf = SymbolsFile::CreateSymbolsFile(elfFileName_);
if (!elf->LoadSymbols("")) {
printf("load elf faild.\n");
printf("load elf failed.\n");
return false;
} else {
printf("load elf succeed.\n");
@ -187,7 +187,7 @@ bool SubCommandDump::DumpProtoFile()
printf("dump protobuf file: '%s'\n", protobufDumpFileName_.c_str());
protobufInputFileReader_ = std::make_unique<ReportProtobufFileReader>();
if (!protobufInputFileReader_->Dump(protobufDumpFileName_)) {
printf("load proto faild.\n");
printf("load proto failed.\n");
return false;
}
return true;

View File

@ -576,7 +576,7 @@ bool SubCommandRecord::ParseControlCmd(const std::string cmd)
return true;
}
printf("Invalid --control %s option, command shoud be: prepare, start, pause, resume, stop.\n",
printf("Invalid --control %s option, command should be: prepare, start, pause, resume, stop.\n",
cmd.c_str());
return false;
}
@ -624,7 +624,7 @@ bool SubCommandRecord::TraceOffCpu()
const std::string nodeDebug = "/sys/kernel/debug/tracing/events/sched/sched_switch/enable";
if (!ReadIntFromProcFile(node.c_str(), enable) and
!ReadIntFromProcFile(nodeDebug.c_str(), enable)) {
printf("Cannot trace off CPU, event sched:sched_switch is not avilable (%s or %s)\n",
printf("Cannot trace off CPU, event sched:sched_switch is not available (%s or %s)\n",
node.c_str(), nodeDebug.c_str());
return false;
}
@ -936,7 +936,7 @@ bool SubCommandRecord::CreateFifoServer()
bool SubCommandRecord::SendFifoAndWaitReply(const std::string &cmd)
{
// need open for read fisrt, because server maybe send reply before client wait to read
// need open for read first, because server maybe send reply before client wait to read
int fdRead = open(CONTROL_FIFO_FILE_S2C.c_str(), O_RDONLY | O_NONBLOCK);
if (fdRead == -1) {
HLOGE("can not open fifo file(%s)", CONTROL_FIFO_FILE_C2S.c_str());

View File

@ -141,10 +141,10 @@ bool SubCommandReport::VerifyOption()
{
for (auto key : reportOption_.sortKeys_) {
if (key == "count") {
printf("unknow sort key name '%s'\n", key.c_str());
printf("unknown sort key name '%s'\n", key.c_str());
return false;
} else if (GetReport().reportKeyMap_.count(key) == 0) {
printf("unknow sort key name '%s'\n", key.c_str());
printf("unknown sort key name '%s'\n", key.c_str());
return false;
}
}
@ -166,7 +166,7 @@ bool SubCommandReport::VerifyOption()
}
}
// defualt report file name
// default report file name
if (reportFile_.empty()) {
if (protobufFormat_) {
reportFile_ = "perf.proto";
@ -358,7 +358,7 @@ void SubCommandReport::LoadEventDesc()
cpuOffids_ = cpuOffids;
HLOGV("this is cpu off event");
} else {
// dont' add cpuoff event
// don't add cpuoff event
if (protobufFormat_) {
configNames_.emplace_back(fileAttr.name);
}
@ -366,7 +366,7 @@ void SubCommandReport::LoadEventDesc()
GetReport().configIdIndexMaps_[id] = GetReport().configs_.size(); // setup index
HLOGV("add config id map %" PRIu64 " to %zu", id, GetReport().configs_.size());
}
// when cpuOffMode_ , dont use count mode , use time mode.
// when cpuOffMode_ , don't use count mode , use time mode.
auto &config =
GetReport().configs_.emplace_back(fileAttr.name, fileAttr.attr.type,
fileAttr.attr.config, cpuOffMode_ ? false : true);

View File

@ -125,7 +125,7 @@ const std::string SymbolsFile::FindSymbolFile(
}
symboleFilePath = PlatformPathConvert(symboleFilePath);
std::string foundPath;
// search fisrt if we have path
// search first if we have path
if (symbolsFileSearchPaths.size() != 0) {
foundPath = SearchReadableFile(symbolsFileSearchPaths, symboleFilePath);
if (foundPath.empty()) {
@ -411,7 +411,7 @@ private:
case STT_OBJECT:
return " object";
default:
return " unknow";
return " unknown";
}
}
@ -587,7 +587,7 @@ private:
symbol->symSize_, demangle.c_str());
if (symbol->symValue_ == 0) {
continue; // we dont need 0 addr symbol
continue; // we don't need 0 addr symbol
}
symbolsTable.emplace_back(symbol->symValue_, symbol->symSize_, name, demangle,
filePath_);
@ -720,7 +720,7 @@ private:
HLOGD("%zu symbols loadded from elf '%s'.", symbols_.size(), elfPath.c_str());
if (buildId_.empty()) {
HLOGD("buildId not found from elf '%s'.", elfPath.c_str());
// dont failed. some time the lib have not got the build id
// don't failed. some time the lib have not got the build id
// buildId not found from elf '/system/bin/ld-musl-arm.so.1'.
}
}
@ -764,7 +764,7 @@ private:
} else {
HLOGW("symbols will not update for '%s' because buildId is not match.",
elfPath.c_str());
// this mean failed . we dont goon for this.
// this mean failed . we don't goon for this.
return false;
}
@ -875,7 +875,7 @@ public:
}
HLOGM(" 0x%016" PRIx64 " %c '%s' '%s'", addr, type, nameRaw, moduleRaw);
} else {
HLOGW("unknow line %d: '%s'", ret, lineBegin);
HLOGW("unknown line %d: '%s'", ret, lineBegin);
continue;
}
std::string name = nameRaw;
@ -933,7 +933,7 @@ public:
if (ReadFileToString(KPTR_RESTRICT).front() != '0') {
printf("/proc/sys/kernel/kptr_restrict is NOT 0, will try set it to 0.\n");
if (!WriteStringToFile(KPTR_RESTRICT, "0")) {
printf("/proc/sys/kernel/kptr_restrict write failed and we cant not change it.\n");
printf("/proc/sys/kernel/kptr_restrict write failed and we can't not change it.\n");
}
}
@ -1019,7 +1019,7 @@ public:
{
symbolsLoaded_ = true;
if (module_ == filePath_ and onRecording_) {
// file name sitll not convert to ko file path
// file name still not convert to ko file path
// this is in record mode
HLOGV("find ko name %s", module_.c_str());
for (const std::string &path : kernelModulePaths) {

View File

@ -45,13 +45,19 @@ TrackedCommand::TrackedCommand(const std::vector<std::string> &args) : command_
{
// check sa_hanlder of SIGCHLD, set it to SIG_DFL if otherwise
struct sigaction oldAct;
memset_s(&oldAct, sizeof(oldAct), 0, sizeof(oldAct));
if (memset_s(&oldAct, sizeof(oldAct), 0, sizeof(oldAct)) == nullptr) {
HLOGE("memset_s() failed in TrackedCommand::TrackedCommand()");
return;
}
if (sigaction(SIGCHLD, nullptr, &oldAct) == -1) {
HLOGW("sigaction(SIGCHLD, nullptr, &oldAct) failed");
} else {
if (oldAct.sa_handler != SIG_DFL) {
struct sigaction newAct;
memset_s(&newAct, sizeof(newAct), 0, sizeof(newAct));
if (memset_s(&newAct, sizeof(newAct), 0, sizeof(newAct)) == nullptr) {
HLOGE("memset_s() failed in TrackedCommand::TrackedCommand()");
return;
}
newAct.sa_handler = SIG_DFL;
if (sigaction(SIGCHLD, &newAct, &oldAct) == -1) {
HLOGW("sigaction(SIGCHLD, &newAct, &oldAct) failed");

View File

@ -581,14 +581,14 @@ void *mmap(void *addr, size_t length, int prot, int flags, int fd, size_t offset
HLOGV("fd is %d", fd);
HANDLE FileMappingHandle = ::CreateFileMappingW(FileHandle, 0, PAGE_READONLY, 0, 0, 0);
if (FileMappingHandle == NULL) {
if (FileMappingHandle == nullptr) {
HLOGE("CreateFileMappingW %zu Failed with %ld:%s", length, GetLastError(),
GetLastErrorString().c_str());
return MMAP_FAILED;
}
void *mapAddr = ::MapViewOfFile(FileMappingHandle, FILE_MAP_READ, 0, 0, 0);
if (mapAddr == NULL) {
if (mapAddr == nullptr) {
HLOGE("MapViewOfFile %zu Failed with %ld:%s", length, GetLastError(),
GetLastErrorString().c_str());
return MMAP_FAILED;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@ -171,7 +171,7 @@ void VirtualRuntime::UpdateKernelModulesSpaceMaps()
MemMapItem &map = koMaps.emplace_back(addr, addr + size, 0, std::string(module));
HLOGV("add ko map %s", map.ToString().c_str());
} else {
HLOGE("unknow line %d: '%s'", ret, line.c_str());
HLOGE("unknown line %d: '%s'", ret, line.c_str());
}
}
@ -400,7 +400,7 @@ void VirtualRuntime::UpdateFromRecord(PerfRecordMmap &recordMmap)
recordMmap.data_.filename, recordMmap.data_.addr,
recordMmap.data_.addr + recordMmap.data_.len, recordMmap.data_.pgoff);
// kernel mmap
// dont overwrite the vailed mmap , so we also check the recordMmap.data_.len
// don't overwrite the vailed mmap , so we also check the recordMmap.data_.len
if (recordMmap.inKernel()) {
UpdatekernelMap(recordMmap.data_.addr, recordMmap.data_.addr + recordMmap.data_.len,
recordMmap.data_.pgoff, recordMmap.data_.filename);
@ -608,16 +608,16 @@ const Symbol VirtualRuntime::GetSymbol(uint64_t ip, pid_t pid, pid_t tid,
bool VirtualRuntime::SetSymbolsPaths(const std::vector<std::string> &symbolsPaths)
{
std::unique_ptr<SymbolsFile> symbolsFile = SymbolsFile::CreateSymbolsFile(SYMBOL_UNKNOW_FILE);
// we need check if the path is accessable
bool accessable = symbolsFile->setSymbolsFilePath(symbolsPaths);
if (accessable) {
// we need check if the path is accessible
bool accessible = symbolsFile->setSymbolsFilePath(symbolsPaths);
if (accessible) {
symbolsPaths_ = symbolsPaths;
} else {
if (!symbolsPaths.empty()) {
printf("some symbols path unable access\n");
}
}
return accessable;
return accessible;
}
void VirtualRuntime::UpdateFromPerfData(const std::vector<SymbolFileStruct> &symbolFileStructs)

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@ -183,7 +183,7 @@ bool VirtualThread::ReadRoMemory(uint64_t vaddr, uint8_t *data, size_t size) con
bool VirtualThread::IsLegalFileName(const std::string &fileName)
{
// some specail
// some special
if (fileName == "[vdso]") {
return true;
}

View File

@ -46,7 +46,10 @@ static const std::string GetNextLine(FILE *fp, int *status)
{
constexpr int bufSize {128};
char buf[bufSize];
memset_s(buf, sizeof(buf), '\0', sizeof(buf));
if (memset_s(buf, sizeof(buf), '\0', sizeof(buf)) == nullptr) {
HLOGV("memset_s() failed");
return "";
}
if (fgets(buf, bufSize, fp) == nullptr) {
HLOGV("fgets() failed");
*status = -1;

View File

@ -59,7 +59,7 @@ void RingBufferTest::ReadBufferAndCheck(RingBuffer &buf)
perf_event_header readData = {0, 0, 0};
uint8_t *p = nullptr;
while ((p = buf.GetReadData()) != nullptr) {
ASSERT_EQ(memcpy_s(&readData, sizeof(perf_event_header), p, sizeof(perf_event_header)), 0);
ASSERT_EQ((void *)memcpy_s(&readData, sizeof(perf_event_header), p, sizeof(perf_event_header)), 0);
ASSERT_EQ(checkSize, readData.size)
<< " read data size " << readData.size << " expect data size " << checkSize;
p += sizeof(perf_event_header);
@ -82,7 +82,7 @@ void RingBufferTest::WriteBuffer(RingBuffer &buf)
perf_event_header writeData = {PERF_RECORD_MMAP, 0, sizeof(perf_event_header)};
uint8_t *p = nullptr;
while ((p = buf.AllocForWrite(writeData.size)) != nullptr) {
ASSERT_EQ(memcpy_s(p, writeData.size, &writeData, sizeof(perf_event_header)), 0);
ASSERT_EQ((void *)memcpy_s(p, writeData.size, &writeData, sizeof(perf_event_header)), 0);
p += sizeof(perf_event_header);
uint8_t data = static_cast<uint8_t>(writeData.size & U8MASK);
for (size_t i = 0; i < (writeData.size - sizeof(perf_event_header)); i++) {
@ -122,7 +122,7 @@ HWTEST_F(RingBufferTest, Wrap, TestSize.Level1)
size_t half = 0;
uint8_t *p = nullptr;
while ((p = rb.AllocForWrite(writeData.size)) != nullptr) {
ASSERT_EQ(memcpy_s(p, writeData.size, &writeData, sizeof(perf_event_header)), 0);
ASSERT_EQ((void *)memcpy_s(p, writeData.size, &writeData, sizeof(perf_event_header)), 0);
rb.EndWrite();
half += writeData.size;
if (half >= (rb.GetFreeSize() / 2)) {

View File

@ -118,7 +118,7 @@ HWTEST_F(SubCommandRecordTest, StopSecondsMinErr, TestSize.Level1)
HWTEST_F(SubCommandRecordTest, StopSecondsMax, TestSize.Level1)
{
std::string opt = "-d 10000.0 ";
opt += " ls "; // beacuse UT don't need wait so long
opt += " ls "; // because UT don't need wait so long
TestRecordCommand(opt, true, false);
}

View File

@ -418,7 +418,7 @@ HWTEST_F(SubCommandReportTest, TestOnSubCommand_sort4, TestSize.Level1)
if (HasFailure()) {
printf("output:\n%s", stringOut.c_str());
}
const std::string expectStr = "unknow sort key name 'pids'";
const std::string expectStr = "unknown sort key name 'pids'";
EXPECT_EQ(FindExpectStr(stringOut, expectStr), true);
}

View File

@ -348,7 +348,10 @@ HWTEST_F(VirtualRuntimeTest, UnwindFromRecord, TestSize.Level1)
LoadFromFile(PATH_RESOURCE_TEST_DWARF_DATA + TEST_DWARF_RECORD, data);
ASSERT_NE(data.size(), 0u);
perf_event_attr attr;
memset_s(&attr, sizeof(perf_event_attr), 0, sizeof(perf_event_attr));
if (memset_s(&attr, sizeof(perf_event_attr), 0, sizeof(perf_event_attr)) == nullptr) {
printf("error: memset_s failed.");
return;
}
attr.sample_type = TEST_RECORD_SAMPLE_TYPE;
attr.sample_regs_user = TEST_DWARF_RECORD_REGS_USER;
PerfRecordSample sample(data.data(), attr);