diff --git a/include/callstack.h b/include/callstack.h index c401fd488b1ef9e481ec90993524b2bc8383c0ca..ff432bc8c9a0748ee31ba808c29ea3a5d02608ab 100644 --- a/include/callstack.h +++ b/include/callstack.h @@ -47,10 +47,10 @@ public: CallStack(); ~CallStack() = default; void ClearCache(); - bool UnwindCallStack(const VirtualThread &thread, bool abi32, u64 *regs, u64 regsNum, + bool UnwindCallStack(const VirtualThread &thread, const bool abi32, u64 *regs, const u64 regsNum, const u8 *stack, u64 stackSize, std::vector &, - size_t maxStackLevel = MAX_CALL_FRAME_UNWIND_SIZE); - size_t ExpandCallStack(pid_t tid, std::vector &callFrames, size_t expandLimit = 1u); + const size_t maxStackLevel = MAX_CALL_FRAME_UNWIND_SIZE); + size_t ExpandCallStack(const pid_t tid, std::vector &callFrames, const size_t expandLimit = 1u); private: pid_t lastPid_ = -1; @@ -65,22 +65,22 @@ private: void LogFrame(const std::string msg, const std::vector &frames); size_t DoExpandCallStack(std::vector &newCallFrames, - const std::vector &cachedCallFrames, size_t expandLimit); + const std::vector &cachedCallFrames, const size_t expandLimit); // we have a cache for all thread std::map>> cachedCallFramesMap_; - bool GetIpSP(uint64_t &ip, uint64_t &sp, const u64 *regs, size_t regNum) const; + bool GetIpSP(uint64_t &ip, uint64_t &sp, const u64 *regs, const size_t regNum) const; ArchType arch_ = ArchType::ARCH_UNKNOWN; - static bool ReadVirtualThreadMemory(UnwindInfo &unwindInfoPtr, ADDR_TYPE addr, ADDR_TYPE *data); + static bool ReadVirtualThreadMemory(UnwindInfo &unwindInfoPtr, const ADDR_TYPE addr, ADDR_TYPE *data); #if defined(HAVE_LIBUNWINDER) && HAVE_LIBUNWINDER - bool DoUnwind2(const VirtualThread &thread, std::vector &callStack, size_t maxStackLevel); + bool DoUnwind2(const VirtualThread &thread, std::vector &callStack, const size_t maxStackLevel); static void DumpTableInfo(UnwindTableInfo &outTableInfo); static int FillUnwindTable(SymbolsFile *symbolsFile, std::shared_ptr map, UnwindInfo *unwindInfoPtr, - uintptr_t pc, UnwindTableInfo& outTableInfo); - static int FindUnwindTable(uintptr_t pc, UnwindTableInfo& outTableInfo, void *arg); - static int AccessMem2(uintptr_t addr, uintptr_t *val, void *arg); - static int GetMapByPc(uintptr_t pc, std::shared_ptr& map, void *arg); + const uintptr_t pc, UnwindTableInfo& outTableInfo); + static int FindUnwindTable(const uintptr_t pc, UnwindTableInfo& outTableInfo, void *arg); + static int AccessMem2(const uintptr_t addr, uintptr_t *val, void *arg); + static int GetMapByPc(const uintptr_t pc, std::shared_ptr& map, void *arg); // pid->unwinder(acc/regs/maps) cache std::unordered_map> pidUnwinder_; @@ -88,14 +88,14 @@ private: using DsoUnwindTableInfoMap = std::unordered_map; std::unordered_map unwindTableInfoMap_; - std::shared_ptr accessor_; + std::shared_ptr accessor_ = nullptr; #endif }; struct UnwindInfo { const VirtualThread &thread; const u64 *regs; - size_t regNumber; + size_t regNumber = 0; ArchType arch; CallStack &callStack; }; diff --git a/include/debug_logger.h b/include/debug_logger.h index ea0666799f180cd5e2ecc09c8aa275f5da265614..d52b3919579579363a39b58415cd6da181945e2c 100644 --- a/include/debug_logger.h +++ b/include/debug_logger.h @@ -87,22 +87,22 @@ public: ~DebugLogger(); static DebugLogger *GetInstance(); - DebugLevel SetLogLevel(DebugLevel debugLevel); - bool SetMixLogOutput(bool enable); + DebugLevel SetLogLevel(const DebugLevel debugLevel); + bool SetMixLogOutput(const bool enable); bool SetLogPath(const std::string &logPath); void SetLogTags(const std::string &tags); - int Log(DebugLevel level, const std::string &logTag, const char *fmt, ...) const + int Log(const DebugLevel level, const std::string &logTag, const char *fmt, ...) const __attribute__((format(printf, 4, 5))); // for class, pointer need add 1 offset (first one is *this) - bool EnableHiLog(bool enable = true); + bool EnableHiLog(const bool enable = true); DebugLevel GetLogLevel() const { return debugLevel_; }; - void Disable(bool disable = true); + void Disable(const bool disable = true); static bool logDisabled_; #ifdef HIPERF_DEBUG_TIME @@ -118,10 +118,10 @@ public: void Reset(); private: - bool ShouldLog(DebugLevel level, const std::string &logtag) const; + bool ShouldLog(const DebugLevel level, const std::string &logtag) const; DebugLevel GetLogLevelByName(const std::string &) const; DebugLevel GetLogLevelByTag(const std::string &) const; - const std::string GetLogLevelName(DebugLevel) const; + const std::string GetLogLevelName(const DebugLevel) const; int HiLog(std::string &buffer) const; diff --git a/include/hiperf_hilog.h b/include/hiperf_hilog.h index 2121f870695acacce627fb067c17178cd4664647..6ef4f60eaadbf0ba0783c2c8b25fa7682f22c12a 100644 --- a/include/hiperf_hilog.h +++ b/include/hiperf_hilog.h @@ -124,7 +124,7 @@ static inline std::string StringFormat(const char* fmt, ...) #define LOG_TYPE_WITH_HILOG 3 #define CHECK_TRUE(expr, retval, log, fmt, ...) \ do { \ - if (!(expr)) { \ + if (!(expr)) { \ if (log == 1) { \ std::string str = StringFormat(fmt, ##__VA_ARGS__); \ HLOGE("%s", str.c_str()); \ diff --git a/include/option.h b/include/option.h index 6537c76fdf1bb934eb9c231e0fb576394e53575a..80937d6f539866af04f501f98fd28f67b65868f0 100644 --- a/include/option.h +++ b/include/option.h @@ -63,7 +63,7 @@ Return true, indicating that the parameter is legal (but the user does not neces parameter) */ template -bool GetOptionValue(argsVector &args, std::string optionName, T &value) +bool GetOptionValue(argsVector &args, const std::string optionName, T &value) { // we need keep the ref if we got failed // so we use a local value first. diff --git a/include/perf_event_record.h b/include/perf_event_record.h index 97c25df0d600c63e2412abf50ad14d6e57f36bc9..11da0cc6e4408fa1adeca7b9f2937936e4b5dd05 100644 --- a/include/perf_event_record.h +++ b/include/perf_event_record.h @@ -122,13 +122,13 @@ public: }; virtual bool GetBinary(std::vector &buf) const = 0; - void Dump(int indent = 0, std::string outputFilename = "", FILE *outputDump = nullptr) const; - virtual void DumpData(int indent) const = 0; + void Dump(const int indent = 0, std::string outputFilename = "", FILE *outputDump = nullptr) const; + virtual void DumpData(const int indent) const = 0; virtual void DumpLog(const std::string& prefix) const; protected: - void Init(perf_event_type type, bool inKernel); - void Init(perf_event_hiperf_ext_type type); + void Init(const perf_event_type type, const bool inKernel); + void Init(const perf_event_hiperf_ext_type type); void InitHeader(uint8_t* p); }; @@ -180,12 +180,13 @@ class PerfRecordAuxtrace : public PerfEventRecordTemplate &buf) const; bool GetBinary(std::vector &buf) const override; - void DumpData(int indent) const override; + void DumpData(const int indent) const override; void DumpLog(const std::string &prefix) const override; size_t GetSize() const override; @@ -196,21 +197,21 @@ class PerfRecordAuxTraceInfo : public PerfEventRecordTemplate &buf) const override; - void DumpData(int indent) const override; + void DumpData(const int indent) const override; }; class PerfRecordTimeConv : public PerfEventRecordTemplate { public: PerfRecordTimeConv() = default; bool GetBinary(std::vector &buf) const override; - void DumpData(int indent) const override; + void DumpData(const int indent) const override; }; class PerfRecordCpuMap : public PerfEventRecordTemplate { public: PerfRecordCpuMap() = default; bool GetBinary(std::vector &buf) const override; - void DumpData(int indent) const override; + void DumpData(const int indent) const override; }; class PerfRecordMmap : public PerfEventRecordTemplate { @@ -221,7 +222,7 @@ public: const std::string &filename); bool GetBinary(std::vector &buf) const override; - void DumpData(int indent) const override; + void DumpData(const int indent) const override; void DumpLog(const std::string &prefix) const override; }; @@ -230,13 +231,13 @@ public: PerfRecordMmap2() = default; void Init(uint8_t* data, const perf_event_attr& attr = {}) override; - PerfRecordMmap2(bool inKernel, u32 pid, u32 tid, u64 addr, u64 len, u64 pgoff, u32 maj, u32 min, - u64 ino, u32 prot, u32 flags, const std::string &filename); + PerfRecordMmap2(const bool inKernel, const u32 pid, const u32 tid, const u64 addr, const u64 len, const u64 pgoff, + const u32 maj, const u32 min, u64 ino, u32 prot, u32 flags, const std::string &filename); - PerfRecordMmap2(bool inKernel, u32 pid, u32 tid, std::shared_ptr item); + PerfRecordMmap2(const bool inKernel, const u32 pid, const u32 tid, std::shared_ptr item); bool GetBinary(std::vector &buf) const override; - void DumpData(int indent) const override; + void DumpData(const int indent) const override; void DumpLog(const std::string &prefix) const override; bool discard_ = false; }; @@ -247,7 +248,7 @@ public: PerfRecordLost() = default; bool GetBinary(std::vector &buf) const override; - void DumpData(int indent) const override; + void DumpData(const int indent) const override; // only for UT PerfRecordLost(bool inKernel, u64 id, u64 lost) @@ -264,10 +265,10 @@ public: PerfRecordComm() = default; void Init(uint8_t* data, const perf_event_attr& attr = {}) override; - PerfRecordComm(bool inKernel, u32 pid, u32 tid, const std::string &comm); + PerfRecordComm(const bool inKernel, const u32 pid, const u32 tid, const std::string &comm); bool GetBinary(std::vector &buf) const override; - void DumpData(int indent) const override; + void DumpData(const int indent) const override; void DumpLog(const std::string &prefix) const override; }; @@ -293,18 +294,19 @@ public: static void SetDumpRemoveStack(bool dumpRemoveStack); static bool IsDumpRemoveStack(); bool GetBinary(std::vector &buf) const override; - void DumpData(int indent = 0) const override; + void DumpData(const int indent = 0) const override; void DumpLog(const std::string &prefix) const override; void RecoverCallStack(); // originalSize is use for expand callstack - void ReplaceWithCallStack(size_t originalSize = 0); + void ReplaceWithCallStack(const size_t originalSize = 0); pid_t GetPid() const override; uint64_t GetTime() const; void Clean(); // only for UT - PerfRecordSample(bool inKernel, u32 pid, u32 tid, u64 period = 0, u64 time = 0, u64 id = 0) + PerfRecordSample(const bool inKernel, const u32 pid, const u32 tid, const u64 period = 0, + const u64 time = 0, const u64 id = 0) { PerfEventRecord::Init(PERF_RECORD_SAMPLE, inKernel); Clean(); @@ -327,7 +329,7 @@ public: PerfRecordExit() = default; bool GetBinary(std::vector &buf) const override; - void DumpData(int indent) const override; + void DumpData(const int indent) const override; }; class PerfRecordThrottle : public PerfEventRecordTemplate { @@ -335,7 +337,7 @@ public: PerfRecordThrottle() = default; bool GetBinary(std::vector &buf) const override; - void DumpData(int indent) const override; + void DumpData(const int indent) const override; }; class PerfRecordUnthrottle : public PerfEventRecordTemplate { @@ -343,7 +345,7 @@ public: PerfRecordUnthrottle() = default; bool GetBinary(std::vector &buf) const override; - void DumpData(int indent) const override; + void DumpData(const int indent) const override; }; class PerfRecordFork : public PerfEventRecordTemplate { @@ -351,7 +353,7 @@ public: PerfRecordFork() = default; bool GetBinary(std::vector &buf) const override; - void DumpData(int indent) const override; + void DumpData(const int indent) const override; }; /* @@ -362,7 +364,7 @@ public: PerfRecordRead() = default; bool GetBinary(std::vector &buf) const override; - void DumpData(int indent) const override; + void DumpData(const int indent) const override; }; /* @@ -390,7 +392,7 @@ public: PerfRecordAux() = default; bool GetBinary(std::vector &buf) const override; - void DumpData(int indent) const override; + void DumpData(const int indent) const override; }; /* @@ -409,7 +411,7 @@ public: PerfRecordItraceStart() = default; bool GetBinary(std::vector &buf) const override; - void DumpData(int indent) const override; + void DumpData(const int indent) const override; }; /* @@ -422,7 +424,7 @@ public: PerfRecordLostSamples() = default; bool GetBinary(std::vector &buf) const override; - void DumpData(int indent) const override; + void DumpData(const int indent) const override; }; /* @@ -436,7 +438,7 @@ public: PerfRecordSwitch() = default; bool GetBinary(std::vector &buf) const override; - void DumpData(int) const override {}; + void DumpData(const int) const override {}; }; /* @@ -463,7 +465,7 @@ public: PerfRecordSwitchCpuWide() = default; bool GetBinary(std::vector &buf) const override; - void DumpData(int indent) const override; + void DumpData(const int indent) const override; }; class PerfRecordNull : public PerfEventRecordTemplate { @@ -471,7 +473,7 @@ public: PerfRecordNull() = default; bool GetBinary(std::vector&) const override { return false; }; - void DumpData(int indent) const override {}; + void DumpData(const int indent) const override {}; }; class PerfEventRecordFactory { @@ -483,16 +485,16 @@ private: }; template -void PushToBinary(bool condition, uint8_t *&p, const T &v); +void PushToBinary(const bool condition, uint8_t *&p, const T &v); template -void PushToBinary2(bool condition, uint8_t *&p, const T1 &v1, const T2 &v2); +void PushToBinary2(const bool condition, uint8_t *&p, const T1 &v1, const T2 &v2); template -void PopFromBinary(bool condition, uint8_t *&p, T &v); +void PopFromBinary(const bool condition, uint8_t *&p, T &v); template -void PopFromBinary2(bool condition, uint8_t *&p, T1 &v1, T2 &v2); +void PopFromBinary2(const bool condition, uint8_t *&p, T1 &v1, T2 &v2); } // namespace HiPerf } // namespace Developtools } // namespace OHOS diff --git a/include/perf_events.h b/include/perf_events.h index 387d92ce66b5c231a969096bbfdd9e8da27f810f..98b5e36fbc0fb60b457c00d1ceccd9f3cd0cd078 100644 --- a/include/perf_events.h +++ b/include/perf_events.h @@ -350,9 +350,9 @@ public: PerfEvents(); ~PerfEvents(); - bool AddEvents(const std::vector &eventStrings, bool group = false); + bool AddEvents(const std::vector &eventStrings, const bool group = false); bool PrepareTracking(void); - bool StartTracking(bool immediately = true); + bool StartTracking(const bool immediately = true); bool StopTracking(void); bool PauseTracking(void); bool ResumeTracking(void); @@ -366,14 +366,14 @@ public: bool EnableTracking(); bool IsTrackRunning(); bool IsOutputTracking(); - void SetOutputTrackingStatus(bool status); + void SetOutputTrackingStatus(const bool status); - void SetSystemTarget(bool systemTarget); + void SetSystemTarget(const bool systemTarget); void SetCpu(const std::vector cpus); // cpu id must be [0~N] void SetPid(const std::vector pids); // tis is same as pid in kernel - void SetTimeOut(float timeOut); + void SetTimeOut(const float timeOut); void SetTimeReport(int); - void SetVerboseReport(bool); + void SetVerboseReport(const bool); bool AddOffCpuEvent(); inline void SetTrackedCommand(const std::vector &trackedCommand) @@ -383,41 +383,41 @@ public: } } - void SetSampleFrequency(unsigned int frequency); - void SetSamplePeriod(unsigned int period); + void SetSampleFrequency(const unsigned int frequency); + void SetSamplePeriod(const unsigned int period); // for background track - void SetBackTrack(bool backtrack); - void SetBackTrackTime(uint64_t backtrackTime); + void SetBackTrack(const bool backtrack); + void SetBackTrackTime(const uint64_t backtrackTime); enum SampleStackType { NONE, FP, DWARF, }; - void SetSampleStackType(SampleStackType type); - void SetDwarfSampleStackSize(uint32_t stackSize); - void SetMmapPages(size_t mmapPages); + void SetSampleStackType(const SampleStackType type); + void SetDwarfSampleStackSize(const uint32_t stackSize); + void SetMmapPages(const size_t mmapPages); std::vector GetAttrWithId() const; - void SetInherit(bool inherit) + void SetInherit(const bool inherit) { inherit_ = inherit; }; - void SetClockId(int clockId) + void SetClockId(const int clockId) { clockId_ = clockId; }; - void SetPerCpu(bool perCpu); - void SetPerThread(bool perThread); - bool SetBranchSampleType(uint64_t value); - bool AddDefaultEvent(perf_type_id type); + void SetPerCpu(const bool perCpu); + void SetPerThread(const bool perThread); + bool SetBranchSampleType(const uint64_t value); + bool AddDefaultEvent(const perf_type_id type); - std::map<__u64, std::string> GetSupportEvents(perf_type_id type); + std::map<__u64, std::string> GetSupportEvents(const perf_type_id type); struct Summary { - int cpu; - pid_t tid; + int cpu = -1; + pid_t tid = -1; __u64 eventCount = 0; __u64 timeEnabled = 0; __u64 timeRunning = 0; @@ -429,9 +429,9 @@ public: }; struct ReportSum { - int cpu; - pid_t pid; - pid_t tid; + int cpu = -1; + pid_t pid = -1; + pid_t tid = -1; double scaleSum = 1.0; double commentSum = 0; __u64 eventCountSum = 0; @@ -454,8 +454,8 @@ public: std::function> &, FILE*)>; using RecordCallBack = std::function; - void SetStatCallBack(StatCallBack reportCallBack); - void SetRecordCallBack(RecordCallBack recordCallBack); + void SetStatCallBack(const StatCallBack reportCallBack); + void SetRecordCallBack(const RecordCallBack recordCallBack); void SetStatReportFd(FILE* reportPtr); void GetLostSamples(size_t &lostSamples, size_t &lostNonSamples) { @@ -464,7 +464,7 @@ public: } // review: remove this function. - static const std::string GetStaticConfigName(perf_type_id type_id, __u64 config_id) + static const std::string GetStaticConfigName(const perf_type_id type_id, const __u64 config_id) { auto typeConfigs = TYPE_CONFIGS.find(type_id); if (typeConfigs != TYPE_CONFIGS.end()) { @@ -499,7 +499,7 @@ public: return std::make_tuple(false, PERF_TYPE_MAX, 0); }; - const std::string GetTraceConfigName(__u64 config_id) + const std::string GetTraceConfigName(const __u64 config_id) { auto config = traceConfigTable.find(config_id); if (config != traceConfigTable.end()) { @@ -510,13 +510,13 @@ public: return ""; }; - static const std::string GetTypeName(perf_type_id type_id); + static const std::string GetTypeName(const perf_type_id type_id); bool ParseEventName(const std::string &nameStr, std::string &name, bool &excludeUser, bool &excludeKernel, bool &isTracePoint); // mmap one fd for each cpu struct MmapFd { - int fd; + int fd = -1; perf_event_mmap_page *mmapPage = nullptr; uint8_t *buf = nullptr; size_t bufSize = 0; @@ -527,15 +527,15 @@ public: uint64_t timestamp = 0; const perf_event_attr *attr = nullptr; size_t posCallChain = 0; - int cpu = 0; + int cpu = -1; void *auxBuf = nullptr; - pid_t tid_ = 0; + pid_t tid_ = -1; }; bool isHM_ = false; bool isSpe_ = false; - void SetHM(bool isHM); + void SetHM(const bool isHM); void SetConfig(std::map &speOptMaps); private: size_t recordEventCount_ = 0; // only for debug time @@ -558,10 +558,10 @@ private: bool isLowPriorityThread_ = false; void RecordLoop(); void StatLoop(); - bool IsRecordInMmap(int timeout); + bool IsRecordInMmap(const int timeout); void ReadRecordsFromMmaps(); - void ReadRecordsFromSpeMmaps(MmapFd& mmapFd, u64 auxOffset, u64 auxSize, u32 pid, u32 tid); - void SpeReadData(void *dataPage, u64 *dataTail, uint8_t *buf, u32 size); + void ReadRecordsFromSpeMmaps(MmapFd& mmapFd, const u64 auxOffset, u64 auxSize, const u32 pid, const u32 tid); + void SpeReadData(void *dataPage, u64 *dataTail, uint8_t *buf, const u32 size); bool GetRecordFromMmap(MmapFd &mmap); void GetRecordFieldFromMmap(MmapFd &mmap, void *dest, size_t pos, size_t size); void MoveRecordToBuf(MmapFd &mmap, bool &isAuxEvent, u64 &auxOffset, u64 &auxSize, u32 &pid, u32 &tid); @@ -613,10 +613,10 @@ private: struct FdItem { OHOS::UniqueFd fd; - int cpu; - pid_t pid; - pid_t tid; - __u64 eventCount; + int cpu = -1; + pid_t pid = -1; + pid_t tid = -1; + __u64 eventCount = 0; mutable uint64_t perfId = 0; uint64_t GetPrefId() const { @@ -672,12 +672,12 @@ private: RecordCallBack recordCallBack_; void LoadTracepointEventTypesFromSystem(); - bool PerfEventsEnable(bool); - bool AddEvent(perf_type_id type, __u64 config, bool excludeUser = false, - bool excludeKernel = false, bool followGroup = false); - bool AddEvent(const std::string &eventString, bool followGroup = false); - bool AddSpeEvent(u32 type, bool followGroup = false); - bool IsEventSupport(perf_type_id type, __u64 config); + bool PerfEventsEnable(const bool); + bool AddEvent(const perf_type_id type, const __u64 config, const bool excludeUser = false, + const bool excludeKernel = false, const bool followGroup = false); + bool AddEvent(const std::string &eventString, const bool followGroup = false); + bool AddSpeEvent(const u32 type, const bool followGroup = false); + bool IsEventSupport(const perf_type_id type, const __u64 config); bool IsEventAttrSupport(perf_event_attr &attr); std::chrono::time_point trackingStartTime_; @@ -700,9 +700,9 @@ private: return &(eventGroupItem_.at(0).eventItems.at(0).attr); }; - OHOS::UniqueFd Open(perf_event_attr &attr, pid_t pid = 0, int cpu = -1, int groupFd = -1, - unsigned long flags = 0); - std::unique_ptr CreateDefaultAttr(perf_type_id type, __u64 config); + OHOS::UniqueFd Open(perf_event_attr &attr, const pid_t pid = 0, const int cpu = -1, const int groupFd = -1, + const unsigned long flags = 0); + std::unique_ptr CreateDefaultAttr(const perf_type_id type, const __u64 config); // for update time thread static bool updateTimeThreadRunning_; diff --git a/include/perf_file_format.h b/include/perf_file_format.h index 8476331e0cd39f9ffd478e79c9dc4abedc8ed46a..5f8c9a9990dad07c1261f1d1a4e15a07ef0b7de1 100644 --- a/include/perf_file_format.h +++ b/include/perf_file_format.h @@ -81,8 +81,8 @@ const static std::vector FeatureStrings = { }; struct perf_file_section { - uint64_t offset; - uint64_t size; + uint64_t offset = 0; + uint64_t size = 0; }; struct perf_file_attr { @@ -91,7 +91,7 @@ struct perf_file_attr { }; struct perf_header_string { - uint32_t len; + uint32_t len = 0; char string[0]; /* zero terminated */ }; @@ -114,7 +114,7 @@ public: struct perf_file_section header; const FEATURE featureId_; - virtual bool GetBinary(char *buf, size_t size) = 0; + virtual bool GetBinary(char *buf, const size_t size) = 0; virtual size_t GetSize() = 0; virtual ~PerfFileSection() {} explicit PerfFileSection(const FEATURE featureId) : featureId_(featureId) @@ -122,7 +122,7 @@ public: header.size = 0; header.offset = 0; } - static std::string GetFeatureName(FEATURE featureId); + static std::string GetFeatureName(const FEATURE featureId); protected: const char *rBuffer_ = nullptr; @@ -131,23 +131,23 @@ protected: size_t offset_ = 0; // for read - void Init(const char *buffer, size_t maxSize); + void Init(const char *buffer, const size_t maxSize); // for write - void Init(char *buffer, size_t maxSize); - bool Write(uint32_t u32); - bool Write(uint64_t u64); + void Init(char *buffer, const size_t maxSize); + bool Write(const uint32_t u32); + bool Write(const uint64_t u64); bool Write(const std::string &str); - bool Write(const char *buf, size_t size); - bool Write(const char *buf, size_t size, size_t max); + bool Write(const char *buf, const size_t size); + bool Write(const char *buf, const size_t size, const size_t max); bool Read(uint32_t &value); bool Read(uint64_t &value); bool Read(std::string &value); bool Read(char *buf, size_t size); - void Skip(size_t size); + void Skip(const size_t size); - uint32_t SizeOf(std::string &string); + uint32_t SizeOf(const std::string &string); }; class PerfFileSectionString : public PerfFileSection { @@ -156,10 +156,10 @@ class PerfFileSectionString : public PerfFileSection { public: // convert buff to PerfFileSectionString, used to read file // if the data in buf is incorrect, ...... - PerfFileSectionString(FEATURE id, const char *buf, size_t size); - PerfFileSectionString(FEATURE id, const std::string &charString); + PerfFileSectionString(const FEATURE id, const char *buf, size_t size); + PerfFileSectionString(const FEATURE id, const std::string &charString); - bool GetBinary(char *buf, size_t size); + bool GetBinary(char *buf, const size_t size); size_t GetSize(); const std::string ToString() const; }; @@ -170,7 +170,7 @@ struct SymbolStruct { uint32_t len_ = 0; std::string symbolName_ = EMPTY_STRING; SymbolStruct() {} - SymbolStruct(uint64_t vaddr, uint32_t len, const std::string &symbolName) + SymbolStruct(const uint64_t vaddr, const uint32_t len, const std::string &symbolName) : vaddr_(vaddr), len_(len), symbolName_(symbolName) { } @@ -178,9 +178,9 @@ struct SymbolStruct { struct SymbolFileStruct { std::string filePath_ = EMPTY_STRING; - uint32_t symbolType_; - uint64_t textExecVaddr_; - uint64_t textExecVaddrFileOffset_; + uint32_t symbolType_ = 0; + uint64_t textExecVaddr_ = 0; + uint64_t textExecVaddrFileOffset_ = 0; std::string buildId_; std::vector symbolStructs_; }; @@ -190,14 +190,14 @@ public: std::vector symbolFileStructs_; size_t GetSize(); - PerfFileSectionSymbolsFiles(FEATURE id, const std::vector &symbolFileStructs) + PerfFileSectionSymbolsFiles(const FEATURE id, const std::vector &symbolFileStructs) : PerfFileSection(id), symbolFileStructs_(symbolFileStructs) { } // if the data in buf is incorrect, ...... - PerfFileSectionSymbolsFiles(FEATURE id, const char *buf, size_t size); + PerfFileSectionSymbolsFiles(const FEATURE id, const char *buf, const size_t size); - bool GetBinary(char *buf, size_t size); + bool GetBinary(char *buf, const size_t size); void ReadSymbolFileStructs(); private: }; @@ -208,10 +208,10 @@ class PerfFileSectionNrCpus : public PerfFileSection { uint32_t nrCpusOnline_ = 0; public: - PerfFileSectionNrCpus(FEATURE id, const char *buf, size_t size); - PerfFileSectionNrCpus(FEATURE id, uint32_t nrCpusAvailable, uint32_t nrCpusOnline); + PerfFileSectionNrCpus(const FEATURE id, const char *buf, const size_t size); + PerfFileSectionNrCpus(const FEATURE id, const uint32_t nrCpusAvailable, const uint32_t nrCpusOnline); - bool GetBinary(char *buf, size_t size); + bool GetBinary(char *buf, const size_t size); size_t GetSize(); void GetValue(uint32_t &nrCpusAvailable, uint32_t &nrCpusOnline) const; }; @@ -220,10 +220,10 @@ class PerfFileSectionU64 : public PerfFileSection { uint64_t value_; public: - PerfFileSectionU64(FEATURE id, const char *buf, size_t size); - PerfFileSectionU64(FEATURE id, uint64_t v); + PerfFileSectionU64(const FEATURE id, const char *buf, const size_t size); + PerfFileSectionU64(const FEATURE id, const uint64_t v); - bool GetBinary(char *buf, size_t size); + bool GetBinary(char *buf, const size_t size); size_t GetSize(); void GetValue(uint64_t &v) const; }; @@ -231,14 +231,14 @@ public: class PerfFileSectionUniStackTable : public PerfFileSection { public: std::vector uniStackTableInfos_; - PerfFileSectionUniStackTable(FEATURE id, + PerfFileSectionUniStackTable(const FEATURE id, const ProcessStackMap *table) : PerfFileSection(id), processStackTable_(table) {} - PerfFileSectionUniStackTable(FEATURE id, const char *buf, size_t size); + PerfFileSectionUniStackTable(const FEATURE id, const char *buf, const size_t size); private: const ProcessStackMap *processStackTable_; size_t GetSize(); - bool GetBinary(char *buf, size_t size); + bool GetBinary(char *buf, const size_t size); }; struct AttrWithId; @@ -246,10 +246,10 @@ class PerfFileSectionEventDesc : public PerfFileSection { public: std::vector eventDesces_; - PerfFileSectionEventDesc(FEATURE id, const char *buf, size_t size); - PerfFileSectionEventDesc(FEATURE id, const std::vector &eventDesces); + PerfFileSectionEventDesc(const FEATURE id, const char *buf, const size_t size); + PerfFileSectionEventDesc(const FEATURE id, const std::vector &eventDesces); - bool GetBinary(char *buf, size_t size); + bool GetBinary(char *buf, const size_t size); size_t GetSize(); void GetValue(std::vector &eventDesces) const; }; diff --git a/include/perf_file_reader.h b/include/perf_file_reader.h index 6f9b11b566068d45531dcb4ad4df766f66393b70..cfe22816ea6363ac7d1a8cc977a9a8e2eaf0b3aa 100644 --- a/include/perf_file_reader.h +++ b/include/perf_file_reader.h @@ -46,7 +46,7 @@ public: bool ReadFeatureSection(); const std::vector &GetFeatures() const; const std::vector> &GetFeatureSections() const; - const PerfFileSection *GetFeatureSection(FEATURE feature) const; + const PerfFileSection *GetFeatureSection(const FEATURE feature) const; explicit PerfFileReader(const std::string &fileName, FILE *fp); const std::string GetFeatureString(const FEATURE feature) const; @@ -59,8 +59,8 @@ public: // fuzz user this protected: - virtual bool Read(void *buf, size_t len); - virtual bool Read(char *buf, uint64_t offset, size_t len); + virtual bool Read(void *buf, const size_t len); + virtual bool Read(char *buf, const uint64_t offset, const size_t len); FILE *fp_ = nullptr; bool ReadFileHeader(); bool ReadAttrSection(); @@ -77,7 +77,7 @@ private: const perf_event_attr *GetDefaultAttr(); const std::string fileName_; - uint64_t dataSectionSize_; + uint64_t dataSectionSize_ = 0; bool compressData_ = false; perf_file_header header_; @@ -85,7 +85,7 @@ private: std::vector> vecAttrIds_; std::unordered_map mapId2Attr_; - uint64_t featureSectionOffset_; + uint64_t featureSectionOffset_ = 0; std::vector features_; std::vector> perfFileSections_; diff --git a/include/perf_file_writer.h b/include/perf_file_writer.h index 6b961dfe51fd33020d91a8c15164c5720f7c8fc3..bd4db870c40d5f8bdec78a45dd23882365c50e34 100644 --- a/include/perf_file_writer.h +++ b/include/perf_file_writer.h @@ -43,15 +43,15 @@ public: } ~PerfFileWriter(); - bool Open(const std::string &fileName, bool compressData = false); + bool Open(const std::string &fileName, const bool compressData = false); // WriteAttrAndId() must be called before WriteRecord() - bool WriteAttrAndId(const std::vector &attrIds, bool isSpe = false); + bool WriteAttrAndId(const std::vector &attrIds, const bool isSpe = false); bool WriteRecord(const PerfEventRecord &record); - bool AddNrCpusFeature(FEATURE feature, uint32_t nrCpusAvailable, uint32_t nrCpusOnline); - bool AddEventDescFeature(FEATURE feature, const std::vector &eventDesces); - bool AddStringFeature(FEATURE feature, std::string string); - bool AddU64Feature(FEATURE feature, uint64_t v); - bool AddBoolFeature(FEATURE feature); + bool AddNrCpusFeature(const FEATURE feature, const uint32_t nrCpusAvailable, const uint32_t nrCpusOnline); + bool AddEventDescFeature(const FEATURE feature, const std::vector &eventDesces); + bool AddStringFeature(const FEATURE feature, const std::string& string); + bool AddU64Feature(const FEATURE feature, const uint64_t v); + bool AddBoolFeature(const FEATURE feature); bool AddSymbolsFeature(const std::vector> &); bool AddUniStackTableFeature(const ProcessStackMap *table); // close file diff --git a/include/perf_pipe.h b/include/perf_pipe.h index 6c9764b44ba782166a040993ac81126c3e2276ba..9647d98bbf4e5ef50b6d2b580919cec61161d5fc 100644 --- a/include/perf_pipe.h +++ b/include/perf_pipe.h @@ -48,12 +48,12 @@ public: void RemoveFifoFile(); bool CreateFifoFile(); bool SendFifoAndWaitReply(const std::string &cmd, const std::chrono::milliseconds &timeOut); - bool WaitFifoReply(int fd, const std::chrono::milliseconds &timeOut); - void WaitFifoReply(int fd, const std::chrono::milliseconds &timeOut, std::string& reply); - void ProcessStopCommand(bool ret); + bool WaitFifoReply(const int fd, const std::chrono::milliseconds &timeOut); + void WaitFifoReply(const int fd, const std::chrono::milliseconds &timeOut, std::string& reply); + void ProcessStopCommand(const bool ret); void ProcessOutputCommand(bool ret); bool ProcessControlCmd(); - void SetOutPutEnd(bool outputEnd); + void SetOutPutEnd(const bool outputEnd); }; } // namespace HiPerf } // namespace Developtools diff --git a/include/register.h b/include/register.h index ec74cd5cd133d0f285e042791679afb7cc459f3f..70c38fc068eb4677b5dc9dac20096fb1cb3482c1 100644 --- a/include/register.h +++ b/include/register.h @@ -135,38 +135,36 @@ constexpr ArchType BUILD_ARCH_TYPE = ArchType::ARCH_ARM; #error NOT SUPPORT ARCH #endif -const std::string UpdatePerfContext(uint64_t addr, perf_callchain_context &perfCallchainContext); -const std::string GetArchName(ArchType arch); -uint64_t GetSupportedRegMask(ArchType arch); +const std::string UpdatePerfContext(const uint64_t addr, perf_callchain_context &perfCallchainContext); +const std::string GetArchName(const ArchType arch); +uint64_t GetSupportedRegMask(const ArchType arch); // this is only for debug -const std::string RegisterGetName(size_t registerIndex); +const std::string RegisterGetName(const size_t registerIndex); bool RegisterGetValue(uint64_t &value, const u64 registers[], const size_t registerIndex, const size_t registerNumber); -size_t RegisterGetSP(ArchType arch); -size_t RegisterGetIP(ArchType arch); +size_t RegisterGetSP(const ArchType arch); +size_t RegisterGetIP(const ArchType arch); -inline bool RegisterGetSPValue(uint64_t &value, ArchType arch, const u64 registers[], +inline bool RegisterGetSPValue(uint64_t &value, const ArchType arch, const u64 registers[], const size_t registerNumber) { return RegisterGetValue(value, registers, RegisterGetSP(arch), registerNumber); } -inline bool RegisterGetIPValue(uint64_t &value, ArchType arch, const u64 registers[], +inline bool RegisterGetIPValue(uint64_t &value, const ArchType arch, const u64 registers[], const size_t registerNumber) { return RegisterGetValue(value, registers, RegisterGetIP(arch), registerNumber); } -int LibunwindRegIdToPerfReg(int regnum); - ArchType GetDeviceArch(); -ArchType SetDeviceArch(ArchType arch); +ArchType SetDeviceArch(const ArchType arch); ArchType GetArchTypeFromUname(const std::string &machine); -ArchType GetArchTypeFromABI(bool abi32); -void UpdateRegForABI(ArchType arch, u64 *registers); +ArchType GetArchTypeFromABI(const bool abi32); +void UpdateRegForABI(const ArchType arch, u64 *registers); } // namespace HiPerf } // namespace Developtools } // namespace OHOS diff --git a/include/report.h b/include/report.h index 265d1565e3b7c825a84622d01debfcf6401d0aad..99eb86f93be5986ad233b52d923be83df385efba 100644 --- a/include/report.h +++ b/include/report.h @@ -34,13 +34,13 @@ namespace HiPerf { class ReportItemCallFrame { public: std::string func_; - uint64_t vaddr_; + uint64_t vaddr_ = 0; std::string dso_; uint64_t eventCount_ = 0; // call chain event uint64_t selfEventCount_ = 0; // call chain event end in this function std::vector childs; - ReportItemCallFrame(std::string func, uint64_t vaddr, std::string dso, - uint64_t eventCount, uint64_t selfEventCount) + ReportItemCallFrame(const std::string func, const uint64_t vaddr, const std::string dso, + const uint64_t eventCount, const uint64_t selfEventCount) : func_(func), vaddr_(vaddr), dso_(dso), @@ -64,7 +64,7 @@ public: return a.eventCount_ > b.eventCount_; } - static void OrderCallFrames(std::vector &callframes, int indent = 2) + static void OrderCallFrames(std::vector &callframes, const int indent = 2) { int i = 2; if (callframes.size() > 0) { @@ -81,7 +81,7 @@ public: } // just a log - static void DumpCallFrames(std::vector &callframes, int indent = 2) + static void DumpCallFrames(std::vector &callframes, const int indent = 2) { int y = 2; if (callframes.size() > 0) { @@ -122,11 +122,11 @@ public: std::vector callStacks_; float heat = 0.0f; static unsigned long long allIndex_; // debug only - unsigned long long index_; + unsigned long long index_ = 0; // only for ut test - ReportItem(pid_t pid, pid_t tid, const char *comm, const char *dso, const char *func, - uint64_t vaddr, uint64_t eventCount) + ReportItem(const pid_t pid, const pid_t tid, const char *comm, const char *dso, const char *func, + const uint64_t vaddr, uint64_t eventCount) : pid_(pid), tid_(tid), comm_(comm), @@ -199,7 +199,7 @@ public: return 0; } } - static const std::string GetPid(const ReportItem &a, size_t len, const std::string &format) + static const std::string GetPid(const ReportItem &a, const size_t len, const std::string &format) { return StringPrintf(format.c_str(), len, a.pid_); } @@ -213,7 +213,7 @@ public: return 0; } } - static const std::string GetTid(const ReportItem &a, size_t len, const std::string &format) + static const std::string GetTid(const ReportItem &a, const size_t len, const std::string &format) { return StringPrintf(format.c_str(), len, a.tid_); } @@ -224,7 +224,7 @@ public: int result = a.comm_.compare(b.comm_); return result; } - static const std::string GetComm(const ReportItem &a, size_t len, const std::string &format) + static const std::string GetComm(const ReportItem &a, const size_t len, const std::string &format) { return StringPrintf(format.c_str(), len, a.comm_.data()); } @@ -234,7 +234,7 @@ public: { return a.func_.compare(b.func_); } - static const std::string GetFunc(const ReportItem &a, size_t len, const std::string &format) + static const std::string GetFunc(const ReportItem &a, const size_t len, const std::string &format) { return StringPrintf(format.c_str(), len, a.func_.data()); } @@ -244,7 +244,7 @@ public: { return a.dso_.compare(b.dso_); } - static const std::string GetDso(const ReportItem &a, size_t len, const std::string &format) + static const std::string GetDso(const ReportItem &a, const size_t len, const std::string &format) { return StringPrintf(format.c_str(), len, a.dso_.data()); } @@ -254,7 +254,7 @@ public: { return a.fromDso_.compare(b.fromDso_); } - static const std::string GetFromDso(const ReportItem &a, size_t len, const std::string &format) + static const std::string GetFromDso(const ReportItem &a, const size_t len, const std::string &format) { return StringPrintf(format.c_str(), len, a.fromDso_.data()); } @@ -264,7 +264,7 @@ public: { return a.fromFunc_.compare(b.fromFunc_); } - static const std::string GetFromFunc(const ReportItem &a, size_t len, const std::string &format) + static const std::string GetFromFunc(const ReportItem &a, const size_t len, const std::string &format) { return StringPrintf(format.c_str(), len, a.fromFunc_.data()); } @@ -312,7 +312,7 @@ struct ReportKey { } } - void UpdateValueMaxLen(size_t value) + void UpdateValueMaxLen(const size_t value) { size_t newMaxLen = std::max(maxLen_, std::to_string(value).size()); if (maxLen_ < newMaxLen) { @@ -375,7 +375,7 @@ public: Report(ReportOption &option) : option_(option), virtualRuntime_(false) {} bool MultiLevelSame(const ReportItem &a, const ReportItem &b); void AdjustReportItems(); - void AddReportItem(const PerfRecordSample &sample, bool includeCallStack); + void AddReportItem(const PerfRecordSample &sample, const bool includeCallStack); void AddReportItemBranch(const PerfRecordSample &sample); void OutputStd(FILE *output); void OutputStdDiff(FILE *output, Report &other); @@ -475,8 +475,8 @@ public: uint64_t sampleCount_ = 0; uint64_t eventCount_ = 0; std::vector reportItems_; - uint32_t type_; - uint64_t config_; + uint32_t type_ = 0; + uint64_t config_ = 0; std::vector ids_; bool coutMode_ = true; // use cout or time ? @@ -503,13 +503,13 @@ public: virtual ~Report() {} std::map configIdIndexMaps_; // index of configNames_ - std::string GetConfigName(uint64_t id) + std::string GetConfigName(const uint64_t id) { size_t index = GetConfigIndex(id); HIPERF_ASSERT(index < configs_.size(), "unable found config index %zu\n", index); return configs_[index].eventName_; } - size_t GetConfigIndex(uint64_t id) + size_t GetConfigIndex(const uint64_t id) { HIPERF_ASSERT(configIdIndexMaps_.find(id) != configIdIndexMaps_.end(), "unable found id %" PRIx64 "\n", id); return configIdIndexMaps_.at(id); @@ -543,17 +543,17 @@ private: void OutputStdStatistics(ReportEventConfigItem &config); - void OutputStdHead(ReportEventConfigItem &config, bool diffMode = false); + void OutputStdHead(ReportEventConfigItem &config, const bool diffMode = false); void OutputStdContent(ReportEventConfigItem &config); void OutputStdContentDiff(ReportEventConfigItem &left, ReportEventConfigItem &right); void OutputStdContentItem(const ReportItem &reportItem); - void OutputStdCallFrames(int indent, const ReportItemCallFrame &callFrame, uint64_t totalEventCount); - bool OutputStdCallFrame(int indent, const std::string_view &funcName, uint64_t eventCount, - uint64_t totalEventCount); - void OutputStdItemHeating(float heat, float heat2); + void OutputStdCallFrames(const int indent, const ReportItemCallFrame &callFrame, const uint64_t totalEventCount); + bool OutputStdCallFrame(const int indent, const std::string_view &funcName, const uint64_t eventCount, + const uint64_t totalEventCount); + void OutputStdItemHeating(const float heat, const float heat2); }; } // namespace HiPerf } // namespace Developtools diff --git a/include/report_json_file.h b/include/report_json_file.h index d1800e0607bb86cae152071ac3c413c862d7a8dd..632df665f44a10ae3ca92ea28fa8f343be74b1f8 100644 --- a/include/report_json_file.h +++ b/include/report_json_file.h @@ -60,7 +60,7 @@ void OutputJsonKey(FILE *output, const T &value) } } template -void OutputJsonValue(FILE *output, const T &value, bool first = true) +void OutputJsonValue(FILE *output, const T &value, const bool first = true) { if (!first) { fprintf(output, ","); @@ -89,7 +89,7 @@ void OutputJsonValue(FILE *output, const T &value, bool first = true) k:1 */ template -void OutputJsonPair(FILE *output, const K &key, const T &value, bool first = false) +void OutputJsonPair(FILE *output, const K &key, const T &value, const bool first = false) { if (!first) { if (fprintf(output, ",") < 0) { @@ -107,7 +107,7 @@ void OutputJsonPair(FILE *output, const K &key, const T &value, bool first = fal */ template void OutputJsonVectorList(FILE *output, const std::string &key, const std::vector &value, - bool first = false) + const bool first = false) { if (!first) { if (fprintf(output, ",") < 0) { @@ -131,7 +131,7 @@ void OutputJsonVectorList(FILE *output, const std::string &key, const std::vecto */ template void OutputJsonMapList(FILE *output, const std::string &key, const std::map &value, - bool first = false) + const bool first = false) { if (!first) { if (fprintf(output, ",") < 0) { @@ -155,7 +155,7 @@ void OutputJsonMapList(FILE *output, const std::string &key, const std::map void OutputJsonMap(FILE *output, const std::string &key, const std::map &value, - bool first = false) + const bool first = false) { if (!first) { if (fprintf(output, ",") < 0) { @@ -335,7 +335,7 @@ struct ReportProcessItem { }; struct ReportConfigItem { - int index_; + int index_ = -1; std::string eventName_; uint64_t eventCount_ = 0; std::map processes_; @@ -368,9 +368,10 @@ public: { } - void UpdateReportSample(uint64_t configid, pid_t pid, pid_t tid, uint64_t eventCount); - void UpdateReportCallStack(uint64_t id, pid_t pid, pid_t tid, uint64_t eventCount, - std::vector &frames); + void UpdateReportSample(const uint64_t configid, const pid_t pid, + const pid_t tid, const uint64_t eventCount); + void UpdateReportCallStack(const uint64_t id, const pid_t pid, const pid_t tid, const uint64_t eventCount, + const std::vector &frames); void UpdateCallNodeEventCount(); void ProcessSymbolsFiles(const std::vector> &symbolsFiles); @@ -385,22 +386,22 @@ private: std::vector libList_; int functionId_ = 0; std::map> functionMap_; - void AddNewFunction(int libId, std::string name); + void AddNewFunction(const int libId, std::string name); void OutputJsonFunctionMap(FILE *output); - ReportConfigItem &GetConfig(uint64_t id); - std::string GetConfigName(uint64_t id); - uint32_t GetConfigIndex(uint64_t id); + ReportConfigItem &GetConfig(const uint64_t id); + std::string GetConfigName(const uint64_t id); + uint32_t GetConfigIndex(const uint64_t id); - int GetFunctionID(int libId, const std::string &function); - int GetLibID(std::string_view filepath); + int GetFunctionID(const int libId, const std::string &function); + int GetLibID(const std::string_view filepath); void OutputJsonFeatureString(); void OutputJsonRuntimeInfo(); - void AddReportCallStack(uint64_t eventCount, ReportCallNodeItem &callNode, + void AddReportCallStack(const uint64_t eventCount, ReportCallNodeItem &callNode, const std::vector &frames); - void AddReportCallStackReverse(uint64_t eventCount, ReportCallNodeItem &callNode, + void AddReportCallStackReverse(const uint64_t eventCount, ReportCallNodeItem &callNode, const std::vector &frames); uint64_t sampleCount_ = 0; }; diff --git a/include/report_protobuf_file.h b/include/report_protobuf_file.h index 7af63264f260789cd376bac77bdac98c6276f438..06ce84cce02ccb8d14d89cc35109e4a58983e84b 100644 --- a/include/report_protobuf_file.h +++ b/include/report_protobuf_file.h @@ -39,7 +39,7 @@ using ProtobufReadBack = std::function; class ReportProtobufFileWriter : public google::protobuf::io::CopyingOutputStream { public: - bool Create(std::string fileName); + bool Create(const std::string fileName); bool ProcessRecord(const PerfEventRecord &record); bool ProcessSampleRecord(const PerfRecordSample &recordSample, uint32_t configIndex, @@ -61,7 +61,7 @@ private: uint64_t recordLost_ = 0; bool IsOpen(); - bool Write(const void *buffer, int size) override; + bool Write(const void *buffer, const int size) override; virtual bool ProcessRecord(const PerfRecordComm &recordComm); virtual bool ProcessRecord(const PerfRecordLost &recordLost); void BeforeClose(); @@ -69,7 +69,7 @@ private: class ReportProtobufFileReader : public google::protobuf::io::CopyingInputStream { public: - bool Dump(std::string fileName, ProtobufReadBack readBack = nullptr); + bool Dump(const std::string fileName, ProtobufReadBack readBack = nullptr); private: std::unique_ptr protpbufInputStream_; @@ -79,13 +79,13 @@ private: bool IsOpen(); bool CheckFileMagic(); - int Read(void *buffer, int size) override; - bool Dump(const Proto::HiperfRecord &record, int indent = 0); - bool Dump(const Proto::CallStackSample &message, int indent = 0); - bool Dump(const Proto::SampleStatistic &message, int indent = 0); - bool Dump(const Proto::SymbolTableFile &message, int indent = 0); - bool Dump(const Proto::VirtualThreadInfo &message, int indent = 0); - bool Dump(const Proto::ReportInfo &message, int indent = 0); + int Read(void *buffer, const int size) override; + bool Dump(const Proto::HiperfRecord &record, const int indent = 0); + bool Dump(const Proto::CallStackSample &message, const int indent = 0); + bool Dump(const Proto::SampleStatistic &message, const int indent = 0); + bool Dump(const Proto::SymbolTableFile &message, const int indent = 0); + bool Dump(const Proto::VirtualThreadInfo &message, const int indent = 0); + bool Dump(const Proto::ReportInfo &message, const int indent = 0); }; } // namespace HiPerf } // namespace Developtools diff --git a/include/ring_buffer.h b/include/ring_buffer.h index 9834114bf228e1846d8d338ef344358fb6a07f44..b236a760ecf00bffb0afb80d1a7dfc9e34c489ad 100644 --- a/include/ring_buffer.h +++ b/include/ring_buffer.h @@ -24,13 +24,13 @@ public: // little endian, perf_event_header.type is less than 0xff, so set it static constexpr uint8_t MARGIN_BYTE = 0xFF; - explicit RingBuffer(size_t size); + explicit RingBuffer(const size_t size); ~RingBuffer(); // get size of the writable space size_t GetFreeSize() const; // before writing data to rbuff, alloc space first - uint8_t *AllocForWrite(size_t writeSize); + uint8_t *AllocForWrite(const size_t writeSize); // after writing data, move head pointer void EndWrite(); // get data from buff, return nullptr if no readable data diff --git a/include/spe_decoder.h b/include/spe_decoder.h index 8518ea1d9e44d5ee125a7ef232f43911530c703c..cd4c7bf57c7bbc517eef5fc00b23b1c6b00a07a5 100644 --- a/include/spe_decoder.h +++ b/include/spe_decoder.h @@ -285,13 +285,13 @@ struct SpeDecoder { struct SpePkt packet; }; -struct SpeDecoder *SpeDecoderDataNew(const unsigned char *speBuf, size_t speLen); +struct SpeDecoder *SpeDecoderDataNew(const unsigned char *speBuf, const size_t speLen); void SpeDecoderFree(struct SpeDecoder *decoder); int SpeDecode(struct SpeDecoder *decoder); -int SpePktDesc(const struct SpePkt *packet, char *buf, size_t len); -bool SpeDumpRawData(unsigned char *buf, size_t len, int indent, FILE *outputDump); +int SpePktDesc(const struct SpePkt *packet, char *buf, const size_t len); +bool SpeDumpRawData(unsigned char *buf, size_t len, const int indent, FILE *outputDump); struct ReportItemAuxRawData { u32 type; @@ -306,9 +306,9 @@ struct ReportItemAuxRawData { void AddReportItems(const std::vector& auxRawData); void UpdateHeating(); -void DumpSpeReportData(int indent, FILE *outputDump); -void DumpSpeReportHead(int indent, uint32_t type, uint64_t count); -void GetSpeEventNameByType(uint32_t type, std::string& eventName); +void DumpSpeReportData(const int indent, FILE *outputDump); +void DumpSpeReportHead(const int indent, const uint32_t type, const uint64_t count); +void GetSpeEventNameByType(const uint32_t type, std::string& eventName); } // namespace HiPerf } // namespace Developtools } // namespace OHOS diff --git a/include/subcommand.h b/include/subcommand.h index 87c3185365523db08a9697f3bd2ff93f33f40a4c..6de659f664ce80d673b95ca607f970d3201e12b9 100644 --- a/include/subcommand.h +++ b/include/subcommand.h @@ -82,19 +82,19 @@ public: // get some cmd static bool RegisterSubCommand(const std::string& cmdName, std::function func); static const std::map> &GetSubCommands(); - static SubCommand *FindSubCommand(std::string &cmdName); + static SubCommand *FindSubCommand(const std::string &cmdName); // for test code static bool RegisterSubCommand(const std::string& cmdName, std::unique_ptr subCommand); static void ClearSubCommands(); // check restart option - bool CheckRestartOption(std::string &appPackage, bool targetSystemWide, bool restart, - std::vector &selectPids); + bool CheckRestartOption(const std::string &appPackage, const bool targetSystemWide, const bool restart, + std::vector &selectPids); // handle subcommand exclude - bool HandleSubCommandExclude(const std::vector &excludeTids, const std::vector - &excludeThreadNames, std::vector &selectTids); + bool HandleSubCommandExclude(const std::vector &excludeTids, + const std::vector &excludeThreadNames, std::vector &selectTids); private: void ExcludeTidsFromSelectTids(const std::vector &excludeTids, std::vector &selectTids); void ExcludeThreadsFromSelectTids(const std::vector &excludeThreadNames, diff --git a/include/subcommand_dump.h b/include/subcommand_dump.h index ea8a5cf264fad44524549c7b79aee0e3f50945e5..b5e0d03b6b89d5ab0ab8f52266a0a0bd984afc01 100644 --- a/include/subcommand_dump.h +++ b/include/subcommand_dump.h @@ -106,17 +106,17 @@ private: #if defined(HAVE_PROTOBUF) && HAVE_PROTOBUF bool DumpProtoFile(); #endif - void DumpPrintFileHeader(int indent = 0); - void DumpAttrPortion(int indent = 0); - void DumpDataPortion(int indent = 0); + void DumpPrintFileHeader(const int indent = 0); + void DumpAttrPortion(const int indent = 0); + void DumpDataPortion(const int indent = 0); void DumpCallChain(int indent, const PerfRecordSample& sample); - void DumpFeaturePortion(int indent = 0); - void DumpUniqueStackTableNode(int indent, const PerfFileSectionUniStackTable &uniStackTable); + void DumpFeaturePortion(const int indent = 0); + void DumpUniqueStackTableNode(const int indent, const PerfFileSectionUniStackTable &uniStackTable); void ExportUserData(PerfEventRecord& record); void ExportUserStack(const PerfRecordSample &recordSample); void PrintHeaderInfo(const int &indent); void PrintSymbolFile(const int &indent, const SymbolFileStruct &symbolFileStruct); - void PrintFeatureEventdesc(int indent, const PerfFileSectionEventDesc §ionEventdesc); + void PrintFeatureEventdesc(const int indent, const PerfFileSectionEventDesc §ionEventdesc); void DumpSpeReport(); bool CheckOptions(); bool CheckOutputFile(); diff --git a/include/subcommand_record.h b/include/subcommand_record.h index 14eea9be9e3c0711354d36b4b2350ab405b1455d..e405f279d3dabd4744dc6846e20401d3fe4704de 100644 --- a/include/subcommand_record.h +++ b/include/subcommand_record.h @@ -155,6 +155,18 @@ public: " Set the clock id to use for the various time fields in the perf_event_type records.\n" " monotonic and monotonic_raw are supported,\n" " some events might also allow boottime, realtime and clock_tai.\n" + " --pipe_input\n" + " Enable anonymous pipe for the client (calling process) to send control\n" + " commands to the server (hiperf executable program).\n" + " This parameter is designed for system-side C++ interface calls.\n" + " Application developers do not need to pay attention to this parameter\n" + " when using the hiperf command tool.\n" + " --pipe_output\n" + " Enable anonymous pipe for the server (hiperf executable program) to send\n" + " response to the client (calling process).\n" + " This parameter is designed for system-side C++ interface calls.\n" + " Application developers do not need to pay attention to this parameter\n" + " when using the hiperf command tool.\n" " --symbol-dir \n" " Set directory to look for symbol files, used for unwinding. \n" " -m \n" @@ -274,7 +286,7 @@ private: std::set excludeTids_ = {}; void CollectExcludeThread(); void SetExcludeHiperf(); - bool IsThreadExcluded(pid_t pid, pid_t tid); + bool IsThreadExcluded(const pid_t pid, const pid_t tid); // for background track bool backtrack_ = false; @@ -282,7 +294,7 @@ private: bool outputEnd_ = false; bool PreOutputRecordFile(); void OutputRecordFile(); - bool PostOutputRecordFile(bool output); + bool PostOutputRecordFile(const bool output); #ifdef CONFIG_HAS_CCM static constexpr char PRODUCT_CONFIG_PATH[] = "etc/hiperf/hiperf_cfg.json"; @@ -331,9 +343,9 @@ private: void ReplyCommandHandle(); void InitControlCommandHandlerMap(); void DispatchControlCommand(const std::string& command); - bool ClientCommandResponse(bool response); + bool ClientCommandResponse(const bool response); bool ClientCommandResponse(const std::string& str); - bool ChildResponseToMain(bool response); + bool ChildResponseToMain(const bool response); bool ChildResponseToMain(const std::string& str); bool IsSamplingRunning(); @@ -346,7 +358,7 @@ private: std::map> mapPids_; bool ProcessControl(); bool CreateFifoServer(); - bool MainRecvFromChild(int fd, std::string& reply); + bool MainRecvFromChild(const int fd, std::string& reply); void CloseClientThread(); void CloseReplyThread(); @@ -386,7 +398,7 @@ private: void AddDevhostFeature(); bool AddFeatureRecordFile(); - bool CreateInitRecordFile(bool compressData = false); + bool CreateInitRecordFile(const bool compressData = false); bool FinishWriteRecordFile(); bool PostProcessRecordFile(); bool RecordCompleted(); @@ -396,7 +408,7 @@ private: bool CollectionSymbol(PerfEventRecord& record); void CollectSymbol(PerfRecordSample *sample); - bool SetPerfLimit(const std::string& file, int value, std::function const& cmd, + bool SetPerfLimit(const std::string& file, const int value, std::function const& cmd, const std::string& param); bool SetPerfCpuMaxPercent(); bool SetPerfMaxSampleRate(); @@ -418,7 +430,7 @@ private: pid_t GetPidFromAppPackage(const pid_t oldPid, const uint64_t waitAppTimeOut); bool IsAppRunning(); bool IsPidAndTidExist(); - void MsgPrintAndTrans(bool isTrans, const std::string& msg); + void MsgPrintAndTrans(const bool isTrans, const std::string& msg); void WriteCommEventBeforeSampling(); void RemoveVdsoTmpFile(); void RemoveFifoFile(); diff --git a/include/subcommand_stat.h b/include/subcommand_stat.h index 6adfc88ef97bba1e10a453ceb07b0d6b1641b14b..b229a8865edad99c40e140252ce6b566304b678c 100644 --- a/include/subcommand_stat.h +++ b/include/subcommand_stat.h @@ -131,8 +131,8 @@ private: bool verboseReport_ {false}; std::vector trackedCommand_ {}; bool helpOption_ {false}; - bool CheckOptionPidAndApp(std::vector pids); - bool CheckOptionPid(std::vector pids); + bool CheckOptionPidAndApp(const std::vector& pids); + bool CheckOptionPid(const std::vector& pids); bool CheckOutPutFile(); static bool FindEventCount( const std::map> &countEvents, @@ -145,7 +145,7 @@ private: double &running_time_in_sec, __u64 &group_id, double &main_scale); static bool IsMonitoredAtAllTime(const double &scale); static std::string GetCommentConfigName( - const std::unique_ptr &countEvent, std::string eventName); + const std::unique_ptr &countEvent, const std::string &eventName); static void Report(const std::map> &countEvents, FILE* filePtr); @@ -157,7 +157,7 @@ private: static void ReportDetailInfos(const std::map> &countEvents, FILE* filePtr); static void PrintPerValue(const std::unique_ptr &reportSum, const float &ratio, - std::string &configName, FILE* filePtr); + const std::string &configName, FILE* filePtr); static void InitPerMap(const std::unique_ptr &newPerMap, const PerfEvents::Summary &summary, VirtualRuntime& virtualInstance); static bool FindPerCoreEventCount(PerfEvents::Summary &summary, __u64 &eventCount, double &scale); @@ -165,7 +165,8 @@ private: static std::string GetDetailComments(const std::unique_ptr &countEvent, double &comment, PerfEvents::Summary &summary, std::string &configName); static std::string HandleOtherConfig(double &comment, PerfEvents::Summary &summary, - double running_time_in_sec, double scale, bool findRunningTime); + const double running_time_in_sec, const double scale, + const bool findRunningTime); void PrintUsage(); inline bool HelpOption() @@ -175,7 +176,7 @@ private: bool PrepairEvents(); bool CheckOptions(const std::vector &pids); bool CheckSelectCpuPidOption(); - void SetReportFlags(bool cpuFlag, bool threadFlag); + void SetReportFlags(const bool cpuFlag, const bool threadFlag); void SetPerfEvent(); HiperfError CheckStatOption(); @@ -197,7 +198,7 @@ private: void ClientCommandHandle(); void InitControlCommandHandlerMap(); void DispatchControlCommand(const std::string& command); - bool ClientCommandResponse(bool response); + bool ClientCommandResponse(const bool response); bool ClientCommandResponse(const std::string& str); bool IsSamplingRunning(); diff --git a/include/symbols_file.h b/include/symbols_file.h index 11e223131a6b5c79346279d274111095d5df5401..04079977fd896eb07baa60517293cb8a9229eab0 100644 --- a/include/symbols_file.h +++ b/include/symbols_file.h @@ -164,7 +164,7 @@ public: const std::vector &GetMatchedSymbols(); // get vaddr(in symbol) from ip(real addr , after mmap reloc) - virtual uint64_t GetVaddrInSymbols(uint64_t ip, uint64_t mapStart, uint64_t mapOffset) const; + virtual uint64_t GetVaddrInSymbols(const uint64_t ip, const uint64_t mapStart, const uint64_t mapOffset) const; // get symbols from vaddr const DfxSymbol GetSymbolWithVaddr(uint64_t vaddrInFile); @@ -208,7 +208,7 @@ public: std::vector matchedSymbols_ {}; std::map symbolsMap_; static uint32_t offsetNum_; - virtual DfxSymbol GetSymbolWithPcAndMap(uint64_t pc, std::shared_ptr map) + virtual DfxSymbol GetSymbolWithPcAndMap(const uint64_t pc, std::shared_ptr map) { return DfxSymbol(); } @@ -229,7 +229,7 @@ protected: std::string SearchReadableFile(const std::vector &searchPaths, const std::string &filePath) const; - bool UpdateBuildIdIfMatch(std::string buildId); + bool UpdateBuildIdIfMatch(const std::string &buildId); std::string buildId_ = ""; std::vector symbolsFileSearchPaths_; diff --git a/include/unique_stack_table.h b/include/unique_stack_table.h index ff48edf6fa2215ba067a75b2c7e7e41e59aaf09e..4a0f8f9ab88200b0c9b1e203f30eff695f6fa4ea 100644 --- a/include/unique_stack_table.h +++ b/include/unique_stack_table.h @@ -77,12 +77,12 @@ static_assert(sizeof(Node) == 8, "Node size must be 8 byte"); class UniqueStackTable { public: bool Init(); - explicit UniqueStackTable(pid_t pid) : pid_(pid) + explicit UniqueStackTable(const pid_t pid) : pid_(pid) { Init(); } - UniqueStackTable(pid_t pid, uint32_t size) : pid_(pid), tableSize_(size) + UniqueStackTable(const pid_t pid, const uint32_t size) : pid_(pid), tableSize_(size) { Init(); } @@ -91,9 +91,9 @@ public: tableBuf_ = nullptr; } - uint64_t PutIpsInTable(StackId *stackId, u64 *ips, u64 nr); + uint64_t PutIpsInTable(StackId *stackId, const u64 *ips, const u64 nr); bool GetIpsByStackId(const StackId stackId, std::vector& ips); - bool ImportNode(uint32_t index, const Node& node); + bool ImportNode(const uint32_t index, const Node& node); size_t GetWriteSize(); bool Resize(); @@ -120,8 +120,8 @@ public: private: Node* GetFrame(uint64_t stackId); - uint64_t PutIpInSlot(uint64_t thisIp, uint64_t prevIdx); - u32 pid_; + uint64_t PutIpInSlot(const uint64_t thisIp, const uint64_t prevIdx); + u32 pid_ = 0; uint32_t tableSize_ = INITIAL_TABLE_SIZE; std::unique_ptr tableBuf_ = nullptr; std::vector usedSlots_; diff --git a/include/utilities.h b/include/utilities.h index 8dca5e7e88ea28fccaa90d8bed9799c60918e2d9..001cec2f37679f4d0fc3d3b24be7fa3aa65efb0c 100644 --- a/include/utilities.h +++ b/include/utilities.h @@ -187,8 +187,8 @@ std::string SetToString(const std::unordered_set &items) } std::string BufferToHexString(const std::vector &vec); -std::string BufferToHexString(const unsigned char buf[], size_t size); -bool HexDump(const void *buf, size_t size, size_t max_size = 0); +std::string BufferToHexString(const unsigned char buf[], const size_t size); +bool HexDump(const void *buf, const size_t size, const size_t max_size = 0); std::string &StringTrim(std::string &s); @@ -271,7 +271,7 @@ uint32_t RoundUp(uint32_t x, const int align); // data convert function template -std::string ToHex(const T &source, int size = sizeof(T), bool prefix = false) +std::string ToHex(const T &source, const int size = sizeof(T), const bool prefix = false) { std::stringstream ss; if (prefix) { @@ -299,7 +299,7 @@ size_t inline CopyFromBufferAndMove(S *&buffer, T *dest, size_t size = 0) bool ReadIntFromProcFile(const std::string &path, int &value); bool WriteIntToProcFile(const std::string &path, int value); std::string ReadFileToString(const std::string &fileName); -bool ReadFileToString(const std::string &fileName, std::string &content, size_t fileSize = 0); +bool ReadFileToString(const std::string &fileName, std::string &content, const size_t fileSize = 0); bool WriteStringToFile(const std::string &fileName, const std::string &value); // stdout @@ -337,13 +337,13 @@ bool IsBeta(); bool IsHM(); bool IsAllowProfilingUid(); bool IsHiviewCall(); -bool PowerOfTwo(uint64_t n); +bool PowerOfTwo(const uint64_t n); bool IsNumeric(const std::string& str); bool IscontainDigits(const std::string& str); bool IsStringToIntSuccess(const std::string &str, int &num); bool StringToUint64(const std::string &str, uint64_t &val); bool IsDirectoryExists(const std::string& fileName); -bool CreateDirectory(const std::string& path, mode_t mode); +bool CreateDirectory(const std::string& path, const mode_t mode); bool IsValidOutPath(const std::string& path); void AgeHiperflogFiles(); @@ -387,7 +387,7 @@ void CollectPidsByAppname(std::set &pids, const Container& appPackage) } } -bool CheckAppIsRunning(std::vector &selectPids, const std::string &appPackage, int checkAppMs); +bool CheckAppIsRunning(std::vector &selectPids, const std::string &appPackage, const int checkAppMs); bool IsExistDebugByApp(const std::string& bundleName, std::string& err); bool IsExistDebugByPid(const std::vector &pids, std::string& err); bool IsSupportNonDebuggableApp(); @@ -395,9 +395,9 @@ const std::string GetUserType(); bool GetDeveloperMode(); bool IsArkJsFile(const std::string& filepath); bool IsV8File(const std::string& filepath); -std::string GetProcessName(int pid); +std::string GetProcessName(const int pid); std::string HandleAppInfo(const std::string& appPackage, const std::vector &inputPidTidArgs); -bool NeedAdaptSandboxPath(char *filename, int pid, u16 &headerSize); +bool NeedAdaptSandboxPath(char *filename, const int pid, u16 &headerSize); bool NeedAdaptHMBundlePath(std::string& filename, const std::string& threadname); template diff --git a/include/virtual_runtime.h b/include/virtual_runtime.h index 07bcb36e489a7fc020e79d1bc26b08cb79fbf27f..d94a9a0dab1356f1af6ef08a703a1e3774232fb1 100644 --- a/include/virtual_runtime.h +++ b/include/virtual_runtime.h @@ -45,7 +45,7 @@ using uSymbolsHits = std::unordered_map>; class VirtualRuntime { public: - explicit VirtualRuntime(bool onDevice = true); + explicit VirtualRuntime(const bool onDevice = true); ~VirtualRuntime(); // thread need hook the record // from the record , it will call back to write some Simulated Record @@ -54,8 +54,8 @@ public: using RecordCallBack = std::function; using CollectSymbolCallBack = std::function; - void SetRecordMode(RecordCallBack recordCallBack); - void SetCollectSymbolCallBack(CollectSymbolCallBack collectSymbolCallBack); + void SetRecordMode(const RecordCallBack &recordCallBack); + void SetCollectSymbolCallBack(const CollectSymbolCallBack &collectSymbolCallBack); // this both used in report and record follow // it process the record, and rebuild the trhread maps @@ -78,8 +78,8 @@ public: void UpdateDevhostSymbols(); pid_t devhostPid_ = -1; - void SetDevhostPid(pid_t devhost); - void FixHMBundleMmap(char *filename, int pid, u16 &headerSize); + void SetDevhostPid(const pid_t devhost); + void FixHMBundleMmap(char *filename, const int pid, u16 &headerSize); // set symbols path , it will send to every symobile file for search bool SetSymbolsPaths(const std::vector &symbolsPaths); @@ -97,18 +97,18 @@ public: return &processStackMap_; } - void SetCallStackExpend(size_t mergeLevel = 0) + void SetCallStackExpend(const size_t mergeLevel = 0) { callstackMergeLevel_ = mergeLevel; } - void SetDisableUnwind(bool disableUnwind) + void SetDisableUnwind(const bool disableUnwind) { HLOGV("disableUnwind change to %d", disableUnwind); disableUnwind_ = disableUnwind; } - void EnableDebugInfoSymbolic(bool enable) + void EnableDebugInfoSymbolic(const bool enable) { enableDebugInfoSymbolic_ = enable; } @@ -125,15 +125,15 @@ public: isHM_ = isHM; } - void SetNeedKernelCallChain(bool kernelCallChain) + void SetNeedKernelCallChain(const bool kernelCallChain) { needkernelCallChain_ = kernelCallChain; } - DfxSymbol GetSymbol(uint64_t ip, pid_t pid, pid_t tid, + DfxSymbol GetSymbol(const uint64_t ip, const pid_t pid, const pid_t tid, const perf_callchain_context &context = PERF_CONTEXT_MAX); void ClearSymbolCache(); - VirtualThread &GetThread(pid_t pid, pid_t tid, const std::string name = ""); + VirtualThread &GetThread(const pid_t pid, const pid_t tid, const std::string name = ""); const std::map &GetThreads() const { return userSpaceThreadMap_; @@ -144,9 +144,9 @@ public: // report use void UpdateFromPerfData(const std::vector &); void UnwindFromRecord(PerfRecordSample &recordSample); - std::string ReadThreadName(pid_t tid, bool isThread); - std::string ReadFromSavedCmdLines(pid_t tid); - bool IsKernelThread(pid_t pid); + std::string ReadThreadName(const pid_t tid, const bool isThread); + std::string ReadFromSavedCmdLines(const pid_t tid); + bool IsKernelThread(const pid_t pid); void CollectDedupSymbol(kSymbolsHits &kernelSymbolsHits, uSymbolsHits &userSymbolsHits); // debug time @@ -191,11 +191,11 @@ private: HashList userSymbolCache_; HashList kernelSymbolCache_ {KERNEL_SYMBOL_CACHE_LIMIT}; HashList kThreadSymbolCache_ {KERNEL_SYMBOL_CACHE_LIMIT}; - bool GetSymbolCache(uint64_t fileVaddr, DfxSymbol &symbol, + bool GetSymbolCache(const uint64_t fileVaddr, DfxSymbol &symbol, const perf_callchain_context &context); // find synbols function name void MakeCallFrame(DfxSymbol &symbol, DfxFrame &callFrame); - void UpdateSymbols(std::shared_ptr map, pid_t pid); + void UpdateSymbols(std::shared_ptr map, const pid_t pid); // we don't know whether hap vma mapping is stand for a so // thus we need try to parse it first bool UpdateHapSymbols(std::shared_ptr map); @@ -206,28 +206,30 @@ private: void DedupFromRecord(PerfRecordSample *recordSample); void UpdateFromRecord(PerfRecordAuxtrace &recordAuxTrace); // threads - VirtualThread &UpdateThread(pid_t pid, pid_t tid, const std::string name = ""); - VirtualThread &CreateThread(pid_t pid, pid_t tid, const std::string name = ""); + VirtualThread &UpdateThread(const pid_t pid, const pid_t tid, const std::string name = ""); + VirtualThread &CreateThread(const pid_t pid, const pid_t tid, const std::string name = ""); // maps - std::shared_ptr UpdateThreadMaps(pid_t pid, pid_t tid, const std::string filename, uint64_t begin, - uint64_t len, uint64_t offset, uint32_t prot = 0); - void UpdatekernelMap(uint64_t begin, uint64_t end, uint64_t offset, std::string filename); - - const DfxSymbol GetKernelSymbol(uint64_t ip, const std::vector &memMaps, - const VirtualThread &thread); - const DfxSymbol GetUserSymbol(uint64_t ip, const VirtualThread &thread); - const DfxSymbol GetKernelThreadSymbol(uint64_t ip, const VirtualThread &thread); + std::shared_ptr UpdateThreadMaps(const pid_t pid, const pid_t tid, const std::string filename, + const uint64_t begin, const uint64_t len, const uint64_t offset, + const uint32_t prot = 0); + void UpdatekernelMap(const uint64_t begin, const uint64_t end, const uint64_t offset, const std::string &filename); + + const DfxSymbol GetKernelSymbol(const uint64_t ip, const std::vector &memMaps, + const VirtualThread &thread); + const DfxSymbol GetUserSymbol(const uint64_t ip, const VirtualThread &thread); + const DfxSymbol GetKernelThreadSymbol(const uint64_t ip, const VirtualThread &thread); #ifdef HIPERF_DEBUG std::unordered_set missedRuntimeVaddr_; #endif - void SymbolicCallFrame(PerfRecordSample &recordSample, uint64_t ip, - pid_t serverPid, perf_callchain_context context); + void SymbolicCallFrame(PerfRecordSample &recordSample, const uint64_t ip, + const pid_t serverPid, const perf_callchain_context context); bool RecoverCallStack(PerfRecordSample &recordSample); std::vector symbolsPaths_; // kernel thread - void UpdateKernelThreadMap(pid_t pid, uint64_t begin, uint64_t len, uint64_t offset, std::string filename); + void UpdateKernelThreadMap(const pid_t pid, const uint64_t begin, const uint64_t len, + const uint64_t offset, const std::string &filename); bool CheckValidSandBoxMmap(PerfRecordMmap2 &recordMmap2); void ProcessKernelCallChain(PerfRecordSample &sample); void AdjustCallChain(PerfRecordSample &sample); diff --git a/include/virtual_thread.h b/include/virtual_thread.h index 89f16a5d8b5950afdffeb51707fbe388ba3c13c4..8206a634d40d7c830f0e63180e5fce4be51462b6 100644 --- a/include/virtual_thread.h +++ b/include/virtual_thread.h @@ -43,7 +43,7 @@ public: VirtualThread(const VirtualThread &) = delete; VirtualThread &operator=(const VirtualThread &) = delete; - VirtualThread(pid_t pid, const std::vector> &symbolsFiles) + VirtualThread(const pid_t pid, const std::vector> &symbolsFiles) : pid_(pid), tid_(pid), symbolsFiles_(symbolsFiles), @@ -53,7 +53,7 @@ public: memMapsIndexs_(processMemMapsIndexs_), parent_(*this) {} - VirtualThread(pid_t pid, pid_t tid, VirtualThread &thread, + VirtualThread(const pid_t pid, const pid_t tid, VirtualThread &thread, const std::vector> &symbolsFiles) : pid_(pid), tid_(tid), @@ -68,8 +68,8 @@ public: HLOGV("%d %d map from parent size is %zu", pid, tid, memMaps_.size()); }; - pid_t pid_; - pid_t tid_; + pid_t pid_ = -1; + pid_t tid_ = -1; std::string name_; const std::vector> &GetMaps() const @@ -79,16 +79,16 @@ public: void ParseMap(); void FixHMBundleMap(); void ParseServiceMap(const std::string &filename); - void ParseDevhostMap(pid_t devhost); - std::shared_ptr CreateMapItem(const std::string filename, uint64_t begin, - uint64_t len, uint64_t offset, uint32_t prot = 0); - std::shared_ptr FindMapByAddr(uint64_t addr) const; - std::shared_ptr FindMapByFileInfo(const std::string name, uint64_t offset) const; - int64_t FindMapIndexByAddr(uint64_t addr) const; + void ParseDevhostMap(const pid_t devhost); + std::shared_ptr CreateMapItem(const std::string &filename, const uint64_t begin, + const uint64_t len, const uint64_t offset, const uint32_t prot = 0); + std::shared_ptr FindMapByAddr(const uint64_t addr) const; + std::shared_ptr FindMapByFileInfo(const std::string name, const uint64_t offset) const; + int64_t FindMapIndexByAddr(const uint64_t addr) const; SymbolsFile *FindSymbolsFileByMap(std::shared_ptr map) const; - bool ReadRoMemory(uint64_t vaddr, uint8_t *data, size_t size) const; + bool ReadRoMemory(const uint64_t vaddr, uint8_t *data, const size_t size) const; #ifdef HIPERF_DEBUG - void ReportVaddrMapMiss(uint64_t vaddr) const; + void ReportVaddrMapMiss(const uint64_t vaddr) const; #endif private: diff --git a/interfaces/innerkits/native/hiperf_client/src/hiperf_client.cpp b/interfaces/innerkits/native/hiperf_client/src/hiperf_client.cpp index 27fc2aa4ae424def70fab056b6b23fa98834255d..e942eb4a30c19d0fb471b6d9f2e9897959150012 100644 --- a/interfaces/innerkits/native/hiperf_client/src/hiperf_client.cpp +++ b/interfaces/innerkits/native/hiperf_client/src/hiperf_client.cpp @@ -335,8 +335,8 @@ void RecordOption::SetBackTrackSec(int backTracesec) Client::Client(const std::string &outputDir) { - HIPERF_HILOGI(MODULE_CPP_API, "%" HILOG_PUBLIC "s default init with %" HILOG_PUBLIC "s\n", - __FUNCTION__, outputDir.c_str()); + HIPERF_HILOGI(MODULE_CPP_API, "%" HILOG_PUBLIC "s default init\n", + __FUNCTION__); Setup(outputDir); } @@ -347,7 +347,7 @@ bool Client::Setup(std::string outputDir) if (!outputDir.empty() && outputDir.back() != '/') { outputDir.push_back('/'); } - HIPERF_HILOGI(MODULE_CPP_API, "outputDir setup to %" HILOG_PUBLIC "s\n", outputDir.c_str()); + HIPERF_HILOGI(MODULE_CPP_API, "outputDir setup\n"); executeCommandPath_ = SystemCommandPath; diff --git a/src/callstack.cpp b/src/callstack.cpp index cbe9f1969f843d2bba6bebd061db1338e5e22a7e..96620a3537a3cd3aef40f4cf52047b1a53662274 100644 --- a/src/callstack.cpp +++ b/src/callstack.cpp @@ -39,7 +39,7 @@ namespace Developtools { namespace HiPerf { using namespace OHOS::HiviewDFX; -bool CallStack::ReadVirtualThreadMemory(UnwindInfo &unwindInfoPtr, ADDR_TYPE vaddr, ADDR_TYPE *data) +bool CallStack::ReadVirtualThreadMemory(UnwindInfo &unwindInfoPtr, const ADDR_TYPE vaddr, ADDR_TYPE *data) { if (__builtin_expect(unwindInfoPtr.thread.pid_ == unwindInfoPtr.callStack.lastPid_ && vaddr == unwindInfoPtr.callStack.lastAddr_, true)) { @@ -59,7 +59,7 @@ bool CallStack::ReadVirtualThreadMemory(UnwindInfo &unwindInfoPtr, ADDR_TYPE vad } } -bool CallStack::GetIpSP(uint64_t &ip, uint64_t &sp, const u64 *regs, size_t regNum) const +bool CallStack::GetIpSP(uint64_t &ip, uint64_t &sp, const u64 *regs, const size_t regNum) const { if (regNum > 0) { CHECK_TRUE(RegisterGetSPValue(sp, arch_, regs, regNum), false, 1, "unable get sp"); @@ -74,9 +74,9 @@ bool CallStack::GetIpSP(uint64_t &ip, uint64_t &sp, const u64 *regs, size_t regN return false; } -bool CallStack::UnwindCallStack(const VirtualThread &thread, bool abi32, u64 *regs, u64 regsNum, - const u8 *stack, u64 stackSize, std::vector &callStack, - size_t maxStackLevel) +bool CallStack::UnwindCallStack(const VirtualThread &thread, const bool abi32, u64 *regs, const u64 regsNum, + const u8 *stack, const u64 stackSize, std::vector &callStack, + const size_t maxStackLevel) { regs_ = regs; regsNum_ = regsNum; @@ -141,7 +141,7 @@ use expandLimit to setup how may frame match is needs */ size_t CallStack::DoExpandCallStack(std::vector &newCallFrames, const std::vector &cachedCallFrames, - size_t expandLimit) + const size_t expandLimit) { int maxCycle = 0; @@ -206,7 +206,7 @@ size_t CallStack::DoExpandCallStack(std::vector &newCallFrames, return 0u; // nothing expand } -size_t CallStack::ExpandCallStack(pid_t tid, std::vector &callFrames, size_t expandLimit) +size_t CallStack::ExpandCallStack(const pid_t tid, std::vector &callFrames, const size_t expandLimit) { size_t expand = 0u; if (expandLimit == 0) { @@ -257,7 +257,7 @@ size_t CallStack::ExpandCallStack(pid_t tid, std::vector &callFrames, #if defined(HAVE_LIBUNWINDER) && HAVE_LIBUNWINDER bool CallStack::DoUnwind2(const VirtualThread &thread, std::vector &callStack, - size_t maxStackLevel) + const size_t maxStackLevel) { #ifdef target_cpu_x86_64 return false; @@ -314,7 +314,7 @@ void CallStack::DumpTableInfo(UnwindTableInfo &outTableInfo) } int CallStack::FillUnwindTable(SymbolsFile *symbolsFile, std::shared_ptr map, UnwindInfo *unwindInfoPtr, - uintptr_t pc, UnwindTableInfo& outTableInfo) + const uintptr_t pc, UnwindTableInfo& outTableInfo) { HLOGM("try search debug info at %s", symbolsFile->filePath_.c_str()); CHECK_TRUE(unwindInfoPtr != nullptr, -1, 0, ""); @@ -348,7 +348,7 @@ int CallStack::FillUnwindTable(SymbolsFile *symbolsFile, std::shared_ptr return -1; } -int CallStack::FindUnwindTable(uintptr_t pc, UnwindTableInfo& outTableInfo, void *arg) +int CallStack::FindUnwindTable(const uintptr_t pc, UnwindTableInfo& outTableInfo, void *arg) { UnwindInfo *unwindInfoPtr = static_cast(arg); CHECK_TRUE(unwindInfoPtr != nullptr, -1, 0, ""); @@ -373,7 +373,7 @@ int CallStack::FindUnwindTable(uintptr_t pc, UnwindTableInfo& outTableInfo, void return -1; } -int CallStack::AccessMem2(uintptr_t addr, uintptr_t *val, void *arg) +int CallStack::AccessMem2(const uintptr_t addr, uintptr_t *val, void *arg) { UnwindInfo *unwindInfoPtr = static_cast(arg); *val = 0; @@ -406,7 +406,7 @@ int CallStack::AccessMem2(uintptr_t addr, uintptr_t *val, void *arg) return 0; } -int CallStack::GetMapByPc(uintptr_t pc, std::shared_ptr& map, void *arg) +int CallStack::GetMapByPc(const uintptr_t pc, std::shared_ptr& map, void *arg) { UnwindInfo *unwindInfoPtr = static_cast(arg); int64_t mapIndex = unwindInfoPtr->thread.FindMapIndexByAddr(pc); diff --git a/src/debug_logger.cpp b/src/debug_logger.cpp index d314945bbc8517491d4aa33077f7efa09038e2f1..8cfe4cad0b8f2519c654450a4377d60e6593d731 100644 --- a/src/debug_logger.cpp +++ b/src/debug_logger.cpp @@ -49,7 +49,7 @@ DebugLogger::~DebugLogger() } } -void DebugLogger::Disable(bool disable) +void DebugLogger::Disable(const bool disable) { if (logDisabled_ != disable) { logDisabled_ = disable; @@ -74,7 +74,7 @@ int DebugLogger::HiLog(std::string &buffer) const #endif #endif -int DebugLogger::Log(DebugLevel level, const std::string &logTag, const char *fmt, ...) const +int DebugLogger::Log(const DebugLevel level, const std::string &logTag, const char *fmt, ...) const { constexpr const int DEFAULT_STRING_BUF_SIZE = 4096; #ifdef HIPERF_DEBUG_TIME @@ -130,7 +130,7 @@ int DebugLogger::Log(DebugLevel level, const std::string &logTag, const char *fm return ret; } -bool DebugLogger::EnableHiLog(bool enable) +bool DebugLogger::EnableHiLog(const bool enable) { enableHilog_ = enable; if (enable) { @@ -141,12 +141,12 @@ bool DebugLogger::EnableHiLog(bool enable) return enableHilog_; } -bool DebugLogger::ShouldLog(DebugLevel level, const std::string &logtag) const +bool DebugLogger::ShouldLog(const DebugLevel level, const std::string &logtag) const { return GetLogLevelByTag(logtag) <= level; } -DebugLevel DebugLogger::SetLogLevel(DebugLevel debugLevel) +DebugLevel DebugLogger::SetLogLevel(const DebugLevel debugLevel) { DebugLevel lastLevel = DebugLogger::GetInstance()->debugLevel_; debugLevel_ = debugLevel; @@ -155,7 +155,7 @@ DebugLevel DebugLogger::SetLogLevel(DebugLevel debugLevel) return lastLevel; } -bool DebugLogger::SetMixLogOutput(bool enable) +bool DebugLogger::SetMixLogOutput(const bool enable) { bool lastMixLogOutput = mixLogOutput_; mixLogOutput_ = enable; @@ -209,7 +209,7 @@ DebugLevel DebugLogger::GetLogLevelByTag(const std::string &tag) const } } -const std::string DebugLogger::GetLogLevelName(DebugLevel level) const +const std::string DebugLogger::GetLogLevelName(const DebugLevel level) const { return DebugLevelMap.at(level); } diff --git a/src/ipc_utilities.cpp b/src/ipc_utilities.cpp index 924ba682f066f553be70d7c4ec967e8bf78dc885..55160dbce9dfbe103627b89ec494b1b80e7e1402 100644 --- a/src/ipc_utilities.cpp +++ b/src/ipc_utilities.cpp @@ -74,13 +74,13 @@ bool IsDebugableApp(const std::string& bundleName) err = "appProvisionType is " + appInfo.appProvisionType; break; } - HIPERF_HILOGI(MODULE_DEFAULT, "bundleName is %{public}s,appProvisionType: %{public}s", - bundleName.c_str(), appInfo.appProvisionType.c_str()); + HIPERF_HILOGI(MODULE_DEFAULT, "appProvisionType: %{public}s", + appInfo.appProvisionType.c_str()); return true; } while (0); - HIPERF_HILOGE(MODULE_DEFAULT, "IsDebugableApp error, bundleName: [%{public}s] err: [%{public}s]", - bundleName.c_str(), err.c_str()); + HIPERF_HILOGE(MODULE_DEFAULT, "IsDebugableApp error, err: [%{public}s]", + err.c_str()); return false; #else return false; diff --git a/src/perf_event_record.cpp b/src/perf_event_record.cpp index d6d9695ebcf2d5e7ee76efda21ef71771d27aa42..232796ce2cd27369dba15292b5167c87d35e974d 100644 --- a/src/perf_event_record.cpp +++ b/src/perf_event_record.cpp @@ -78,7 +78,7 @@ static PerfEventRecord* CreatePerfEventRecord(PerfRecordType type) } template -inline void PushToBinary(bool condition, uint8_t *&p, const T &v) +inline void PushToBinary(const bool condition, uint8_t *&p, const T &v) { if (condition) { *(reinterpret_cast(p)) = v; @@ -87,7 +87,7 @@ inline void PushToBinary(bool condition, uint8_t *&p, const T &v) } template -inline void PushToBinary2(bool condition, uint8_t *&p, const T1 &v1, const T2 &v2) +inline void PushToBinary2(const bool condition, uint8_t *&p, const T1 &v1, const T2 &v2) { if (condition) { *(reinterpret_cast(p)) = v1; @@ -98,7 +98,7 @@ inline void PushToBinary2(bool condition, uint8_t *&p, const T1 &v1, const T2 &v } template -inline void PopFromBinary(bool condition, uint8_t*& p, T& v, u64& size) +inline void PopFromBinary(const bool condition, uint8_t*& p, T& v, u64& size) { HIPERF_ASSERT(sizeof(T) <= size, "PopFromBinary error\n"); if (condition) { @@ -109,7 +109,7 @@ inline void PopFromBinary(bool condition, uint8_t*& p, T& v, u64& size) } template -inline void PopFromBinary2(bool condition, uint8_t*& p, T1& v1, T2& v2, u64& size) +inline void PopFromBinary2(const bool condition, uint8_t*& p, T1& v1, T2& v2, u64& size) { HIPERF_ASSERT(sizeof(T1) + sizeof(T2) <= size, "PopFromBinary2 error\n"); if (condition) { @@ -137,7 +137,7 @@ void PerfEventRecord::GetHeaderBinary(std::vector &buf) const *(reinterpret_cast(p)) = header_; } -void PerfEventRecord::Dump(int indent, std::string outputFilename, FILE *outputDump) const +void PerfEventRecord::Dump(const int indent, std::string outputFilename, FILE *outputDump) const { if (outputDump != nullptr) { g_outputDump = outputDump; @@ -161,14 +161,14 @@ void PerfEventRecord::DumpLog(const std::string &prefix) const GetType(), GetMisc(), GetSize()); } -void PerfEventRecord::Init(perf_event_type type, bool inKernel) +void PerfEventRecord::Init(const perf_event_type type, const bool inKernel) { header_.type = type; header_.misc = inKernel ? PERF_RECORD_MISC_KERNEL : PERF_RECORD_MISC_USER; header_.size = sizeof(header_); }; -void PerfEventRecord::Init(perf_event_hiperf_ext_type type) +void PerfEventRecord::Init(const perf_event_hiperf_ext_type type) { header_.type = type; header_.misc = PERF_RECORD_MISC_USER; @@ -203,7 +203,8 @@ void PerfRecordAuxtrace::Init(uint8_t* data, const perf_event_attr& attr) rawData_ = data + header_.size; } -PerfRecordAuxtrace::PerfRecordAuxtrace(u64 size, u64 offset, u64 reference, u32 idx, u32 tid, u32 cpu, u32 pid) +PerfRecordAuxtrace::PerfRecordAuxtrace(const u64 size, const u64 offset, const u64 reference, const u32 idx, + const u32 tid, const u32 cpu, const u32 pid) { PerfEventRecord::Init(PERF_RECORD_AUXTRACE); data_.size = size; @@ -256,7 +257,7 @@ bool PerfRecordAuxtrace::GetBinary(std::vector &buf) const return true; } -void PerfRecordAuxtrace::DumpData(int indent) const +void PerfRecordAuxtrace::DumpData(const int indent) const { PRINT_INDENT(indent, "size 0x%llx, offset 0x%llx, reference 0x%llx, idx %u, tid %u, cpu %u, pid %u\n", data_.size, data_.offset, data_.reference, data_.idx, data_.tid, data_.cpu, data_.reserved__); @@ -316,7 +317,7 @@ bool PerfRecordMmap::GetBinary(std::vector &buf) const return true; } -void PerfRecordMmap::DumpData(int indent) const +void PerfRecordMmap::DumpData(const int indent) const { #if defined(is_ohos) && is_ohos if (IsRoot()) { @@ -339,9 +340,9 @@ void PerfRecordMmap2::Init(uint8_t* data, const perf_event_attr&) discard_ = false; } -PerfRecordMmap2::PerfRecordMmap2(bool inKernel, u32 pid, u32 tid, u64 addr, u64 len, u64 pgoff, - u32 maj, u32 min, u64 ino, u32 prot, u32 flags, - const std::string &filename) +PerfRecordMmap2::PerfRecordMmap2(const bool inKernel, const u32 pid, const u32 tid, const u64 addr, const u64 len, + const u64 pgoff, const u32 maj, const u32 min, const u64 ino, const u32 prot, + const u32 flags, const std::string &filename) { PerfEventRecord::Init(PERF_RECORD_MMAP2, inKernel); data_.pid = pid; @@ -362,7 +363,7 @@ PerfRecordMmap2::PerfRecordMmap2(bool inKernel, u32 pid, u32 tid, u64 addr, u64 header_.size = sizeof(header_) + sizeof(data_) - KILO + filename.size() + 1; } -PerfRecordMmap2::PerfRecordMmap2(bool inKernel, u32 pid, u32 tid, std::shared_ptr item) +PerfRecordMmap2::PerfRecordMmap2(const bool inKernel, const u32 pid, const u32 tid, std::shared_ptr item) { PerfEventRecord::Init(PERF_RECORD_MMAP2, inKernel); data_.pid = pid; @@ -412,7 +413,7 @@ bool PerfRecordMmap2::GetBinary(std::vector &buf) const return true; } -void PerfRecordMmap2::DumpData(int indent) const +void PerfRecordMmap2::DumpData(const int indent) const { #if defined(is_ohos) && is_ohos if (IsRoot()) { @@ -448,7 +449,7 @@ bool PerfRecordLost::GetBinary(std::vector &buf) const return true; } -void PerfRecordLost::DumpData(int indent) const +void PerfRecordLost::DumpData(const int indent) const { PRINT_INDENT(indent, "id %llu, lost %llu\n", data_.id, data_.lost); } @@ -459,7 +460,7 @@ void PerfRecordComm::Init(uint8_t* data, const perf_event_attr&) data_.comm[KILO - 1] = '\0'; } -PerfRecordComm::PerfRecordComm(bool inKernel, u32 pid, u32 tid, const std::string &comm) +PerfRecordComm::PerfRecordComm(const bool inKernel, const u32 pid, const u32 tid, const std::string &comm) { PerfEventRecord::Init(PERF_RECORD_COMM, inKernel); data_.pid = pid; @@ -487,7 +488,7 @@ bool PerfRecordComm::GetBinary(std::vector &buf) const return true; } -void PerfRecordComm::DumpData(int indent) const +void PerfRecordComm::DumpData(const int indent) const { PRINT_INDENT(indent, "pid %u, tid %u, comm %s\n", data_.pid, data_.tid, data_.comm); } @@ -647,7 +648,7 @@ bool PerfRecordSample::GetBinary(std::vector &buf) const return true; } -void PerfRecordSample::DumpData(int indent) const +void PerfRecordSample::DumpData(const int indent) const { PRINT_INDENT(indent, "sample_type: 0x%" PRIx64 "\n", sampleType_); @@ -750,7 +751,7 @@ void PerfRecordSample::RecoverCallStack() removeStack_ = true; } -void PerfRecordSample::ReplaceWithCallStack(size_t originalSize) +void PerfRecordSample::ReplaceWithCallStack(const size_t originalSize) { // first we check if we have some user unwind stack need to merge ? if (callFrames_.size() != 0) { @@ -905,7 +906,7 @@ bool PerfRecordExit::GetBinary(std::vector &buf) const return true; } -void PerfRecordExit::DumpData(int indent) const +void PerfRecordExit::DumpData(const int indent) const { PRINT_INDENT(indent, "pid %u, ppid %u, tid %u, ptid %u time 0x%llx\n", data_.pid, data_.ppid, data_.tid, data_.ptid, data_.time); @@ -925,7 +926,7 @@ bool PerfRecordThrottle::GetBinary(std::vector &buf) const return true; } -void PerfRecordThrottle::DumpData(int indent) const +void PerfRecordThrottle::DumpData(const int indent) const { PRINT_INDENT(indent, "time 0x%llx, id %llx, stream_id %llx\n", data_.time, data_.id, data_.stream_id); @@ -945,7 +946,7 @@ bool PerfRecordUnthrottle::GetBinary(std::vector &buf) const return true; } -void PerfRecordUnthrottle::DumpData(int indent) const +void PerfRecordUnthrottle::DumpData(const int indent) const { PRINT_INDENT(indent, "time 0x%llx, id %llx, stream_id %llx\n", data_.time, data_.id, data_.stream_id); @@ -965,7 +966,7 @@ bool PerfRecordFork::GetBinary(std::vector &buf) const return true; } -void PerfRecordFork::DumpData(int indent) const +void PerfRecordFork::DumpData(const int indent) const { PRINT_INDENT(indent, "pid %u, ppid %u, tid %u, ptid %u\n", data_.pid, data_.ppid, data_.tid, data_.ptid); @@ -985,7 +986,7 @@ bool PerfRecordRead::GetBinary(std::vector &buf) const return true; } -void PerfRecordRead::DumpData(int indent) const +void PerfRecordRead::DumpData(const int indent) const { PRINT_INDENT(indent, "pid %u, tid %u\n", data_.pid, data_.tid); PRINT_INDENT(indent, "values: value %llx, timeEnabled %llx, timeRunning %llx, id %llx\n", @@ -1014,7 +1015,7 @@ bool PerfRecordAux::GetBinary(std::vector &buf) const return true; } -void PerfRecordAux::DumpData(int indent) const +void PerfRecordAux::DumpData(const int indent) const { PRINT_INDENT(indent, "aux_offset 0x%llx aux_size 0x%llx flags 0x%llx pid %u tid %u time %llu", data_.aux_offset, data_.aux_size, data_.flags, data_.sample_id.pid, data_.sample_id.tid, @@ -1034,7 +1035,7 @@ bool PerfRecordAuxTraceInfo::GetBinary(std::vector &buf) const return true; } -void PerfRecordAuxTraceInfo::DumpData(int indent) const +void PerfRecordAuxTraceInfo::DumpData(const int indent) const { PRINT_INDENT(indent, "aux_trace_event"); } @@ -1052,7 +1053,7 @@ bool PerfRecordTimeConv::GetBinary(std::vector &buf) const return true; } -void PerfRecordTimeConv::DumpData(int indent) const +void PerfRecordTimeConv::DumpData(const int indent) const { PRINT_INDENT(indent, "aux_time_event"); } @@ -1070,7 +1071,7 @@ bool PerfRecordCpuMap::GetBinary(std::vector &buf) const return true; } -void PerfRecordCpuMap::DumpData(int indent) const +void PerfRecordCpuMap::DumpData(const int indent) const { PRINT_INDENT(indent, "cpu_map_event"); } @@ -1089,7 +1090,7 @@ bool PerfRecordItraceStart::GetBinary(std::vector &buf) const return true; } -void PerfRecordItraceStart::DumpData(int indent) const +void PerfRecordItraceStart::DumpData(const int indent) const { PRINT_INDENT(indent, "pid %u, tid %u\n", data_.pid, data_.tid); } @@ -1108,7 +1109,7 @@ bool PerfRecordLostSamples::GetBinary(std::vector &buf) const return true; } -void PerfRecordLostSamples::DumpData(int indent) const +void PerfRecordLostSamples::DumpData(const int indent) const { PRINT_INDENT(indent, "lost %llu\n", data_.lost); } @@ -1141,7 +1142,7 @@ bool PerfRecordSwitchCpuWide::GetBinary(std::vector &buf) const return true; } -void PerfRecordSwitchCpuWide::DumpData(int indent) const +void PerfRecordSwitchCpuWide::DumpData(const int indent) const { PRINT_INDENT(indent, "next_prev_pid %u, next_prev_tid %u\n", data_.next_prev_pid, data_.next_prev_tid); diff --git a/src/perf_events.cpp b/src/perf_events.cpp index 2b0be44f5b5936a309d0d5ad309b8f6ef6ab1bf0..5f47bd5edbf35868388f723aa3d95c07b4a4ac49 100644 --- a/src/perf_events.cpp +++ b/src/perf_events.cpp @@ -48,8 +48,8 @@ static constexpr int32_t UPDATE_TIME_INTERVAL = 10; // 10ms static constexpr uint64_t NANO_SECONDS_PER_SECOND = 1000000000; static constexpr uint32_t POLL_FAIL_COUNT_THRESHOLD = 10; -OHOS::UniqueFd PerfEvents::Open(perf_event_attr &attr, pid_t pid, int cpu, int groupFd, - unsigned long flags) +OHOS::UniqueFd PerfEvents::Open(perf_event_attr &attr, const pid_t pid, const int cpu, const int groupFd, + const unsigned long flags) { OHOS::UniqueFd fd = UniqueFd(syscall(__NR_perf_event_open, &attr, pid, cpu, groupFd, flags)); if (fd < 0) { @@ -61,7 +61,7 @@ OHOS::UniqueFd PerfEvents::Open(perf_event_attr &attr, pid_t pid, int cpu, int g return fd; } -void PerfEvents::SpeReadData(void *dataPage, u64 *dataTail, uint8_t *buf, u32 size) +void PerfEvents::SpeReadData(void *dataPage, u64 *dataTail, uint8_t *buf, const u32 size) { void *src = nullptr; u32 left = 0; @@ -94,7 +94,8 @@ static u64 arm_spe_reference() return static_cast(ts.tv_sec) ^ static_cast(ts.tv_nsec); } -void PerfEvents::ReadRecordsFromSpeMmaps(MmapFd& mmapFd, u64 auxOffset, u64 auxSize, u32 pid, u32 tid) +void PerfEvents::ReadRecordsFromSpeMmaps(MmapFd& mmapFd, const u64 auxOffset, + u64 auxSize, const u32 pid, const u32 tid) { if (mmapFd.mmapPage == nullptr || mmapFd.auxBuf == nullptr) { printf("ReadRecordsFromSpeMmaps mmapFd.mmapPage == nullptr, mmapFd.fd: %d", mmapFd.fd); @@ -201,7 +202,7 @@ PerfEvents::~PerfEvents() } } -bool PerfEvents::IsEventSupport(perf_type_id type, __u64 config) +bool PerfEvents::IsEventSupport(const perf_type_id type, const __u64 config) { std::unique_ptr attr = PerfEvents::CreateDefaultAttr(type, config); CHECK_TRUE(attr != nullptr, false, 1, "attr is nullptr"); @@ -221,7 +222,7 @@ bool PerfEvents::IsEventAttrSupport(perf_event_attr &attr) return true; } -bool PerfEvents::SetBranchSampleType(uint64_t value) +bool PerfEvents::SetBranchSampleType(const uint64_t value) { if (value != 0) { // cpu-clcles event must be supported @@ -238,7 +239,7 @@ bool PerfEvents::SetBranchSampleType(uint64_t value) return true; } -bool PerfEvents::AddDefaultEvent(perf_type_id type) +bool PerfEvents::AddDefaultEvent(const perf_type_id type) { auto it = DEFAULT_TYPE_CONFIGS.find(type); if (it != DEFAULT_TYPE_CONFIGS.end()) { @@ -260,7 +261,7 @@ bool PerfEvents::AddOffCpuEvent() return AddEvent(eventName); } -bool PerfEvents::AddEvents(const std::vector &eventStrings, bool group) +bool PerfEvents::AddEvents(const std::vector &eventStrings, const bool group) { bool followGroup = false; HLOGV(" %s", VectorToString(eventStrings).c_str()); @@ -336,7 +337,7 @@ bool PerfEvents::ParseEventName(const std::string &nameStr, return true; } -bool PerfEvents::AddEvent(const std::string &eventString, bool followGroup) +bool PerfEvents::AddEvent(const std::string &eventString, const bool followGroup) { std::string eventName; bool excludeUser = false; @@ -389,7 +390,7 @@ bool PerfEvents::AddEvent(const std::string &eventString, bool followGroup) return false; } -bool PerfEvents::AddSpeEvent(u32 type, bool followGroup) +bool PerfEvents::AddSpeEvent(const u32 type, const bool followGroup) { EventGroupItem &eventGroupItem = followGroup ? eventGroupItem_.back() : eventGroupItem_.emplace_back(); @@ -442,8 +443,8 @@ void PerfEvents::SetConfig(std::map &speOptMaps) config2_ |= speOptMaps["min_latency"] & 0xfff; } -bool PerfEvents::AddEvent(perf_type_id type, __u64 config, bool excludeUser, bool excludeKernel, - bool followGroup) +bool PerfEvents::AddEvent(const perf_type_id type, const __u64 config, const bool excludeUser, + const bool excludeKernel, const bool followGroup) { HLOG_ASSERT(!excludeUser || !excludeKernel); CHECK_TRUE(!followGroup || !eventGroupItem_.empty(), false, 1, "no group leader create before"); @@ -549,7 +550,7 @@ bool PerfEvents::AddEvent(perf_type_id type, __u64 config, bool excludeUser, boo return true; } -std::unique_ptr PerfEvents::CreateDefaultAttr(perf_type_id type, __u64 config) +std::unique_ptr PerfEvents::CreateDefaultAttr(const perf_type_id type, const __u64 config) { std::unique_ptr attr = std::make_unique(); if (memset_s(attr.get(), sizeof(perf_event_attr), 0, sizeof(perf_event_attr)) != EOK) { @@ -676,7 +677,7 @@ void PerfEvents::WaitRecordThread() #endif } -bool PerfEvents::StartTracking(bool immediately) +bool PerfEvents::StartTracking(const bool immediately) { if (!prepared_) { HLOGD("do not prepared_"); @@ -823,27 +824,27 @@ bool PerfEvents::IsOutputTracking() return outputTracking_; } -void PerfEvents::SetOutputTrackingStatus(bool status) +void PerfEvents::SetOutputTrackingStatus(const bool status) { outputTracking_ = status; } -void PerfEvents::SetSystemTarget(bool systemTarget) +void PerfEvents::SetSystemTarget(const bool systemTarget) { systemTarget_ = systemTarget; } -void PerfEvents::SetCpu(std::vector cpus) +void PerfEvents::SetCpu(const std::vector cpus) { cpus_ = cpus; } -void PerfEvents::SetPid(std::vector pids) +void PerfEvents::SetPid(const std::vector pids) { pids_ = pids; } -void PerfEvents::SetTimeOut(float timeOut) +void PerfEvents::SetTimeOut(const float timeOut) { if (timeOut > 0) { timeOut_ = milliseconds(static_cast(timeOut * THOUSANDS)); @@ -861,7 +862,7 @@ void PerfEvents::SetTimeReport(int timeReport) timeReport_ = milliseconds(timeReport); } -std::map<__u64, std::string> PerfEvents::GetSupportEvents(perf_type_id type) +std::map<__u64, std::string> PerfEvents::GetSupportEvents(const perf_type_id type) { if (type == PERF_TYPE_TRACEPOINT) { LoadTracepointEventTypesFromSystem(); @@ -925,22 +926,22 @@ void PerfEvents::LoadTracepointEventTypesFromSystem() } } -void PerfEvents::SetPerCpu(bool perCpu) +void PerfEvents::SetPerCpu(const bool perCpu) { perCpu_ = perCpu; } -void PerfEvents::SetPerThread(bool perThread) +void PerfEvents::SetPerThread(const bool perThread) { perThread_ = perThread; } -void PerfEvents::SetVerboseReport(bool verboseReport) +void PerfEvents::SetVerboseReport(const bool verboseReport) { verboseReport_ = verboseReport; } -void PerfEvents::SetSampleFrequency(unsigned int frequency) +void PerfEvents::SetSampleFrequency(const unsigned int frequency) { if (frequency > 0) { sampleFreq_ = frequency; @@ -959,40 +960,40 @@ void PerfEvents::SetSampleFrequency(unsigned int frequency) } } -void PerfEvents::SetSamplePeriod(unsigned int period) +void PerfEvents::SetSamplePeriod(const unsigned int period) { if (period > 0) { samplePeriod_ = period; } } -void PerfEvents::SetBackTrack(bool backtrack) +void PerfEvents::SetBackTrack(const bool backtrack) { backtrack_ = backtrack; } -void PerfEvents::SetBackTrackTime(uint64_t backtrackTime) +void PerfEvents::SetBackTrackTime(const uint64_t backtrackTime) { backtrackTime_ = backtrackTime; } -void PerfEvents::SetMmapPages(size_t mmapPages) +void PerfEvents::SetMmapPages(const size_t mmapPages) { mmapPages_ = mmapPages; } -void PerfEvents::SetSampleStackType(SampleStackType type) +void PerfEvents::SetSampleStackType(const SampleStackType type) { sampleStackType_ = type; } -void PerfEvents::SetDwarfSampleStackSize(uint32_t stackSize) +void PerfEvents::SetDwarfSampleStackSize(const uint32_t stackSize) { HLOGD("request stack size is %u", stackSize); dwarfSampleStackSize_ = stackSize; } -bool PerfEvents::PerfEventsEnable(bool enable) +bool PerfEvents::PerfEventsEnable(const bool enable) { HLOGV("%s", std::to_string(enable).c_str()); for (const auto &eventGroupItem : eventGroupItem_) { @@ -1012,12 +1013,12 @@ bool PerfEvents::PerfEventsEnable(bool enable) return true; } -void PerfEvents::SetHM(bool isHM) +void PerfEvents::SetHM(const bool isHM) { isHM_ = isHM; } -void PerfEvents::SetStatCallBack(StatCallBack reportCallBack) +void PerfEvents::SetStatCallBack(const StatCallBack reportCallBack) { reportCallBack_ = reportCallBack; } @@ -1027,7 +1028,7 @@ void PerfEvents::SetStatReportFd(FILE* reportPtr) reportPtr_ = reportPtr; } -void PerfEvents::SetRecordCallBack(RecordCallBack recordCallBack) +void PerfEvents::SetRecordCallBack(const RecordCallBack recordCallBack) { recordCallBack_ = recordCallBack; } @@ -1439,7 +1440,7 @@ size_t PerfEvents::CalcBufferSize() return bufferSize; } -inline bool PerfEvents::IsRecordInMmap(int timeout) +inline bool PerfEvents::IsRecordInMmap(const int timeout) { HLOGV("enter"); if (pollFds_.size() > 0) { @@ -1941,7 +1942,7 @@ void PerfEvents::StatLoop() } } -const std::string PerfEvents::GetTypeName(perf_type_id type_id) +const std::string PerfEvents::GetTypeName(const perf_type_id type_id) { auto it = PERF_TYPES.find(type_id); if (it != PERF_TYPES.end()) { diff --git a/src/perf_file_format.cpp b/src/perf_file_format.cpp index 83bda2e0ac561e986a75992d0e8e2e82ff949cf8..3cdfaa5fd57e8b85d38b255cf043a6f245ae033b 100644 --- a/src/perf_file_format.cpp +++ b/src/perf_file_format.cpp @@ -59,7 +59,7 @@ std::string PerfFileSection::GetFeatureName(FEATURE featureId) } // for read -void PerfFileSection::Init(const char *buffer, size_t maxSize) +void PerfFileSection::Init(const char *buffer, const size_t maxSize) { rBuffer_ = buffer; maxSize_ = maxSize; @@ -67,20 +67,20 @@ void PerfFileSection::Init(const char *buffer, size_t maxSize) } // for write -void PerfFileSection::Init(char *buffer, size_t maxSize) +void PerfFileSection::Init(char *buffer, const size_t maxSize) { wBuffer_ = buffer; maxSize_ = maxSize; offset_ = 0; } -bool PerfFileSection::Write(uint32_t u32) +bool PerfFileSection::Write(const uint32_t u32) { uint32_t value = u32; return Write((char *)&value, sizeof(uint32_t)); } -bool PerfFileSection::Write(uint64_t u64) +bool PerfFileSection::Write(const uint64_t u64) { uint64_t value = u64; return Write((char *)&value, sizeof(uint64_t)); @@ -95,12 +95,12 @@ bool PerfFileSection::Write(const std::string &str) } } -bool PerfFileSection::Write(const char *buf, size_t size) +bool PerfFileSection::Write(const char *buf, const size_t size) { return Write(buf, size, size); } -bool PerfFileSection::Write(const char *buf, size_t size, size_t max) +bool PerfFileSection::Write(const char *buf, const size_t size, const size_t max) { CHECK_TRUE(offset_ + size <= maxSize_, false, 1, "write out of size!!! offset_ %zu size %zu max %zu", offset_, size, maxSize_); @@ -156,12 +156,12 @@ bool PerfFileSection::Read(std::string &value) delete []buf; return true; } -void PerfFileSection::Skip(size_t size) +void PerfFileSection::Skip(const size_t size) { offset_ += size; } -bool PerfFileSection::Read(char *buf, size_t size) +bool PerfFileSection::Read(char *buf, const size_t size) { HLOG_ASSERT(buf != nullptr); if (size == 0) { @@ -182,25 +182,25 @@ bool PerfFileSection::Read(char *buf, size_t size) return true; } -uint32_t PerfFileSection::SizeOf(std::string &string) +uint32_t PerfFileSection::SizeOf(const std::string &string) { return sizeof(uint32_t) + string.size() + 1; /* '\0' */ } -PerfFileSectionString::PerfFileSectionString(FEATURE id, const char *buf, size_t size) +PerfFileSectionString::PerfFileSectionString(const FEATURE id, const char *buf, size_t size) : PerfFileSection(id) { Init(buf, size); CHECK_TRUE(Read(stdString_), NO_RETVAL, 0, ""); // or throw ... } -PerfFileSectionString::PerfFileSectionString(FEATURE id, const std::string &charString) +PerfFileSectionString::PerfFileSectionString(const FEATURE id, const std::string &charString) : PerfFileSection(id) { stdString_ = charString; } -bool PerfFileSectionString::GetBinary(char *buf, size_t size) +bool PerfFileSectionString::GetBinary(char *buf, const size_t size) { CHECK_TRUE(size >= GetSize(), false, 0, ""); @@ -289,7 +289,7 @@ void PerfFileSectionSymbolsFiles::ReadSymbolFileStructs() } } -PerfFileSectionSymbolsFiles::PerfFileSectionSymbolsFiles(FEATURE id, const char *buf, size_t size) +PerfFileSectionSymbolsFiles::PerfFileSectionSymbolsFiles(const FEATURE id, const char *buf, const size_t size) : PerfFileSection(id) { Init(buf, size); @@ -297,7 +297,7 @@ PerfFileSectionSymbolsFiles::PerfFileSectionSymbolsFiles(FEATURE id, const char HLOGV(" %zu SymbolFileStruct read.", symbolFileStructs_.size()); } -bool PerfFileSectionSymbolsFiles::GetBinary(char *buf, size_t size) +bool PerfFileSectionSymbolsFiles::GetBinary(char *buf, const size_t size) { HLOGV("PerfFileSectionSymbolsFiles get buffer size %zu.", size); HLOG_ASSERT(size >= GetSize()); @@ -328,7 +328,7 @@ bool PerfFileSectionSymbolsFiles::GetBinary(char *buf, size_t size) return true; } -PerfFileSectionUniStackTable::PerfFileSectionUniStackTable(FEATURE id, const char *buf, size_t size) +PerfFileSectionUniStackTable::PerfFileSectionUniStackTable(const FEATURE id, const char *buf, const size_t size) : PerfFileSection(id) { uint32_t processTableCount; @@ -354,7 +354,7 @@ PerfFileSectionUniStackTable::PerfFileSectionUniStackTable(FEATURE id, const cha } } -bool PerfFileSectionUniStackTable::GetBinary(char *buf, size_t size) +bool PerfFileSectionUniStackTable::GetBinary(char *buf, const size_t size) { HLOG_ASSERT(size >= GetSize()); Init(buf, size); @@ -394,20 +394,20 @@ size_t PerfFileSectionUniStackTable::GetSize() return size; } -PerfFileSectionNrCpus::PerfFileSectionNrCpus(FEATURE id, const char *buf, size_t size) +PerfFileSectionNrCpus::PerfFileSectionNrCpus(const FEATURE id, const char *buf, const size_t size) : PerfFileSection(id) { Init(buf, size); CHECK_TRUE(Read(nrCpusAvailable_) && Read(nrCpusOnline_), NO_RETVAL, 0, ""); } -PerfFileSectionNrCpus::PerfFileSectionNrCpus(FEATURE id, uint32_t nrCpusAvailable, - uint32_t nrCpusOnline) +PerfFileSectionNrCpus::PerfFileSectionNrCpus(const FEATURE id, const uint32_t nrCpusAvailable, + const uint32_t nrCpusOnline) : PerfFileSection(id), nrCpusAvailable_(nrCpusAvailable), nrCpusOnline_(nrCpusOnline) { } -bool PerfFileSectionNrCpus::GetBinary(char *buf, size_t size) +bool PerfFileSectionNrCpus::GetBinary(char *buf, const size_t size) { CHECK_TRUE(size >= GetSize(), false, 0, ""); @@ -428,14 +428,14 @@ void PerfFileSectionNrCpus::GetValue(uint32_t &nrCpusAvailable, uint32_t &nrCpus nrCpusOnline = nrCpusOnline_; } -PerfFileSectionU64::PerfFileSectionU64(FEATURE id, const char *buf, size_t size) +PerfFileSectionU64::PerfFileSectionU64(FEATURE id, const char *buf, const size_t size) : PerfFileSection(id) { Init(buf, size); CHECK_TRUE(Read(value_), NO_RETVAL, 0, ""); } -PerfFileSectionU64::PerfFileSectionU64(FEATURE id, uint64_t v) : PerfFileSection(id) +PerfFileSectionU64::PerfFileSectionU64(const FEATURE id, const uint64_t v) : PerfFileSection(id) { value_ = v; } @@ -466,7 +466,7 @@ PerfFileSectionEventDesc::PerfFileSectionEventDesc(FEATURE id, eventDesces_ = eventDesces; } -PerfFileSectionEventDesc::PerfFileSectionEventDesc(FEATURE id, const char *buf, size_t size) +PerfFileSectionEventDesc::PerfFileSectionEventDesc(const FEATURE id, const char *buf, const size_t size) : PerfFileSection(id) { constexpr uint32_t maxIds = 600; @@ -512,7 +512,7 @@ PerfFileSectionEventDesc::PerfFileSectionEventDesc(FEATURE id, const char *buf, HLOGV("read complete. %zu events", eventDesces_.size()); } -bool PerfFileSectionEventDesc::GetBinary(char *buf, size_t size) +bool PerfFileSectionEventDesc::GetBinary(char *buf, const size_t size) { CHECK_TRUE(size >= GetSize(), false, 0, ""); Init(buf, size); diff --git a/src/perf_file_reader.cpp b/src/perf_file_reader.cpp index e95f7b7e1d5d173816c9a5a5e0f76b127343a389..d0221e01e463712d6395ef78d61e4498a7d35329 100644 --- a/src/perf_file_reader.cpp +++ b/src/perf_file_reader.cpp @@ -313,7 +313,7 @@ bool PerfFileReader::ReadRecord(ProcessRecordCB &callback) return true; } -bool PerfFileReader::Read(void *buf, size_t len) +bool PerfFileReader::Read(void *buf, const size_t len) { if (buf == nullptr || len == 0) { HLOG_ASSERT(buf != nullptr); @@ -333,7 +333,7 @@ const perf_file_header &PerfFileReader::GetHeader() const return header_; } -bool PerfFileReader::Read(char *buf, uint64_t offset, size_t len) +bool PerfFileReader::Read(char *buf, const uint64_t offset, const size_t len) { if (buf == nullptr || len == 0) { HLOG_ASSERT(buf != nullptr); @@ -379,7 +379,7 @@ const std::string PerfFileReader::GetFeatureString(const FEATURE feature) const return EMPTY_STRING; } -const PerfFileSection *PerfFileReader::GetFeatureSection(FEATURE feature) const +const PerfFileSection *PerfFileReader::GetFeatureSection(const FEATURE feature) const { for (auto const &it : perfFileSections_) { HLOGV("perfFileSections"); diff --git a/src/perf_file_writer.cpp b/src/perf_file_writer.cpp index 252689671fd726a82767cbf89d836560f097f66d..cbbeba6b759b87d48fe31b39aa06f8d5fc920a39 100644 --- a/src/perf_file_writer.cpp +++ b/src/perf_file_writer.cpp @@ -503,7 +503,7 @@ bool PerfFileWriter::AddEventDescFeature(FEATURE feature, return true; } -bool PerfFileWriter::AddStringFeature(FEATURE feature, std::string string) +bool PerfFileWriter::AddStringFeature(FEATURE feature, const std::string& string) { HLOGV("add feature '%s' string '%s'", PerfFileSection::GetFeatureName(feature).c_str(), string.c_str()); @@ -514,13 +514,13 @@ bool PerfFileWriter::AddStringFeature(FEATURE feature, std::string string) return true; } -bool PerfFileWriter::AddBoolFeature(FEATURE feature) +bool PerfFileWriter::AddBoolFeature(const FEATURE feature) { // same as u64, just use 1 as value return AddU64Feature(feature, 1u); } -bool PerfFileWriter::AddU64Feature(FEATURE feature, uint64_t v) +bool PerfFileWriter::AddU64Feature(const FEATURE feature, const uint64_t v) { HLOGV("add feature '%s' uint64_t '%" PRIu64 "'", PerfFileSection::GetFeatureName(feature).c_str(), v); diff --git a/src/perf_pipe.cpp b/src/perf_pipe.cpp index 93238c9e683d1e98fc64ec98b7f2997d998e31fa..06b3e506e710aebe10e8ae9d78d2247522d48f91 100644 --- a/src/perf_pipe.cpp +++ b/src/perf_pipe.cpp @@ -133,7 +133,7 @@ bool PerfPipe::SendFifoAndWaitReply(const std::string &cmd, const std::chrono::m return ret; } -bool PerfPipe::WaitFifoReply(int fd, const std::chrono::milliseconds &timeOut) +bool PerfPipe::WaitFifoReply(const int fd, const std::chrono::milliseconds &timeOut) { std::string reply; WaitFifoReply(fd, timeOut, reply); @@ -141,7 +141,7 @@ bool PerfPipe::WaitFifoReply(int fd, const std::chrono::milliseconds &timeOut) return reply == HiperfClient::ReplyOK; } -void PerfPipe::WaitFifoReply(int fd, const std::chrono::milliseconds &timeOut, std::string& reply) +void PerfPipe::WaitFifoReply(const int fd, const std::chrono::milliseconds &timeOut, std::string& reply) { struct pollfd pollFd { fd, POLLIN, 0 @@ -173,12 +173,12 @@ void PerfPipe::WaitFifoReply(int fd, const std::chrono::milliseconds &timeOut, s } } -void PerfPipe::SetOutPutEnd(bool outputEnd) +void PerfPipe::SetOutPutEnd(const bool outputEnd) { outputEnd_ = outputEnd; } -void PerfPipe::ProcessStopCommand(bool ret) +void PerfPipe::ProcessStopCommand(const bool ret) { if (ret) { // wait sampling process exit really diff --git a/src/register.cpp b/src/register.cpp index 658fb270b66e97aa1b2a67a7e6afedf807a7856d..b896ef668afaa4147f7dbac139d52b03b940e629 100644 --- a/src/register.cpp +++ b/src/register.cpp @@ -40,7 +40,7 @@ static const std::map PERF_REG_NAME_MAP = { }; // these copy from kerne uapi perf_regs.h -uint64_t GetSupportedRegMask(ArchType arch) +uint64_t GetSupportedRegMask(const ArchType arch) { uint64_t result = 0; switch (arch) { @@ -66,7 +66,7 @@ uint64_t GetSupportedRegMask(ArchType arch) return result; } -const std::string UpdatePerfContext(uint64_t addr, perf_callchain_context &perfCallchainContext) +const std::string UpdatePerfContext(const uint64_t addr, perf_callchain_context &perfCallchainContext) { if (PERF_CONTEXT_NAME.count(addr) != 0) { perfCallchainContext = static_cast(addr); @@ -77,7 +77,7 @@ const std::string UpdatePerfContext(uint64_t addr, perf_callchain_context &perfC } } -const std::string GetArchName(ArchType arch) +const std::string GetArchName(const ArchType arch) { switch (arch) { case ArchType::ARCH_X86: @@ -93,7 +93,7 @@ const std::string GetArchName(ArchType arch) } } -size_t RegisterGetIP(ArchType arch) +size_t RegisterGetIP(const ArchType arch) { switch (arch) { case ArchType::ARCH_X86: @@ -123,7 +123,7 @@ size_t RegisterGetSP(ArchType arch) } } -const std::string RegisterGetName(size_t registerIndex) +const std::string RegisterGetName(const size_t registerIndex) { std::string name; name.append("PerfReg["); @@ -167,7 +167,7 @@ ArchType GetArchTypeFromUname(const std::string &machine) } } -ArchType GetArchTypeFromABI(bool abi32) +ArchType GetArchTypeFromABI(const bool abi32) { if (g_deviceArchType == ArchType::ARCH_UNKNOWN) { g_deviceArchType = GetDeviceArch(); @@ -182,7 +182,7 @@ ArchType GetArchTypeFromABI(bool abi32) return g_deviceArchType; } -ArchType SetDeviceArch(ArchType arch) +ArchType SetDeviceArch(const ArchType arch) { HLOGD("g_deviceArchType change to %s", GetArchName(arch).c_str()); g_deviceArchType = arch; @@ -214,7 +214,7 @@ ArchType GetDeviceArch() #endif } -void UpdateRegForABI(ArchType arch, u64 *regs) +void UpdateRegForABI(const ArchType arch, u64 *regs) { if (g_deviceArchType == ArchType::ARCH_ARM64 && arch == ArchType::ARCH_ARM) { // arm in arm64 diff --git a/src/report.cpp b/src/report.cpp index e6f69482785046e28afdcaec0c073c6f1f156be2..dbe79e0e86ca025b1126d6e1046c2fc2126e25ec 100644 --- a/src/report.cpp +++ b/src/report.cpp @@ -33,7 +33,7 @@ namespace OHOS { namespace Developtools { namespace HiPerf { unsigned long long ReportItem::allIndex_ = 0; -void Report::AddReportItem(const PerfRecordSample &sample, bool includeCallStack) +void Report::AddReportItem(const PerfRecordSample &sample, const bool includeCallStack) { size_t configIndex = GetConfigIndex(sample.data_.id); HLOG_ASSERT_MESSAGE(configs_.size() > configIndex, @@ -350,7 +350,7 @@ void Report::OutputStdStatistics(ReportEventConfigItem &config) fprintf(output_, "%" PRIu64 "\n", config.eventCount_); } -void Report::OutputStdHead(ReportEventConfigItem &config, bool diffMode) +void Report::OutputStdHead(ReportEventConfigItem &config, const bool diffMode) { // head print const std::string head = "Heating"; @@ -390,8 +390,8 @@ void Report::OutputStdHead(ReportEventConfigItem &config, bool diffMode) } } -bool Report::OutputStdCallFrame(int indent, const std::string_view &funcName, uint64_t eventCount, - uint64_t totalEventCount) +bool Report::OutputStdCallFrame(const int indent, const std::string_view &funcName, const uint64_t eventCount, + const uint64_t totalEventCount) { float heat = Percentage(eventCount, totalEventCount); float num = 100.0; @@ -437,7 +437,8 @@ void Report::PrepareConsole() HLOGD("consoleWidth_:%d", consoleWidth_); } -void Report::OutputStdCallFrames(int indent, const ReportItemCallFrame &callFrame, uint64_t totalEventCount) +void Report::OutputStdCallFrames(const int indent, const ReportItemCallFrame &callFrame, + const uint64_t totalEventCount) { /* 90% a @@ -515,7 +516,7 @@ void Report::OutputStdContentItem(const ReportItem &reportItem) } } -void Report::OutputStdItemHeating(float heat, float heat2) +void Report::OutputStdItemHeating(const float heat, const float heat2) { if (heat == heat2 && heat == 0.0f) { fprintf(output_, "something error , all it is end.\n"); diff --git a/src/report_json_file.cpp b/src/report_json_file.cpp index 205361421979b2aef7bbd10d300cefc2bfb02fbb..1eb0d64141414ef2f1466f456f728684f0dc72f5 100644 --- a/src/report_json_file.cpp +++ b/src/report_json_file.cpp @@ -30,7 +30,7 @@ namespace Developtools { namespace HiPerf { bool ReportJsonFile::debug_ = false; -void ReportJsonFile::AddNewFunction(int libId, std::string name) +void ReportJsonFile::AddNewFunction(const int libId, std::string name) { auto it = functionMap_.find(libId); if (it == functionMap_.end()) { @@ -88,7 +88,7 @@ void ReportJsonFile::UpdateCallNodeEventCount() } } -ReportConfigItem &ReportJsonFile::GetConfig(uint64_t id) +ReportConfigItem &ReportJsonFile::GetConfig(const uint64_t id) { for (auto &configpair : reportConfigItems_) { if (find(configpair.first.begin(), configpair.first.end(), id) != configpair.first.end()) { @@ -100,7 +100,7 @@ ReportConfigItem &ReportJsonFile::GetConfig(uint64_t id) return reportConfigItems_.begin()->second; } -int ReportJsonFile::GetFunctionID(int libId, const std::string &function) +int ReportJsonFile::GetFunctionID(const int libId, const std::string &function) { auto functionMapIt = functionMap_.find(libId); if (functionMapIt == functionMap_.end()) { @@ -117,7 +117,8 @@ int ReportJsonFile::GetFunctionID(int libId, const std::string &function) return funcMapIt->second.reportFuncId_; } -void ReportJsonFile::UpdateReportSample(uint64_t id, pid_t pid, pid_t tid, uint64_t eventCount) +void ReportJsonFile::UpdateReportSample(const uint64_t id, const pid_t pid, + const pid_t tid, const uint64_t eventCount) { auto &config = GetConfig(id); @@ -130,7 +131,7 @@ void ReportJsonFile::UpdateReportSample(uint64_t id, pid_t pid, pid_t tid, uint6 sampleCount_++; } -void ReportJsonFile::AddReportCallStack(uint64_t eventCount, ReportCallNodeItem &callNode, +void ReportJsonFile::AddReportCallStack(const uint64_t eventCount, ReportCallNodeItem &callNode, const std::vector &frames) { std::map *child = &callNode.childrenMap; @@ -162,7 +163,7 @@ void ReportJsonFile::AddReportCallStack(uint64_t eventCount, ReportCallNodeItem } } -void ReportJsonFile::AddReportCallStackReverse(uint64_t eventCount, ReportCallNodeItem &callNode, +void ReportJsonFile::AddReportCallStackReverse(const uint64_t eventCount, ReportCallNodeItem &callNode, const std::vector &frames) { std::map *child = &callNode.childrenMap; @@ -194,18 +195,18 @@ void ReportJsonFile::AddReportCallStackReverse(uint64_t eventCount, ReportCallNo } } -uint32_t ReportJsonFile::GetConfigIndex(uint64_t id) +uint32_t ReportJsonFile::GetConfigIndex(const uint64_t id) { return GetConfig(id).index_; } -std::string ReportJsonFile::GetConfigName(uint64_t id) +std::string ReportJsonFile::GetConfigName(const uint64_t id) { auto &config = GetConfig(id); return config.eventName_; } -int ReportJsonFile::GetLibID(std::string_view filepath) +int ReportJsonFile::GetLibID(const std::string_view filepath) { auto it = find(libList_.begin(), libList_.end(), filepath); if (it != libList_.end()) { @@ -216,8 +217,8 @@ int ReportJsonFile::GetLibID(std::string_view filepath) } } -void ReportJsonFile::UpdateReportCallStack(uint64_t id, pid_t pid, pid_t tid, uint64_t eventCount, - std::vector &frames) +void ReportJsonFile::UpdateReportCallStack(const uint64_t id, const pid_t pid, const pid_t tid, + uint64_t const eventCount, const std::vector &frames) { auto &config = GetConfig(id); std::set RepeatFunctionId; diff --git a/src/report_protobuf_file.cpp b/src/report_protobuf_file.cpp index 496dd59dab6d9022ba0a15f27888594f8665f946..6ca1a694d3a8bf5439db590ccdc6308b079798ed 100644 --- a/src/report_protobuf_file.cpp +++ b/src/report_protobuf_file.cpp @@ -54,7 +54,7 @@ void ReportProtobufFileWriter::Close() } } -bool ReportProtobufFileWriter::Write(const void *buffer, int size) +bool ReportProtobufFileWriter::Write(const void *buffer, const int size) { if (protobufFileStream_ == nullptr) { HLOGE("protobufFileStream_ is nullptr"); @@ -74,7 +74,7 @@ bool ReportProtobufFileWriter::Write(const void *buffer, int size) return false; } -bool ReportProtobufFileWriter::Create(std::string fileName) +bool ReportProtobufFileWriter::Create(const std::string fileName) { fileName_ = fileName; try { @@ -254,7 +254,7 @@ bool ReportProtobufFileReader::CheckFileMagic() return true; } -bool ReportProtobufFileReader::Dump(std::string fileName, ProtobufReadBack readBack) +bool ReportProtobufFileReader::Dump(const std::string fileName, ProtobufReadBack readBack) { const int defaultIndent = 0; fileName_ = fileName; @@ -306,7 +306,7 @@ bool ReportProtobufFileReader::Dump(std::string fileName, ProtobufReadBack readB return false; } -bool ReportProtobufFileReader::Dump(const CallStackSample &message, int indent) +bool ReportProtobufFileReader::Dump(const CallStackSample &message, const int indent) { PRINT_INDENT(indent, "%s:\n", message.GetTypeName().c_str()); if (message.has_time()) { @@ -338,7 +338,7 @@ bool ReportProtobufFileReader::Dump(const CallStackSample &message, int indent) return true; } -bool ReportProtobufFileReader::Dump(const SampleStatistic &message, int indent) +bool ReportProtobufFileReader::Dump(const SampleStatistic &message, const int indent) { PRINT_INDENT(indent, "%s:\n", message.GetTypeName().c_str()); if (message.has_count()) { @@ -350,7 +350,7 @@ bool ReportProtobufFileReader::Dump(const SampleStatistic &message, int indent) return false; } -bool ReportProtobufFileReader::Dump(const SymbolTableFile &message, int indent) +bool ReportProtobufFileReader::Dump(const SymbolTableFile &message, const int indent) { PRINT_INDENT(indent, "%s:\n", message.GetTypeName().c_str()); if (message.has_id()) { @@ -364,7 +364,7 @@ bool ReportProtobufFileReader::Dump(const SymbolTableFile &message, int indent) } return false; } -bool ReportProtobufFileReader::Dump(const VirtualThreadInfo &message, int indent) +bool ReportProtobufFileReader::Dump(const VirtualThreadInfo &message, const int indent) { PRINT_INDENT(indent, "%s:\n", message.GetTypeName().c_str()); if (message.has_pid()) { @@ -378,7 +378,7 @@ bool ReportProtobufFileReader::Dump(const VirtualThreadInfo &message, int indent } return false; } -bool ReportProtobufFileReader::Dump(const ReportInfo &message, int indent) +bool ReportProtobufFileReader::Dump(const ReportInfo &message, const int indent) { PRINT_INDENT(indent, "%s:\n", message.GetTypeName().c_str()); for (int i = 0; i < message.config_name_size(); i++) { @@ -389,7 +389,7 @@ bool ReportProtobufFileReader::Dump(const ReportInfo &message, int indent) } return true; } -bool ReportProtobufFileReader::Dump(const HiperfRecord &record, int indent) +bool ReportProtobufFileReader::Dump(const HiperfRecord &record, const int indent) { PRINT_INDENT(indent, "%s:\n", record.GetTypeName().c_str()); if (record.has_sample()) { diff --git a/src/ring_buffer.cpp b/src/ring_buffer.cpp index c30cb001361e448d88791c314a28e572c102066d..12f32f11bb4ab424f4127406927cb79aa1e903cf 100644 --- a/src/ring_buffer.cpp +++ b/src/ring_buffer.cpp @@ -24,7 +24,7 @@ namespace OHOS { namespace Developtools { namespace HiPerf { -RingBuffer::RingBuffer(size_t size) : size_(size) +RingBuffer::RingBuffer(const size_t size) : size_(size) { if (size > 0) { buf_ = std::make_unique(size); @@ -42,7 +42,7 @@ size_t RingBuffer::GetFreeSize() const return size_ - (head_.load(std::memory_order_relaxed) - tail_.load(std::memory_order_relaxed)); } -uint8_t *RingBuffer::AllocForWrite(size_t writeSize) +uint8_t *RingBuffer::AllocForWrite(const size_t writeSize) { if (buf_ == nullptr) { HLOGE("buf_ is nullptr"); diff --git a/src/spe_decoder.cpp b/src/spe_decoder.cpp index a271d2e0427573afb336fc76ca3341cf7a0b497b..ac367e683daf3788bb72af6450379151f0a95ea7 100644 --- a/src/spe_decoder.cpp +++ b/src/spe_decoder.cpp @@ -49,13 +49,13 @@ const std::string SpePktName(enum SpePktType type) return spePacketName; } -static unsigned int SpePayloadLen(unsigned char hdr) +static unsigned int SpePayloadLen(const unsigned char hdr) { return 1U << PERF_SPE_HDR_GET_BYTES_5_4(hdr); } -static int SpeGetPayload(const unsigned char *buf, size_t len, - unsigned char extHdr, struct SpePkt *packet) +static int SpeGetPayload(const unsigned char *buf, const size_t len, + const unsigned char extHdr, struct SpePkt *packet) { CHECK_TRUE(buf != nullptr && packet != nullptr, -1, 1, "Invalid pointer!"); size_t payloadLen = SpePayloadLen(buf[extHdr]); @@ -82,7 +82,7 @@ static int SpeGetPad(struct SpePkt *packet) return 1; } -static int SpeGetAlignment(const unsigned char *buf, size_t len, +static int SpeGetAlignment(const unsigned char *buf, const size_t len, struct SpePkt *packet) { CHECK_TRUE(buf != nullptr && packet != nullptr, -1, 1, "Invalid pointer!"); @@ -102,7 +102,7 @@ static int SpeGetEnd(struct SpePkt *packet) return 1; } -static int SpeGetTimestamp(const unsigned char *buf, size_t len, +static int SpeGetTimestamp(const unsigned char *buf, const size_t len, struct SpePkt *packet) { CHECK_TRUE(buf != nullptr && packet != nullptr, -1, 1, "Invalid pointer!"); @@ -110,7 +110,7 @@ static int SpeGetTimestamp(const unsigned char *buf, size_t len, return SpeGetPayload(buf, len, 0, packet); } -static int SpeGetEvents(const unsigned char *buf, size_t len, +static int SpeGetEvents(const unsigned char *buf, const size_t len, struct SpePkt *packet) { CHECK_TRUE(buf != nullptr && packet != nullptr, -1, 1, "Invalid pointer!"); @@ -119,7 +119,7 @@ static int SpeGetEvents(const unsigned char *buf, size_t len, return SpeGetPayload(buf, len, 0, packet); } -static int SpeGetDataSource(const unsigned char *buf, size_t len, +static int SpeGetDataSource(const unsigned char *buf, const size_t len, struct SpePkt *packet) { CHECK_TRUE(buf != nullptr && packet != nullptr, -1, 1, "Invalid pointer!"); @@ -127,7 +127,7 @@ static int SpeGetDataSource(const unsigned char *buf, size_t len, return SpeGetPayload(buf, len, 0, packet); } -static int SpeGetContext(const unsigned char *buf, size_t len, +static int SpeGetContext(const unsigned char *buf, const size_t len, struct SpePkt *packet) { CHECK_TRUE(buf != nullptr && packet != nullptr, -1, 1, "Invalid pointer!"); @@ -136,7 +136,7 @@ static int SpeGetContext(const unsigned char *buf, size_t len, return SpeGetPayload(buf, len, 0, packet); } -static int SpeGetOpType(const unsigned char *buf, size_t len, +static int SpeGetOpType(const unsigned char *buf, const size_t len, struct SpePkt *packet) { CHECK_TRUE(buf != nullptr && packet != nullptr, -1, 1, "Invalid pointer!"); @@ -145,7 +145,7 @@ static int SpeGetOpType(const unsigned char *buf, size_t len, return SpeGetPayload(buf, len, 0, packet); } -static int SpeGetCounter(const unsigned char *buf, size_t len, +static int SpeGetCounter(const unsigned char *buf, const size_t len, const unsigned char extHdr, struct SpePkt *packet) { CHECK_TRUE(buf != nullptr && packet != nullptr, -1, 1, "Invalid pointer!"); @@ -159,7 +159,7 @@ static int SpeGetCounter(const unsigned char *buf, size_t len, return SpeGetPayload(buf, len, extHdr, packet); } -static int SpeGetAddr(const unsigned char *buf, size_t len, +static int SpeGetAddr(const unsigned char *buf, const size_t len, const unsigned char extHdr, struct SpePkt *packet) { CHECK_TRUE(buf != nullptr && packet != nullptr, -1, 1, "Invalid pointer!"); @@ -173,7 +173,7 @@ static int SpeGetAddr(const unsigned char *buf, size_t len, return SpeGetPayload(buf, len, extHdr, packet); } -static int SpeDoGetPacket(const unsigned char *buf, size_t len, +static int SpeDoGetPacket(const unsigned char *buf, const size_t len, struct SpePkt *packet) { CHECK_TRUE(buf != nullptr && packet != nullptr, -1, 1, "Invalid pointer!"); @@ -235,7 +235,7 @@ static int SpeDoGetPacket(const unsigned char *buf, size_t len, return PERF_SPE_BAD_PACKET; } -int SpeGetPacket(const unsigned char *buf, size_t len, +int SpeGetPacket(const unsigned char *buf, const size_t len, struct SpePkt *packet) { CHECK_TRUE(buf != nullptr && packet != nullptr, -1, 1, "Invalid pointer!"); @@ -574,7 +574,7 @@ int SpePktDesc(const struct SpePkt *packet, char *buf, return err; } -static u64 SpeCalcIp(int index, u64 payload) +static u64 SpeCalcIp(const int index, u64 payload) { u64 ns; u64 el; @@ -802,7 +802,7 @@ int SpeDecode(struct SpeDecoder *decoder) return SpeReadRecord(decoder); } -struct SpeDecoder *SpeDecoderDataNew(const unsigned char *speBuf, size_t speLen) +struct SpeDecoder *SpeDecoderDataNew(const unsigned char *speBuf, const size_t speLen) { CHECK_TRUE(speBuf != nullptr, nullptr, 1, "Invalid pointer!"); struct SpeDecoder *decoder; @@ -823,7 +823,7 @@ struct SpeDecoder *SpeDecoderDataNew(const unsigned char *speBuf, size_t speLen) return decoder; } -bool SpeDumpRawData(unsigned char *buf, size_t len, int indent, FILE *outputDump) +bool SpeDumpRawData(unsigned char *buf, size_t len, const int indent, FILE *outputDump) { CHECK_TRUE(buf != nullptr, false, 1, "Invalid pointer!"); if (outputDump != nullptr) { @@ -931,7 +931,7 @@ void UpdateHeating() } } -void GetSpeEventNameByType(uint32_t type, std::string& eventName) +void GetSpeEventNameByType(const uint32_t type, std::string& eventName) { switch (type) { case PERF_SPE_L1D_ACCESS: @@ -970,7 +970,7 @@ void GetSpeEventNameByType(uint32_t type, std::string& eventName) } } -void DumpSpeReportHead(int indent, uint32_t type, uint64_t count) +void DumpSpeReportHead(const int indent, const uint32_t type, const uint64_t count) { std::string eventName = ""; GetSpeEventNameByType(type, eventName); @@ -995,7 +995,7 @@ void DumpSpeReportHead(int indent, uint32_t type, uint64_t count) return; } -void DumpSpeReportData(int indent, FILE *outputDump) +void DumpSpeReportData(const int indent, FILE *outputDump) { if (outputDump != nullptr) { g_outputDump = outputDump; diff --git a/src/subcommand.cpp b/src/subcommand.cpp index 53da549c03687ed44ca4bffbffe15084befd204f..557121ef6a5ff05b19fb89dc5ac25ea912c2dc22 100644 --- a/src/subcommand.cpp +++ b/src/subcommand.cpp @@ -63,7 +63,7 @@ bool SubCommand::OnSubCommandOptions(std::vector args) return true; } -bool SubCommand::CheckRestartOption(std::string &appPackage, bool targetSystemWide, bool restart, +bool SubCommand::CheckRestartOption(const std::string &appPackage, const bool targetSystemWide, const bool restart, std::vector &selectPids) { if (!restart) { @@ -84,8 +84,9 @@ bool SubCommand::CheckRestartOption(std::string &appPackage, bool targetSystemWi return false; } -bool SubCommand::HandleSubCommandExclude(const std::vector &excludeTids, const std::vector - &excludeThreadNames, std::vector &selectTids) +bool SubCommand::HandleSubCommandExclude(const std::vector &excludeTids, + const std::vector &excludeThreadNames, + std::vector &selectTids) { if (!excludeTids.empty() && !excludeThreadNames.empty()) { printf("option --exclude-thread and --exclude-tid is conflict, please check usage\n"); @@ -194,7 +195,7 @@ const std::map>& SubCommand::GetSubCom return subCommandFuncMap_; } -SubCommand *SubCommand::FindSubCommand(std::string &cmdName) +SubCommand *SubCommand::FindSubCommand(const std::string &cmdName) { HLOGV("%s", cmdName.c_str()); std::lock_guard lock(subCommandMutex_); diff --git a/src/subcommand_dump.cpp b/src/subcommand_dump.cpp index 0dc0ce911a2fb36cd15e248fae232af738e2339b..c2e6cc932dfc619dbfba4023c70f0682185552c3 100644 --- a/src/subcommand_dump.cpp +++ b/src/subcommand_dump.cpp @@ -270,7 +270,7 @@ void SubCommandDump::PrintHeaderInfo(const int &indent) *(reinterpret_cast(&header.features[24]))); } -void SubCommandDump::DumpPrintFileHeader(int indent) +void SubCommandDump::DumpPrintFileHeader(const int indent) { // print header PrintHeaderInfo(indent); @@ -324,7 +324,7 @@ static std::map g_sampleTypeNames = { {PERF_SAMPLE_SERVER_PID, "server_pid"}, }; -void SubCommandDump::DumpSampleType(uint64_t sampleType, int indent) +void SubCommandDump::DumpSampleType(const uint64_t sampleType, const int indent) { std::string names; for (auto &pair : g_sampleTypeNames) { @@ -338,7 +338,7 @@ void SubCommandDump::DumpSampleType(uint64_t sampleType, int indent) PRINT_INDENT(indent + 1, "sample_type names: %s\n", names.c_str()); } -void SubCommandDump::DumpPrintEventAttr(const perf_event_attr &attr, int indent) +void SubCommandDump::DumpPrintEventAttr(const perf_event_attr &attr, const int indent) { PRINT_INDENT(indent, "event_attr: \n"); @@ -379,7 +379,7 @@ void SubCommandDump::DumpPrintEventAttr(const perf_event_attr &attr, int indent) PRINT_INDENT(indent + 1, "sample_stack_user 0x%x\n", attr.sample_stack_user); } -void SubCommandDump::DumpAttrPortion(int indent) +void SubCommandDump::DumpAttrPortion(const int indent) { attrIds_ = reader_->GetAttrSection(); for (size_t i = 0; i < attrIds_.size(); ++i) { @@ -457,7 +457,7 @@ void SubCommandDump::DumpCallChain(int indent, const PerfRecordSample& sample) } } -void SubCommandDump::DumpDataPortion(int indent) +void SubCommandDump::DumpDataPortion(const int indent) { int recordCount = 0; auto recordcCallback = [&](PerfEventRecord& record) { @@ -505,7 +505,7 @@ void SubCommandDump::PrintSymbolFile(const int &indent, const SymbolFileStruct & } } -void SubCommandDump::PrintFeatureEventdesc(int indent, +void SubCommandDump::PrintFeatureEventdesc(const int indent, const PerfFileSectionEventDesc §ionEventdesc) { PRINT_INDENT(indent + INDENT_TWO, "Event descriptions: %zu\n", sectionEventdesc.eventDesces_.size()); @@ -519,7 +519,7 @@ void SubCommandDump::PrintFeatureEventdesc(int indent, PRINT_INDENT(indent + INDENT_TWO, "\n"); } -void SubCommandDump::DumpFeaturePortion(int indent) +void SubCommandDump::DumpFeaturePortion(const int indent) { PRINT_INDENT(indent, "\n ==== features ====\n"); auto features = reader_->GetFeatures(); @@ -579,7 +579,7 @@ void SubCommandDump::DumpFeaturePortion(int indent) } } -void SubCommandDump::DumpUniqueStackTableNode(int indent, const PerfFileSectionUniStackTable &uniStackTable) +void SubCommandDump::DumpUniqueStackTableNode(const int indent, const PerfFileSectionUniStackTable &uniStackTable) { int tableid = 0; PRINT_INDENT(indent + 1, "TableNums: %zu\n\n", uniStackTable.uniStackTableInfos_.size()); diff --git a/src/subcommand_record.cpp b/src/subcommand_record.cpp index b1f53e4f568cd53614e5809d80e06945e5cc1cc4..e0ed4e2a31342ed482b6e83845494f198ab6bbdf 100644 --- a/src/subcommand_record.cpp +++ b/src/subcommand_record.cpp @@ -725,7 +725,7 @@ bool SubCommandRecord::CheckSpeOption() return true; } -void SubCommandRecord::MsgPrintAndTrans(bool isTrans, const std::string& msg) +void SubCommandRecord::MsgPrintAndTrans(const bool isTrans, const std::string& msg) { if (isTrans && controlCmd_ == CONTROL_CMD_PREPARE) { ChildResponseToMain(msg); @@ -743,8 +743,8 @@ bool SubCommandRecord::IsAppRestarted() HIPERF_HILOGI(MODULE_DEFAULT, "[CollectPidsByAppname] collect oldpids begin"); CollectPidsByAppname(oldPids, appPackage_); for (auto it = oldPids.begin(); it != oldPids.end(); it++) { - HIPERF_HILOGI(MODULE_DEFAULT, "[IsAppRestarted] get oldpids %{public}d for %{public}s", - *it, appPackage_.c_str()); + HIPERF_HILOGI(MODULE_DEFAULT, "[IsAppRestarted] get oldpids %{public}d for app", + *it); } HIPERF_HILOGI(MODULE_DEFAULT, "[CollectPidsByAppname] collect oldpids finish"); std::string info = "please restart " + appPackage_ + " for profiling within 30 seconds\n"; @@ -753,8 +753,8 @@ bool SubCommandRecord::IsAppRestarted() HIPERF_HILOGI(MODULE_DEFAULT, "[CollectPidsByAppname] collect newPids begin"); CollectPidsByAppname(newPids, appPackage_); for (auto it = newPids.begin(); it != newPids.end(); it++) { - HIPERF_HILOGI(MODULE_DEFAULT, "[IsAppRestarted] get newPids %{public}d for %{public}s", - *it, appPackage_.c_str()); + HIPERF_HILOGI(MODULE_DEFAULT, "[IsAppRestarted] get newPids %{public}d for app", + *it); } HIPERF_HILOGI(MODULE_DEFAULT, "[CollectPidsByAppname] collect newPids finish"); std::set_intersection(oldPids.begin(), oldPids.end(), @@ -803,8 +803,8 @@ pid_t SubCommandRecord::GetPidFromAppPackage(const pid_t oldPid, const uint64_t if (IsSameCommand(ReadFileToString(fileName), appPackage_)) { res = static_cast(std::stoul(subDir, nullptr)); HLOGD("[GetAppPackagePid]: get appPid for %s is %d", appPackage_.c_str(), res); - HIPERF_HILOGD(MODULE_DEFAULT, "[GetAppPackagePid] get appPid %{public}d for app %{public}s", - res, appPackage_.c_str()); + HIPERF_HILOGD(MODULE_DEFAULT, "[GetAppPackagePid] get appPid %{public}d for app", + res); return res; } } @@ -823,8 +823,8 @@ bool SubCommandRecord::IsAppRunning() return false; } HLOGD("[CheckAppIsRunning] get appPid %d for app %s", appPid, appPackage_.c_str()); - HIPERF_HILOGD(MODULE_DEFAULT, "[CheckAppIsRunning] get appPid %{public}d for app %{public}s", - appPid, appPackage_.c_str()); + HIPERF_HILOGD(MODULE_DEFAULT, "[CheckAppIsRunning] get appPid %{public}d for app", + appPid); selectPids_.push_back(appPid); } return true; @@ -1208,7 +1208,7 @@ void SubCommandRecord::WriteCommEventBeforeSampling() } } -bool SubCommandRecord::ClientCommandResponse(bool response) +bool SubCommandRecord::ClientCommandResponse(const bool response) { return ClientCommandResponse(response ? HiperfClient::ReplyOK : HiperfClient::ReplyFAIL); } @@ -1238,7 +1238,7 @@ bool SubCommandRecord::ClientCommandResponse(const std::string& str) return true; } -bool SubCommandRecord::ChildResponseToMain(bool response) +bool SubCommandRecord::ChildResponseToMain(const bool response) { return ChildResponseToMain(response ? HiperfClient::ReplyOK : HiperfClient::ReplyFAIL); } @@ -1259,7 +1259,7 @@ bool SubCommandRecord::ChildResponseToMain(const std::string& str) return true; } -bool SubCommandRecord::MainRecvFromChild(int fd, std::string& reply) +bool SubCommandRecord::MainRecvFromChild(const int fd, std::string& reply) { struct pollfd pollFd { fd, POLLIN, 0 @@ -1350,7 +1350,7 @@ void SubCommandRecord::OutputRecordFile() fileWriter_ = nullptr; } -bool SubCommandRecord::PostOutputRecordFile(bool output) +bool SubCommandRecord::PostOutputRecordFile(const bool output) { if (output) { OutputRecordFile(); @@ -1677,8 +1677,7 @@ HiperfError SubCommandRecord::OnSubCommand(std::vector& args) CloseClientThread(); } HLOGE("Fail to create record file %s", outputFilename_.c_str()); - HIPERF_HILOGE(MODULE_DEFAULT, "[OnSubCommand] Fail to create record file %{public}s", - outputFilename_.c_str()); + HIPERF_HILOGE(MODULE_DEFAULT, "[OnSubCommand] Fail to create record file"); return HiperfError::CREATE_OUTPUT_FILE_FAIL; } HIPERF_HILOGI(MODULE_DEFAULT, "[OnSubCommand] CreateInitRecordFile finished"); @@ -1726,7 +1725,7 @@ HiperfError SubCommandRecord::OnSubCommand(std::vector& args) if (!backtrack_) { if (!FinishWriteRecordFile()) { HLOGE("Fail to finish record file %s", outputFilename_.c_str()); - HIPERF_HILOGE(MODULE_DEFAULT, "Fail to finish record file %{public}s", outputFilename_.c_str()); + HIPERF_HILOGE(MODULE_DEFAULT, "Fail to finish record file"); return HiperfError::FINISH_WRITE_RECORD_FILE_FAIL; } else if (!PostProcessRecordFile()) { HLOGE("Fail to post process record file"); @@ -2066,7 +2065,7 @@ bool SubCommandRecord::AddFeatureRecordFile() return true; } -bool SubCommandRecord::CreateInitRecordFile(bool compressData) +bool SubCommandRecord::CreateInitRecordFile(const bool compressData) { if (fileWriter_ == nullptr) { fileWriter_ = std::make_unique(); @@ -2398,16 +2397,16 @@ bool SubCommandRecord::OnlineReportData() if (!report_) { return true; } - HIPERF_HILOGI(MODULE_DEFAULT, "%" HILOG_PUBLIC "s begin to report file %" HILOG_PUBLIC "s", - __FUNCTION__, outputFilename_.c_str()); + HIPERF_HILOGI(MODULE_DEFAULT, "%" HILOG_PUBLIC "s begin to report file", + __FUNCTION__); bool ret = false; std::string tempFileName = outputFilename_ + ".tmp"; if (rename(outputFilename_.c_str(), tempFileName.c_str()) != 0) { char errInfo[ERRINFOLEN] = { 0 }; strerror_r(errno, errInfo, ERRINFOLEN); - HIPERF_HILOGI(MODULE_DEFAULT, "%" HILOG_PUBLIC "s can't rename file %" HILOG_PUBLIC "s" + HIPERF_HILOGI(MODULE_DEFAULT, "%" HILOG_PUBLIC "s can't rename file " "errno:%" HILOG_PUBLIC "d , errInfo: %" HILOG_PUBLIC "s\n", - __FUNCTION__, outputFilename_.c_str(), errno, errInfo); + __FUNCTION__, errno, errInfo); return false; } @@ -2426,9 +2425,9 @@ bool SubCommandRecord::OnlineReportData() if (remove(tempFileName.c_str()) != 0) { char errInfo[ERRINFOLEN] = { 0 }; strerror_r(errno, errInfo, ERRINFOLEN); - HIPERF_HILOGI(MODULE_DEFAULT, "%" HILOG_PUBLIC "s remove file failed %" HILOG_PUBLIC "s" + HIPERF_HILOGI(MODULE_DEFAULT, "%" HILOG_PUBLIC "s remove file failed" "errno:%" HILOG_PUBLIC "d , errInfo: %" HILOG_PUBLIC "s\n", - __FUNCTION__, tempFileName.c_str(), errno, errInfo); + __FUNCTION__, errno, errInfo); } HIPERF_HILOGI(MODULE_DEFAULT, "%" HILOG_PUBLIC "s report result %" HILOG_PUBLIC "s", __FUNCTION__, ret ? "success" : "fail"); @@ -2465,7 +2464,7 @@ void SubCommandRecord::SetExcludeHiperf() } } -bool SubCommandRecord::IsThreadExcluded(pid_t pid, pid_t tid) +bool SubCommandRecord::IsThreadExcluded(const pid_t pid, const pid_t tid) { if (excludePids_.find(pid) != excludePids_.end()) { return true; diff --git a/src/subcommand_stat.cpp b/src/subcommand_stat.cpp index 41db0ee48c2b8e0addf369c97da8e1cf1b6aae8d..2ff131614181de0e459598d2ebabd196a16d9ba2 100644 --- a/src/subcommand_stat.cpp +++ b/src/subcommand_stat.cpp @@ -180,7 +180,7 @@ void SubCommandStat::PrintUsage() printf("%s\n", Help().c_str()); } -void SubCommandStat::SetReportFlags(bool cpuFlag, bool threadFlag) +void SubCommandStat::SetReportFlags(const bool cpuFlag, const bool threadFlag) { g_reportCpuFlag = cpuFlag; g_reportThreadFlag = threadFlag; @@ -237,7 +237,7 @@ void SubCommandStat::PrintPerHead(FILE* filePtr) } void SubCommandStat::PrintPerValue(const std::unique_ptr &reportSum, const float &ratio, - std::string &configName, FILE* filePtr) + const std::string &configName, FILE* filePtr) { if (reportSum == nullptr) { return; @@ -415,7 +415,7 @@ bool SubCommandStat::FindPerCoreEventCount(PerfEvents::Summary &summary, __u64 & } std::string SubCommandStat::GetCommentConfigName( - const std::unique_ptr &countEvent, std::string eventName) + const std::unique_ptr &countEvent, const std::string &eventName) { std::string commentConfigName = ""; CHECK_TRUE(countEvent != nullptr && eventName.length() != 0, commentConfigName, 1, "countEvent is nullptr"); @@ -514,8 +514,9 @@ std::string SubCommandStat::GetDetailComments(const std::unique_ptr pids) +bool SubCommandStat::CheckOptionPidAndApp(const std::vector& pids) { if (!CheckOptionPid(pids)) { printf("Problems finding threads of monitor\n\n"); @@ -668,7 +669,7 @@ bool SubCommandStat::CheckOptionPidAndApp(std::vector pids) return true; } -bool SubCommandStat::CheckOptionPid(std::vector pids) +bool SubCommandStat::CheckOptionPid(const std::vector& pids) { if (pids.empty()) { return true; @@ -774,7 +775,7 @@ bool SubCommandStat::CreateFifoServer() return true; } -bool SubCommandStat::ClientCommandResponse(bool response) +bool SubCommandStat::ClientCommandResponse(const bool response) { return ClientCommandResponse(response ? HiperfClient::ReplyOK : HiperfClient::ReplyFAIL); } diff --git a/src/symbols_file.cpp b/src/symbols_file.cpp index 3b68cab0e35f899c5bc2289a36a705dcc388bc53..e0dc295f6ea9ab4e0112a6743c120990f4e29263 100644 --- a/src/symbols_file.cpp +++ b/src/symbols_file.cpp @@ -57,7 +57,7 @@ const std::string SymbolsFile::GetBuildId() const return buildId_; } -bool SymbolsFile::UpdateBuildIdIfMatch(std::string buildId) +bool SymbolsFile::UpdateBuildIdIfMatch(const std::string &buildId) { /* here we have two case @@ -174,7 +174,7 @@ public: { } - DfxSymbol GetSymbolWithPcAndMap(uint64_t pc, std::shared_ptr map) override + DfxSymbol GetSymbolWithPcAndMap(const uint64_t pc, std::shared_ptr map) override { const DfxSymbol symbol; return symbol; @@ -486,8 +486,8 @@ private: return true; } - uint64_t GetVaddrInSymbols(uint64_t ip, uint64_t mapStart, - uint64_t mapPageOffset) const override + uint64_t GetVaddrInSymbols(const uint64_t ip, const uint64_t mapStart, + const uint64_t mapPageOffset) const override { /* 00200000-002c5000 r--p 00000000 08:02 46400311 @@ -1060,7 +1060,7 @@ public: return true; } - DfxSymbol GetSymbolWithPcAndMap(uint64_t ip, std::shared_ptr map) override + DfxSymbol GetSymbolWithPcAndMap(const uint64_t ip, std::shared_ptr map) override { // get cache auto iter = symbolsMap_.find(ip); @@ -1193,7 +1193,7 @@ public: return true; } - DfxSymbol GetSymbolWithPcAndMap(uint64_t ip, std::shared_ptr map) override + DfxSymbol GetSymbolWithPcAndMap(const uint64_t ip, std::shared_ptr map) override { // get cache auto iter = symbolsMap_.find(ip); diff --git a/src/unique_stack_table.cpp b/src/unique_stack_table.cpp index 0af247cb4ec8cc231c8490333ba3c3f26d6f17f5..aeb8b065780fabd05fa1b6d72f0e93b1092a3b19 100644 --- a/src/unique_stack_table.cpp +++ b/src/unique_stack_table.cpp @@ -78,7 +78,7 @@ bool UniqueStackTable::Resize() return true; } -uint64_t UniqueStackTable::PutIpInSlot(uint64_t thisIp, uint64_t prevIdx) +uint64_t UniqueStackTable::PutIpInSlot(const uint64_t thisIp, const uint64_t prevIdx) { Node *tableHead = reinterpret_cast(tableBuf_.get()); uint64_t curIpIdx = (((thisIp >> 2) ^ (prevIdx << 4)) % hashModulus_) + availableIndex_; @@ -116,7 +116,7 @@ uint64_t UniqueStackTable::PutIpInSlot(uint64_t thisIp, uint64_t prevIdx) return 0; } -uint64_t UniqueStackTable::PutIpsInTable(StackId *stackId, u64 *ips, u64 nr) +uint64_t UniqueStackTable::PutIpsInTable(StackId *stackId, const u64 *ips, const u64 nr) { if (tableBuf_ == nullptr) { HLOGE("Hashtable not exist, fatal error!"); @@ -161,7 +161,7 @@ Node* UniqueStackTable::GetFrame(uint64_t stackId) return reinterpret_cast(&tableHead[stackId]); } -bool UniqueStackTable::GetIpsByStackId(StackId stackId, std::vector& ips) +bool UniqueStackTable::GetIpsByStackId(const StackId stackId, std::vector& ips) { CHECK_TRUE(tableBuf_ != nullptr, false, 1, "Hashtable not exist, failed to find frame!"); uint64_t nr = stackId.section.nr; @@ -180,7 +180,7 @@ bool UniqueStackTable::GetIpsByStackId(StackId stackId, std::vector& ips) return true; } -bool UniqueStackTable::ImportNode(uint32_t index, const Node& node) +bool UniqueStackTable::ImportNode(const uint32_t index, const Node& node) { CHECK_TRUE(index < tableSize_, false, 0, ""); Node *tableHead = reinterpret_cast(tableBuf_.get()); diff --git a/src/utilities.cpp b/src/utilities.cpp index 696b78356ec790cbcc0d07f81a70f98e8bb32dd1..b5e8e65faaabbfcb8c65d4655b7438f02fb516ba 100644 --- a/src/utilities.cpp +++ b/src/utilities.cpp @@ -85,7 +85,7 @@ std::string CanonicalizeSpecPath(const char* src) return res; } -uint32_t RoundUp(uint32_t x, const int align) +uint32_t RoundUp(const uint32_t x, const int align) { return (((x) + (align) >= 1 ? (x) + (align) - 1 : 0) / (align)) * (align); } @@ -295,7 +295,7 @@ std::string ReadFileToString(const std::string &fileName) return content; } -bool ReadFileToString(const std::string &fileName, std::string &fileData, size_t fileSize) +bool ReadFileToString(const std::string &fileName, std::string &fileData, const size_t fileSize) { fileData.clear(); std::string resolvedPath = CanonicalizeSpecPath(fileName.c_str()); @@ -340,7 +340,7 @@ bool IsRoot() #endif } -bool PowerOfTwo(uint64_t n) +bool PowerOfTwo(const uint64_t n) { return n && (!(n & (n - 1))); } @@ -376,7 +376,7 @@ bool StringToUint64(const std::string &str, uint64_t &val) errno = 0; uint64_t num = std::strtoull(str.c_str(), &endPtr, 10); // 10 : decimal scale if (endPtr == str.c_str() || *endPtr != '\0' || errno != 0 || num > ULLONG_MAX || str.c_str()[0] == '-') { - HIPERF_HILOGE(MODULE_DEFAULT, "get uint64 failed, str: %{public}s", str.c_str()); + HIPERF_HILOGE(MODULE_DEFAULT, "get uint64 failed"); return false; } val = num; @@ -399,7 +399,7 @@ bool ReadIntFromProcFile(const std::string &path, int &value) return true; } -bool WriteIntToProcFile(const std::string &path, int value) +bool WriteIntToProcFile(const std::string &path, const int value) { std::string s = std::to_string(value); @@ -615,7 +615,7 @@ bool StringEndsWith(const std::string &string, const std::string &with) return string.rfind(with) == (string.length() - with.length()); } -bool HexDump(const void *buf, size_t size, size_t maxSize) +bool HexDump(const void *buf, const size_t size, const size_t maxSize) { CHECK_TRUE(buf != nullptr, false, 0, ""); const unsigned char *byteBuf = static_cast(buf); @@ -639,7 +639,7 @@ std::string BufferToHexString(const std::vector &vec) return BufferToHexString(vec.data(), vec.size()); } -std::string BufferToHexString(const unsigned char buf[], size_t size) +std::string BufferToHexString(const unsigned char buf[], const size_t size) { std::stringstream ss; ss << size << ":"; @@ -700,7 +700,7 @@ pid_t GetAppPackagePid(const std::string &appPackage, const pid_t oldPid, const return res; } -bool CheckAppIsRunning (std::vector &selectPids, const std::string &appPackage, int checkAppMs) +bool CheckAppIsRunning(std::vector &selectPids, const std::string &appPackage, const int checkAppMs) { if (!appPackage.empty()) { pid_t appPid = GetAppPackagePid(appPackage, -1, checkAppMs, waitAppRunCheckTimeOut); @@ -857,7 +857,7 @@ bool IsAllowProfilingUid() #endif } -std::string GetProcessName(int pid) +std::string GetProcessName(const int pid) { #if defined(is_ohos) && is_ohos std::string filePath = "/proc/" + std::to_string(pid) + "/cmdline"; @@ -868,14 +868,18 @@ std::string GetProcessName(int pid) #endif } -bool NeedAdaptSandboxPath(char *filename, int pid, u16 &headerSize) +bool NeedAdaptSandboxPath(char *filename, const int pid, u16 &headerSize) { std::string oldFilename = filename; if (oldFilename.find("/data/storage") == 0 && access(oldFilename.c_str(), F_OK) != 0) { std::string newFilename = "/proc/" + std::to_string(pid) + "/root" + oldFilename; - (void)memset_s(filename, KILO, '\0', KILO); + if (memset_s(filename, KILO, '\0', KILO) != EOK) { + HLOGD("memset_s filename failed!"); + return false; + } if (strncpy_s(filename, KILO, newFilename.c_str(), newFilename.size()) != 0) { HLOGD("strncpy_s recordMmap2 failed!"); + return false; } headerSize += newFilename.size() - oldFilename.size(); return true; @@ -1021,7 +1025,7 @@ bool IsDirectoryExists(const std::string& fileName) return false; } -bool CreateDirectory(const std::string& path, mode_t mode) +bool CreateDirectory(const std::string& path, const mode_t mode) { #if defined(is_ohos) && is_ohos std::string::size_type pos = 0; diff --git a/src/virtual_runtime.cpp b/src/virtual_runtime.cpp index c8ddb29b2c352eaee2b8930811155cf8b61dfed5..e5e1718cf1cd3a16f2bc61133d84790bf34a07b3 100644 --- a/src/virtual_runtime.cpp +++ b/src/virtual_runtime.cpp @@ -40,7 +40,7 @@ namespace { const uint64_t BAD_IP_ADDRESS = 2; } // we unable to access 'swapper' from /proc/0/ -VirtualRuntime::VirtualRuntime(bool onDevice) +VirtualRuntime::VirtualRuntime(const bool onDevice) { UpdateThread(0, 0, "swapper"); } @@ -52,7 +52,7 @@ VirtualRuntime::~VirtualRuntime() } } -std::string VirtualRuntime::ReadFromSavedCmdLines(pid_t tid) +std::string VirtualRuntime::ReadFromSavedCmdLines(const pid_t tid) { if (!savedCmdLines_.is_open()) { savedCmdLines_.open(SAVED_CMDLINES, std::ios::in); @@ -79,7 +79,7 @@ std::string VirtualRuntime::ReadFromSavedCmdLines(pid_t tid) return EMPTY_STRING; } -std::string VirtualRuntime::ReadThreadName(pid_t tid, bool isThread) +std::string VirtualRuntime::ReadThreadName(const pid_t tid, const bool isThread) { std::string comm = ""; if (tid == SYSMGR_PID) { @@ -99,7 +99,7 @@ std::string VirtualRuntime::ReadThreadName(pid_t tid, bool isThread) return comm; } -VirtualThread &VirtualRuntime::UpdateThread(pid_t pid, pid_t tid, const std::string name) +VirtualThread &VirtualRuntime::UpdateThread(const pid_t pid, const pid_t tid, const std::string name) { #ifdef HIPERF_DEBUG_TIME const auto startTime = steady_clock::now(); @@ -114,7 +114,7 @@ VirtualThread &VirtualRuntime::UpdateThread(pid_t pid, pid_t tid, const std::str return thread; } -VirtualThread &VirtualRuntime::CreateThread(pid_t pid, pid_t tid, const std::string name) +VirtualThread &VirtualRuntime::CreateThread(const pid_t pid, const pid_t tid, const std::string name) { // make a new one if (pid == tid) { @@ -207,7 +207,7 @@ bool VirtualRuntime::UpdateHapSymbols(std::shared_ptr map) return true; } -VirtualThread &VirtualRuntime::GetThread(pid_t pid, pid_t tid, const std::string name) +VirtualThread &VirtualRuntime::GetThread(const pid_t pid, const pid_t tid, const std::string name) { if (userSpaceThreadMap_.find(pid) == userSpaceThreadMap_.end()) { // no pid found @@ -224,8 +224,9 @@ VirtualThread &VirtualRuntime::GetThread(pid_t pid, pid_t tid, const std::string } } -std::shared_ptr VirtualRuntime::UpdateThreadMaps(pid_t pid, pid_t tid, const std::string filename, - uint64_t begin, uint64_t len, uint64_t offset, uint32_t prot) +std::shared_ptr VirtualRuntime::UpdateThreadMaps(const pid_t pid, const pid_t tid, const std::string filename, + const uint64_t begin, const uint64_t len, + const uint64_t offset, const uint32_t prot) { VirtualThread &thread = GetThread(pid, tid); std::shared_ptr map = thread.CreateMapItem(filename, begin, len, offset, prot); @@ -346,8 +347,8 @@ void VirtualRuntime::UpdateKernelSymbols() } } -void VirtualRuntime::UpdatekernelMap(uint64_t begin, uint64_t end, uint64_t offset, - std::string filename) +void VirtualRuntime::UpdatekernelMap(const uint64_t begin, const uint64_t end, const uint64_t offset, + const std::string &filename) { HLOGV("update kernel map name:'%s' 0x%" PRIx64 " - 0x%" PRIx64 "@0x%08" PRIx64 "", filename.c_str(), begin, end, offset); @@ -492,8 +493,8 @@ void VirtualRuntime::MakeCallFrame(DfxSymbol &symbol, DfxFrame &callFrame) HLOG_ASSERT_MESSAGE(!callFrame.funcName.empty(), "%s", symbol.ToDebugString().c_str()); } -void VirtualRuntime::SymbolicCallFrame(PerfRecordSample &recordSample, uint64_t ip, - pid_t serverPid, perf_callchain_context context) +void VirtualRuntime::SymbolicCallFrame(PerfRecordSample &recordSample, const uint64_t ip, + const pid_t serverPid, const perf_callchain_context context) { pid_t pid = static_cast(recordSample.data_.pid); pid_t tid = static_cast(recordSample.data_.tid); @@ -678,7 +679,7 @@ void VirtualRuntime::UnwindFromRecord(PerfRecordSample &recordSample) } } -void VirtualRuntime::SetCollectSymbolCallBack(CollectSymbolCallBack collectSymbolCallBack) +void VirtualRuntime::SetCollectSymbolCallBack(const CollectSymbolCallBack &collectSymbolCallBack) { collectSymbolCallBack_ = collectSymbolCallBack; } @@ -905,12 +906,12 @@ void VirtualRuntime::SymbolSpeRecord(PerfRecordAuxtrace &recordAuxTrace) #endif } -void VirtualRuntime::SetRecordMode(RecordCallBack recordCallBack) +void VirtualRuntime::SetRecordMode(const RecordCallBack &recordCallBack) { recordCallBack_ = recordCallBack; } -void VirtualRuntime::UpdateSymbols(std::shared_ptr map, pid_t pid) +void VirtualRuntime::UpdateSymbols(std::shared_ptr map, const pid_t pid) { CHECK_TRUE(map != nullptr && map->symbolFileIndex == -1, NO_RETVAL, 0, ""); HLOGD("try to find symbols for file: %s", map->name.c_str()); @@ -964,7 +965,7 @@ void VirtualRuntime::UpdateSymbols(std::shared_ptr map, pid_t pid) #endif } -const DfxSymbol VirtualRuntime::GetKernelSymbol(uint64_t ip, const std::vector &memMaps, +const DfxSymbol VirtualRuntime::GetKernelSymbol(const uint64_t ip, const std::vector &memMaps, const VirtualThread &thread) { DfxSymbol vaddrSymbol(ip, thread.name_); @@ -1010,7 +1011,7 @@ const DfxSymbol VirtualRuntime::GetKernelSymbol(uint64_t ip, const std::vector> 12; uint64_t memMapIndex = -1; @@ -306,7 +306,7 @@ void VirtualThread::ParseServiceMap(const std::string &filename) CreateMapItem(filename, begin, end - begin, 0); } -void VirtualThread::ParseDevhostMap(pid_t devhost) +void VirtualThread::ParseDevhostMap(const pid_t devhost) { std::string mapPath = StringPrintf("/proc/%d/maps", devhost); std::string mapContent = ReadFileToString(mapPath); @@ -387,8 +387,9 @@ void VirtualThread::SortMemMaps() } } -std::shared_ptr VirtualThread::CreateMapItem(const std::string filename, uint64_t begin, uint64_t len, - uint64_t offset, uint32_t prot) +std::shared_ptr VirtualThread::CreateMapItem(const std::string &filename, uint64_t const begin, + const uint64_t len, const uint64_t offset, + const uint32_t prot) { if (!OHOS::HiviewDFX::DfxMaps::IsLegalMapItem(filename)) { return nullptr; // skip some memmap diff --git a/test/unittest/common/native/virtual_runtime_test.cpp b/test/unittest/common/native/virtual_runtime_test.cpp index 5c907c210b6c2d243a1c6a8ae3f3634a6d2f2388..691e1b8671307e48b6678aef353e295c9ed6dd5f 100644 --- a/test/unittest/common/native/virtual_runtime_test.cpp +++ b/test/unittest/common/native/virtual_runtime_test.cpp @@ -360,7 +360,9 @@ HWTEST_F(VirtualRuntimeTest, UnwindFromRecord, TestSize.Level0) LoadFromFile(PATH_RESOURCE_TEST_DWARF_DATA + TEST_DWARF_RECORD, data); ASSERT_NE(data.size(), 0u); perf_event_attr attr; - (void)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)) != 0) { + printf("memset_s perf_event_attr failed"); + } attr.sample_type = TEST_RECORD_SAMPLE_TYPE; attr.sample_regs_user = TEST_DWARF_RECORD_REGS_USER; PerfRecordSample sample;