From 0bb2a1f58be52e747f37b3f5e0698aa4178d2e39 Mon Sep 17 00:00:00 2001 From: yuyanqinghw Date: Wed, 25 Jun 2025 14:39:33 +0800 Subject: [PATCH] Code optimization Signed-off-by: yuyanqinghw --- src/perf_events.cpp | 5 ++--- src/symbols_file.cpp | 9 ++++----- src/utilities.cpp | 8 +++++++- src/virtual_runtime.cpp | 2 +- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/perf_events.cpp b/src/perf_events.cpp index 2aa8fae..e331064 100644 --- a/src/perf_events.cpp +++ b/src/perf_events.cpp @@ -1173,8 +1173,6 @@ bool PerfEvents::CreateFdEvents(void) printf("pid %d does not exist.\n", pids_[ipid]); } HLOGE("pid %d does not exist.\n", pids_[ipid]); - HIPERF_HILOGE(MODULE_DEFAULT, "[CreateFdEvents] pid %{public}d does not exist.", - pids_[ipid]); continue; } else { // clang-format off @@ -1221,7 +1219,8 @@ bool PerfEvents::CreateFdEvents(void) eventNumber++; } } - + HIPERF_HILOGE(MODULE_DEFAULT, "[CreateFdEvents] open %{public}d fd for %{public}d events.", + fdNumber, eventNumber); CHECK_TRUE(fdNumber != 0, false, 1, "open %d fd for %d events", fdNumber, eventNumber); HLOGD("will try read %u events from %u fd (%zu groups):", eventNumber, fdNumber, diff --git a/src/symbols_file.cpp b/src/symbols_file.cpp index 3b12c31..9637077 100644 --- a/src/symbols_file.cpp +++ b/src/symbols_file.cpp @@ -946,11 +946,10 @@ public: } hapExtracted_ = true; HLOGD("the symbol file is %s, pid is %d.", filePath_.c_str(), pid_); - if (IsRoot()) { - if (IsApplicationEncryped(pid_)) { - HLOGD("no need to parse js symbols"); - return false; - } + + if (IsApplicationEncryped(pid_)) { + HLOGD("no need to parse js symbols"); + return false; } CHECK_TRUE(!StringEndsWith(filePath_, ".hap") || !map_->IsMapExec(), false, 1, diff --git a/src/utilities.cpp b/src/utilities.cpp index bf6c971..506f687 100644 --- a/src/utilities.cpp +++ b/src/utilities.cpp @@ -328,7 +328,7 @@ bool WriteStringToFile(const std::string &fileName, const std::string &value) return output.good(); } -bool IsRoot() +bool GetIsRoot() { #if defined(is_ohos) && is_ohos std::string debugMode = "0"; @@ -339,6 +339,12 @@ bool IsRoot() #endif } +bool IsRoot() +{ + const static bool isRoot = GetIsRoot(); + return isRoot; +} + bool PowerOfTwo(uint64_t n) { return n && (!(n & (n - 1))); diff --git a/src/virtual_runtime.cpp b/src/virtual_runtime.cpp index 0b04556..2383f9f 100644 --- a/src/virtual_runtime.cpp +++ b/src/virtual_runtime.cpp @@ -229,7 +229,7 @@ std::shared_ptr VirtualRuntime::UpdateThreadMaps(pid_t pid, pid_t tid, c { VirtualThread &thread = GetThread(pid, tid); std::shared_ptr map = thread.CreateMapItem(filename, begin, len, offset, prot); - if (isHM_) { + if (isHM_ && recordCallBack_ != nullptr) { thread.FixHMBundleMap(); } return map; -- Gitee