From 74b2194c535bfc359efa9af39b752cc0e7ba0257 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=BF=8A=E9=BE=99?= Date: Thu, 31 Jul 2025 21:19:07 +0800 Subject: [PATCH 01/27] =?UTF-8?q?fix=20native=20daemon=20memory=20leak=20i?= =?UTF-8?q?ssues=20Signed-off-by:=20=E7=8E=8B=E4=BF=8A=E9=BE=99=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- device/plugins/native_daemon/src/main.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/device/plugins/native_daemon/src/main.cpp b/device/plugins/native_daemon/src/main.cpp index a1095c3c1..f1ab8cb2a 100644 --- a/device/plugins/native_daemon/src/main.cpp +++ b/device/plugins/native_daemon/src/main.cpp @@ -274,6 +274,10 @@ int main(int argc, char* argv[]) } } else { if (!COMMON::GetDeveloperMode()) { + if (lockFileFd > 0) { + flock(lockFileFd, LOCK_UN); + close(lockFileFd); + } return 0; } if (!COMMON::IsBetaVersion()) { @@ -323,6 +327,10 @@ int main(int argc, char* argv[]) } } else { if (!COMMON::GetDeveloperMode()) { + if (lockFileFd > 0) { + flock(lockFileFd, LOCK_UN); + close(lockFileFd); + } return 0; } auto hookManager = std::make_shared(); -- Gitee From 6f7f73917a8275c5362202960a865d18dbe392a1 Mon Sep 17 00:00:00 2001 From: shead-master Date: Fri, 1 Aug 2025 14:59:19 +0800 Subject: [PATCH 02/27] =?UTF-8?q?=E8=93=9D=E9=BB=84=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: shead-master --- bundle.json | 1 + hidebug/interfaces/cj/BUILD.gn | 1 + hidebug/interfaces/cj/hidebug_ffi.cpp | 17 +++++++++++++++++ hidebug/interfaces/js/kits/napi/BUILD.gn | 1 + .../interfaces/js/kits/napi/napi_hidebug.cpp | 17 +++++++++++++++++ 5 files changed, 37 insertions(+) diff --git a/bundle.json b/bundle.json index 0589cd460..2e7e60a65 100644 --- a/bundle.json +++ b/bundle.json @@ -62,6 +62,7 @@ "openssl", "zlib", "grpc", + "storage_service", "abseil-cpp", "netmanager_base" ], diff --git a/hidebug/interfaces/cj/BUILD.gn b/hidebug/interfaces/cj/BUILD.gn index 9ae5ebd53..76e0de947 100644 --- a/hidebug/interfaces/cj/BUILD.gn +++ b/hidebug/interfaces/cj/BUILD.gn @@ -40,6 +40,7 @@ ohos_shared_library("cj_hidebug_ffi") { "napi:cj_bind_ffi", "napi:cj_bind_native", "samgr:samgr_proxy", + "storage_service:storage_manager_acl", ] innerapi_tags = [ "platformsdk" ] diff --git a/hidebug/interfaces/cj/hidebug_ffi.cpp b/hidebug/interfaces/cj/hidebug_ffi.cpp index 38eb663a4..b017a3984 100644 --- a/hidebug/interfaces/cj/hidebug_ffi.cpp +++ b/hidebug/interfaces/cj/hidebug_ffi.cpp @@ -31,6 +31,7 @@ #include "dump_usage.h" #include "file_ex.h" #include "directory_ex.h" +#include "storage_acl.h" #include "hidebug_native_interface.h" #include "memory_collector.h" #include "hilog/log.h" @@ -65,6 +66,21 @@ static bool CheckVersionType(const std::string& type, const std::string& key) return (versionType.find(type) != std::string::npos); } +static bool CreateSanBoxDir() +{ + constexpr mode_t defaultLogDirMode = 0x0770; + const std::string reourceLimitDir = "/data/storage/el2/log/resourcelimit/"; + if (!OHOS::FileExists(reourceLimitDir)) { + OHOS::ForceCreateDirectory(reourceLimitDir); + OHOS::ChangeModeDirectory(reourceLimitDir, defaultLogDirMode); + } + if (OHOS::StorageDaemon::AclSetAccess(reourceLimitDir, "g:1201:rwx") != 0) { + HILOG_ERROR(LOG_CORE, "CreateSanBoxDir Failed to AclSetAccess"); + return false; + } + return true; +} + extern "C" { uint64_t FfiHidebugGetPss() { @@ -289,6 +305,7 @@ extern "C" { if (result == MemoryState::MEMORY_FAILED) { return 0; } + CreateSanBoxDir(); return 0; } diff --git a/hidebug/interfaces/js/kits/napi/BUILD.gn b/hidebug/interfaces/js/kits/napi/BUILD.gn index 7335ff762..0830e7044 100644 --- a/hidebug/interfaces/js/kits/napi/BUILD.gn +++ b/hidebug/interfaces/js/kits/napi/BUILD.gn @@ -52,6 +52,7 @@ ohos_shared_library("hidebug") { "ipc:ipc_core", "napi:ace_napi", "samgr:samgr_proxy", + "storage_service:storage_manager_acl", ] relative_install_dir = "module" diff --git a/hidebug/interfaces/js/kits/napi/napi_hidebug.cpp b/hidebug/interfaces/js/kits/napi/napi_hidebug.cpp index 221979be8..367eb9d77 100644 --- a/hidebug/interfaces/js/kits/napi/napi_hidebug.cpp +++ b/hidebug/interfaces/js/kits/napi/napi_hidebug.cpp @@ -45,6 +45,7 @@ #include "napi/native_node_api.h" #include "native_engine/native_engine.h" #include "refbase.h" +#include "storage_acl.h" #include "system_ability_definition.h" #include "napi_hidebug_gc.h" #include "napi_util.h" @@ -878,6 +879,21 @@ static bool GetAppResourceLimitParam(napi_env env, napi_callback_info info, std: return true; } +static bool CreateSanBoxDir() +{ + constexpr mode_t defaultLogDirMode = 0770; + const std::string reourceLimitDir = "/data/storage/el2/log/resourcelimit/"; + if (!OHOS::FileExists(reourceLimitDir)) { + OHOS::ForceCreateDirectory(reourceLimitDir); + OHOS::ChangeModeDirectory(reourceLimitDir, defaultLogDirMode); + } + if (OHOS::StorageDaemon::AclSetAccess(reourceLimitDir, "g:1201:rwx") != 0) { + HILOG_ERROR(LOG_CORE, "CreateSanBoxDir Failed to AclSetAccess"); + return false; + } + return true; +} + static bool CheckVersionType(const std::string& type, const std::string& key) { auto versionType = OHOS::system::GetParameter(key, "unknown"); @@ -887,6 +903,7 @@ static bool CheckVersionType(const std::string& type, const std::string& key) napi_value SetAppResourceLimit(napi_env env, napi_callback_info info) { ApiInvokeRecorder apiInvokeRecorder("setAppResourceLimit"); + CreateSanBoxDir(); if (!IsBetaVersion() && !CheckVersionType("enable", KEY_HIVIEW_DEVELOP_TYPE)) { HILOG_ERROR(LOG_CORE, "SetAppResourceLimit failed. Not developer options or beta versions"); apiInvokeRecorder.SetErrorCode(ErrorCode::VERSION_ERROR); -- Gitee From 7bc2ea8dc03396fc3e1b28e6b760a762079f3e3a Mon Sep 17 00:00:00 2001 From: zyxzyx Date: Mon, 28 Jul 2025 15:01:46 +0800 Subject: [PATCH 03/27] online mode single share mem Signed-off-by: zyxzyx --- .../native_daemon/include/hook_common.h | 6 ++-- .../native_daemon/include/hook_manager.h | 2 +- .../src/native_memory_profiler_sa_service.cpp | 5 +-- .../native_daemon/src/hook_manager.cpp | 21 +++++++------ .../native_daemon/src/hook_record_factory.cpp | 5 +-- .../native_daemon/src/hook_service.cpp | 6 ++-- .../native_daemon/src/stack_preprocess.cpp | 3 +- .../plugins/native_hook/src/hook_client.cpp | 31 ++++++++++--------- .../native_hook/src/hook_socket_client.cpp | 12 ++++--- .../test/unittest/hook_socket_client_test.cpp | 4 +-- 10 files changed, 54 insertions(+), 41 deletions(-) diff --git a/device/plugins/native_daemon/include/hook_common.h b/device/plugins/native_daemon/include/hook_common.h index 935e98e32..85aebb9b6 100644 --- a/device/plugins/native_daemon/include/hook_common.h +++ b/device/plugins/native_daemon/include/hook_common.h @@ -42,7 +42,7 @@ const size_t MAX_CALL_FRAME_UNWIND_SIZE = MAX_UNWIND_DEPTH + FILTER_STACK_DEPTH; const int32_t DLOPEN_MIN_UNWIND_DEPTH = 5; // default max js stack depth const int32_t DEFAULT_MAX_JS_STACK_DEPTH = 10; -constexpr int SHARED_MEMORY_NUM = 1; +constexpr int SHARED_MEMORY_NUM = 3; constexpr uint64_t DWARF_ERROR_ID = 999999; constexpr uint64_t SIZE_MASK = 0xFFFFFF0000000000; } @@ -170,6 +170,7 @@ struct alignas(8) ClientConfig { // 8 is 8 bit printNmd = false; nmdType = -1; isSaMode = false; + offlineSymbolization = false; arktsConfig.jsStackReport = 0; arktsConfig.maxJsStackDepth = 0; arktsConfig.jsFpunwind = false; @@ -194,7 +195,7 @@ struct alignas(8) ClientConfig { // 8 is 8 bit << std::to_string(arktsConfig.maxJsStackDepth) << ", filterNapiName: " << arktsConfig.filterNapiName << ", jsFpunwind: " << arktsConfig.jsFpunwind << ", largestSize: " << largestSize << ", secondLargestSize: " << secondLargestSize - << ", maxGrowthSize: " << maxGrowthSize; + << ", maxGrowthSize: " << maxGrowthSize << ", offline:" << offlineSymbolization; return ss.str(); } @@ -216,6 +217,7 @@ struct alignas(8) ClientConfig { // 8 is 8 bit bool printNmd = false; int nmdType = -1; bool isSaMode = false; + bool offlineSymbolization = false; ArkTsClientConfig arktsConfig = {0}; uint32_t largestSize = 0; uint32_t secondLargestSize = 0; diff --git a/device/plugins/native_daemon/include/hook_manager.h b/device/plugins/native_daemon/include/hook_manager.h index 9f744c1de..e41101af3 100644 --- a/device/plugins/native_daemon/include/hook_manager.h +++ b/device/plugins/native_daemon/include/hook_manager.h @@ -104,7 +104,7 @@ public: void RegisterWriter(const std::shared_ptr writer); void WriteHookConfig(); std::string GetCmdArgs(NativeHookConfig traceConfig); - std::vector GetFds(int32_t pid, const std::string& name); + std::vector GetFds(int32_t pid, const std::string& name, int sharedMemCount); inline void SetSaServiceConfig(bool saFlag, bool isProtobufSerialize) { isSaService_ = saFlag; diff --git a/device/plugins/native_daemon/native_memory_profiler_sa/src/native_memory_profiler_sa_service.cpp b/device/plugins/native_daemon/native_memory_profiler_sa/src/native_memory_profiler_sa_service.cpp index 3bfd70e79..6572b837b 100644 --- a/device/plugins/native_daemon/native_memory_profiler_sa/src/native_memory_profiler_sa_service.cpp +++ b/device/plugins/native_daemon/native_memory_profiler_sa/src/native_memory_profiler_sa_service.cpp @@ -544,8 +544,9 @@ bool NativeMemoryProfilerSaService::ProtocolProc(SocketContext &context, uint32_ } clientConfig.isSaMode = true; context.SendHookConfig(reinterpret_cast(&clientConfig), sizeof(clientConfig)); - std::vector fdVec = iter->second->hookMgr->GetFds(peerConfig, bundleName); - for (int i = 0; i < SHARED_MEMORY_NUM; ++i) { + int sharedMemCount = (clientConfig.offlineSymbolization) ? SHARED_MEMORY_NUM : 1; + std::vector fdVec = iter->second->hookMgr->GetFds(peerConfig, bundleName, sharedMemCount); + for (int i = 0; i < sharedMemCount; ++i) { int eventFd = fdVec[i * VEC_SHIFT]; int smbFd = fdVec[i * VEC_SHIFT + 1]; if (eventFd == smbFd) { diff --git a/device/plugins/native_daemon/src/hook_manager.cpp b/device/plugins/native_daemon/src/hook_manager.cpp index 24f4419da..fe6ff6267 100644 --- a/device/plugins/native_daemon/src/hook_manager.cpp +++ b/device/plugins/native_daemon/src/hook_manager.cpp @@ -218,7 +218,8 @@ bool HookManager::UnloadPlugin(const uint32_t pluginId) void HookManager::GetClientConfig(ClientConfig& clientConfig) { - clientConfig.shareMemorySize = (static_cast(hookConfig_.smb_pages()) / SHARED_MEMORY_NUM) * PAGE_BYTES; + int sharedMemCount = (hookConfig_.offline_symbolization()) ? SHARED_MEMORY_NUM : 1; + clientConfig.shareMemorySize = (static_cast(hookConfig_.smb_pages()) / sharedMemCount) * PAGE_BYTES; clientConfig.filterSize = static_cast(hookConfig_.filter_size()); clientConfig.clockId = COMMON::GetClockId(hookConfig_.clock()); clientConfig.maxStackDepth = hookConfig_.max_stack_depth(); @@ -233,6 +234,7 @@ void HookManager::GetClientConfig(ClientConfig& clientConfig) clientConfig.memtraceEnable = hookConfig_.memtrace_enable(); clientConfig.statisticsInterval = hookConfig_.statistics_interval(); clientConfig.sampleInterval = hookConfig_.sample_interval(); + clientConfig.offlineSymbolization = hookConfig_.offline_symbolization(); clientConfig.responseLibraryMode = hookConfig_.response_library_mode(); clientConfig.arktsConfig.jsStackReport = hookConfig_.js_stack_report(); clientConfig.targetSoName = hookConfig_.target_so_name(); @@ -256,9 +258,10 @@ bool HookManager::HandleHookContext(const std::shared_ptr& ctx) } // create smb and eventNotifier - uint32_t bufferSize = (static_cast(hookConfig_.smb_pages()) / SHARED_MEMORY_NUM) * PAGE_BYTES; + int sharedMemCount = (hookConfig_.offline_symbolization()) ? SHARED_MEMORY_NUM : 1; + uint32_t bufferSize = (static_cast(hookConfig_.smb_pages()) / sharedMemCount) * PAGE_BYTES; - for (int i = 0; i < SHARED_MEMORY_NUM; ++i) { + for (int i = 0; i < sharedMemCount; ++i) { std::string smbName = ""; if (ctx->pid > 0) { smbName = "hooknativesmb_" + std::to_string(ctx->pid) + ":" + std::to_string(i); @@ -302,7 +305,7 @@ bool HookManager::HandleHookContext(const std::shared_ptr& ctx) fpHookData_, isHookStandalone_, isSaService_, isProtobufSerialize_); ctx->stackPreprocess->SetFlushSize(shareMemorySize_); ctx->stackPreprocess->SetNmdFd(nmdParamInfo_.fd); - for (int i = 0; i < SHARED_MEMORY_NUM; ++i) { + for (int i = 0; i < sharedMemCount; ++i) { ctx->eventPollerList[i]->AddFileDescriptor( ctx->eventNotifierList[i]->GetFd(), std::bind(&StackPreprocess::TakeResultsFromShmem, ctx->stackPreprocess, @@ -314,7 +317,7 @@ bool HookManager::HandleHookContext(const std::shared_ptr& ctx) ctx->stackPreprocess = std::make_shared(ctx->stackData, hookConfig_, pluginDataClockId, fpHookData_, isHookStandalone_, isSaService_, isProtobufSerialize_); ctx->stackPreprocess->SetFlushSize(shareMemorySize_); - for (int i = 0; i < SHARED_MEMORY_NUM; ++i) { + for (int i = 0; i < sharedMemCount; ++i) { ctx->eventPollerList[i]->AddFileDescriptor( ctx->eventNotifierList[i]->GetFd(), [this, &ctx, i] { this->ReadShareMemory(ctx, i); }); @@ -561,7 +564,7 @@ bool HookManager::DestroyPluginSession(const std::vector& pluginIds) } } for (const auto& item : hookCtx_) { - for (int i = 0; i < SHARED_MEMORY_NUM; ++i) { + for (int i = 0; i < item->eventPollerList.size(); ++i) { if (item->eventPollerList[i] && item->eventNotifierList[i]) { PROFILER_LOG_ERROR(LOG_CORE, "eventPoller unset! num: %d", i); item->eventPollerList[i]->RemoveFileDescriptor(item->eventNotifierList[i]->GetFd()); @@ -837,7 +840,7 @@ void HookManager::WriteHookConfig() } } -std::vector HookManager::GetFds(int32_t pid, const std::string& name) +std::vector HookManager::GetFds(int32_t pid, const std::string& name, int sharedMemCount) { for (const auto& item : hookCtx_) { if (item->pid == pid || item->processName == name) { @@ -846,14 +849,14 @@ std::vector HookManager::GetFds(int32_t pid, const std::string& name) } item->stackPreprocess->SetPid(pid); std::vector fds; - for (int i = 0; i < SHARED_MEMORY_NUM; ++i) { + for (int i = 0; i < sharedMemCount; ++i) { fds.push_back(item->eventNotifierList[i]->GetFd()); fds.push_back(item->shareMemoryBlockList[i]->GetfileDescriptor()); } return fds; } } - return std::vector(-1, SHARED_MEMORY_NUM * DOUBLE); + return std::vector(-1, sharedMemCount * DOUBLE); } void HookManager::SetNmdInfo(std::pair info) diff --git a/device/plugins/native_daemon/src/hook_record_factory.cpp b/device/plugins/native_daemon/src/hook_record_factory.cpp index d46936f7b..dee303b54 100644 --- a/device/plugins/native_daemon/src/hook_record_factory.cpp +++ b/device/plugins/native_daemon/src/hook_record_factory.cpp @@ -25,8 +25,9 @@ HookRecordFactory::HookRecordFactory(NativeHookConfig hookConfig) : hookConfig_( { const bool isNoDataQueueMode = (hookConfig_.statistics_interval() > 0 && hookConfig_.fp_unwind() && hookConfig_.offline_symbolization()); - int rawDataCacheSize = isNoDataQueueMode ? SHARED_MEMORY_NUM : RAW_DATA_CACHE_INIT_SIZE; - int hookRecordCacheSize = isNoDataQueueMode ? SHARED_MEMORY_NUM : HOOK_RECORD_CACHE_INIT_SIZE; + int sharedMemCount = (hookConfig_.offline_symbolization()) ? SHARED_MEMORY_NUM : 1; + int rawDataCacheSize = isNoDataQueueMode ? sharedMemCount : RAW_DATA_CACHE_INIT_SIZE; + int hookRecordCacheSize = isNoDataQueueMode ? sharedMemCount : HOOK_RECORD_CACHE_INIT_SIZE; for (int index = 0; index < rawDataCacheSize; ++index) { rawStackCache_.emplace_back(std::make_shared()); diff --git a/device/plugins/native_daemon/src/hook_service.cpp b/device/plugins/native_daemon/src/hook_service.cpp index 0139dd11c..de7ded991 100644 --- a/device/plugins/native_daemon/src/hook_service.cpp +++ b/device/plugins/native_daemon/src/hook_service.cpp @@ -129,9 +129,9 @@ bool HookService::ProtocolProc(SocketContext &context, uint32_t pnum, const int8 PROFILER_LOG_DEBUG(LOG_CORE, "ProtocolProc, receive message from hook client, and send hook config to process %d", peerConfig); context.SendHookConfig(reinterpret_cast(&clientConfig_), sizeof(clientConfig_)); - - std::vector fdVec = hookMgr_->GetFds(peerConfig, procName); - for (int i = 0; i < SHARED_MEMORY_NUM; ++i) { + int sharedMemCount = (clientConfig_.offlineSymbolization) ? SHARED_MEMORY_NUM : 1; + std::vector fdVec = hookMgr_->GetFds(peerConfig, procName, sharedMemCount); + for (int i = 0; i < sharedMemCount; ++i) { int eventFd = fdVec[i * VEC_SHIFT]; int smbFd = fdVec[i * VEC_SHIFT + 1]; if (eventFd == smbFd) { diff --git a/device/plugins/native_daemon/src/stack_preprocess.cpp b/device/plugins/native_daemon/src/stack_preprocess.cpp index d90b3fcde..982b3e491 100644 --- a/device/plugins/native_daemon/src/stack_preprocess.cpp +++ b/device/plugins/native_daemon/src/stack_preprocess.cpp @@ -302,7 +302,8 @@ void StackPreprocess::TakeResultsFromShmem(const std::shared_ptr& return true; } else if (type == END_MSG) { endMsgCount_++; - if (endMsgCount_ == SHARED_MEMORY_NUM) { + int sharedMemCount = (hookConfig_.offline_symbolization()) ? SHARED_MEMORY_NUM : 1; + if (endMsgCount_ == sharedMemCount) { isStopTakeData_ = true; } return true; diff --git a/device/plugins/native_hook/src/hook_client.cpp b/device/plugins/native_hook/src/hook_client.cpp index cc9ab2368..6ed474a99 100644 --- a/device/plugins/native_hook/src/hook_client.cpp +++ b/device/plugins/native_hook/src/hook_client.cpp @@ -49,6 +49,8 @@ static pthread_key_t g_updateThreadNameCount = 10000; static pthread_once_t g_onceFlag; namespace { static std::atomic g_mallocTimes = 0; +static std::atomic g_sharedMemCount = 1; +static std::atomic g_tagId = 0; enum class MISC_TYPE : uint32_t { JS_STACK_DATA = 1, @@ -274,6 +276,7 @@ void* MallocHookStart(void* disableHookCallback) g_hookClient = std::make_shared(g_hookPid.load(), &g_ClientConfig, &g_sampler, &targetedRange, reinterpret_cast(disableHookCallback)); } + g_sharedMemCount = (g_ClientConfig.offlineSymbolization) ? SHARED_MEMORY_NUM : 1; g_hookReady = true; return nullptr; } @@ -350,6 +353,7 @@ void* ohos_release_on_end(void*) g_wholeAddrHandler = nullptr; g_hookClient = nullptr; g_ClientConfig.Reset(); + g_sharedMemCount = 1; g_hookReady = false; return nullptr; } @@ -542,7 +546,7 @@ void* hook_malloc(void* (*fn)(size_t), size_t size) realSize = sizeof(BaseStackRawData) + sizeof(rawdata.regs); } holder->SendStackWithPayload(&rawdata, realSize, reinterpret_cast(stackPtr), stackSize, - reinterpret_cast(rawdata.addr) % SHARED_MEMORY_NUM); + reinterpret_cast(rawdata.addr) % g_sharedMemCount); g_mallocTimes++; #ifdef PERFORMANCE_DEBUG struct timespec end = {}; @@ -637,7 +641,7 @@ void* hook_aligned_alloc(void* (*fn)(size_t, size_t), size_t align, size_t len) realSize = sizeof(BaseStackRawData) + sizeof(rawdata.regs); } holder->SendStackWithPayload(&rawdata, realSize, reinterpret_cast(stackPtr), stackSize, - reinterpret_cast(rawdata.addr) % SHARED_MEMORY_NUM); + reinterpret_cast(rawdata.addr) % g_sharedMemCount); g_mallocTimes++; #ifdef PERFORMANCE_DEBUG struct timespec end = {}; @@ -737,7 +741,7 @@ void* hook_calloc(void* (*fn)(size_t, size_t), size_t number, size_t size) realSize = sizeof(BaseStackRawData) + sizeof(rawdata.regs); } holder->SendStackWithPayload(&rawdata, realSize, reinterpret_cast(stackPtr), stackSize, - reinterpret_cast(rawdata.addr) % SHARED_MEMORY_NUM); + reinterpret_cast(rawdata.addr) % g_sharedMemCount); g_mallocTimes++; #ifdef PERFORMANCE_DEBUG struct timespec end = {}; @@ -845,9 +849,9 @@ void* hook_realloc(void* (*fn)(void*, size_t), void* ptr, size_t size) } // 0: Don't unwind the freeData holder->SendStackWithPayload(&freeData, freeRealSize, nullptr, 0, - reinterpret_cast(freeData.addr) % SHARED_MEMORY_NUM); + reinterpret_cast(freeData.addr) % g_sharedMemCount); holder->SendStackWithPayload(&rawdata, realSize, reinterpret_cast(stackPtr), stackSize, - reinterpret_cast(rawdata.addr) % SHARED_MEMORY_NUM); + reinterpret_cast(rawdata.addr) % g_sharedMemCount); #ifdef PERFORMANCE_DEBUG g_mallocTimes++; struct timespec end = {}; @@ -908,7 +912,7 @@ void hook_free(void (*free_func)(void*), void* p) auto holder = weakClient.lock(); if ((holder != nullptr) && p) { holder->SendStackWithPayload(&p, sizeof(void*), nullptr, 0, - reinterpret_cast(p) % SHARED_MEMORY_NUM); + reinterpret_cast(p) % g_sharedMemCount); } free_func(p); #ifdef PERFORMANCE_DEBUG @@ -980,7 +984,7 @@ void hook_free(void (*free_func)(void*), void* p) realSize = sizeof(BaseStackRawData) + sizeof(rawdata.regs); } holder->SendStackWithPayload(&rawdata, realSize, reinterpret_cast(stackPtr), stackSize, - reinterpret_cast(rawdata.addr) % SHARED_MEMORY_NUM); + reinterpret_cast(rawdata.addr) % g_sharedMemCount); #ifdef PERFORMANCE_DEBUG g_mallocTimes++; struct timespec end = {}; @@ -1131,8 +1135,7 @@ void* hook_mmap(void*(*fn)(void*, size_t, int, int, int, off_t), } else { realSize = sizeof(BaseStackRawData) + sizeof(rawdata.regs); } - holder->SendStackWithPayload(&rawdata, realSize, reinterpret_cast(stackPtr), stackSize, - reinterpret_cast(rawdata.addr) % SHARED_MEMORY_NUM); + holder->SendStackWithPayload(&rawdata, realSize, reinterpret_cast(stackPtr), stackSize); #ifdef PERFORMANCE_DEBUG g_mallocTimes++; struct timespec end = {}; @@ -1211,8 +1214,7 @@ int hook_munmap(int(*fn)(void*, size_t), void* addr, size_t length) } else { realSize = sizeof(BaseStackRawData) + sizeof(rawdata.regs); } - holder->SendStackWithPayload(&rawdata, realSize, reinterpret_cast(stackPtr), stackSize, - reinterpret_cast(rawdata.addr) % SHARED_MEMORY_NUM); + holder->SendStackWithPayload(&rawdata, realSize, reinterpret_cast(stackPtr), stackSize); #ifdef PERFORMANCE_DEBUG g_mallocTimes++; struct timespec end = {}; @@ -1260,7 +1262,7 @@ int hook_prctl(int(*fn)(int, ...), } rawdata.name[sizeof(rawdata.name) - 1] = '\0'; holder->SendStackWithPayload(&rawdata, sizeof(BaseStackRawData) + tagLen, nullptr, 0, - reinterpret_cast(rawdata.addr) % SHARED_MEMORY_NUM); + reinterpret_cast(rawdata.addr) % g_sharedMemCount); #ifdef PERFORMANCE_DEBUG g_mallocTimes++; struct timespec end = {}; @@ -1321,8 +1323,7 @@ void hook_memtrace(void* addr, size_t size, const char* tag, bool isUsing) } else { realSize = sizeof(BaseStackRawData) + sizeof(rawdata.regs); } - holder->SendStackWithPayload(&rawdata, realSize, reinterpret_cast(stackPtr), stackSize, - reinterpret_cast(rawdata.addr) % SHARED_MEMORY_NUM); + holder->SendStackWithPayload(&rawdata, realSize, reinterpret_cast(stackPtr), stackSize); #ifdef PERFORMANCE_DEBUG g_mallocTimes++; struct timespec end = {}; @@ -1484,7 +1485,7 @@ bool ohos_malloc_hook_send_hook_misc_data(uint64_t id, const char* stackPtr, siz auto holder = weakClient.lock(); bool result = true; if (holder != nullptr) { - for (int i = 0; i < SHARED_MEMORY_NUM; ++i) { + for (int i = 0; i < g_sharedMemCount; ++i) { result &= (holder->SendStackWithPayload(&rawdata, sizeof(BaseStackRawData), stackPtr, stackSize, i)); } return result; diff --git a/device/plugins/native_hook/src/hook_socket_client.cpp b/device/plugins/native_hook/src/hook_socket_client.cpp index 291546073..4bc62353e 100644 --- a/device/plugins/native_hook/src/hook_socket_client.cpp +++ b/device/plugins/native_hook/src/hook_socket_client.cpp @@ -83,9 +83,11 @@ HookSocketClient::HookSocketClient(int pid, ClientConfig *config, Sampling *samp : pid_(pid), config_(config), sampler_(sampler), targetedRange_(targetedRange), disableHookCallback_(disableHookCallback) { - smbFds_.reserve(SHARED_MEMORY_NUM); - eventFds_.reserve(SHARED_MEMORY_NUM); - stackWriterList_.reserve(SHARED_MEMORY_NUM); + g_disableHook = true; + int sharedMemCount = (config_->offlineSymbolization) ? SHARED_MEMORY_NUM : 1; + smbFds_.reserve(sharedMemCount); + eventFds_.reserve(sharedMemCount); + stackWriterList_.reserve(sharedMemCount); unixSocketClient_ = nullptr; serviceName_ = "HookService"; Connect(DEFAULT_UNIX_SOCKET_HOOK_FULL_PATH); @@ -100,6 +102,7 @@ HookSocketClient::~HookSocketClient() stackWriterList_[i] = nullptr; } unixSocketClient_ = nullptr; + g_disableHook = true; } bool HookSocketClient::Connect(const std::string addrname) @@ -126,7 +129,8 @@ bool HookSocketClient::ProtocolProc(SocketContext &context, uint32_t pnum, const config_->maxStackDepth = config_->maxStackDepth > MAX_UNWIND_DEPTH ? MAX_UNWIND_DEPTH : config_->maxStackDepth; std::string configStr = config_->ToString(); sampler_->InitSampling(config_->sampleInterval); - for (size_t i = 0; i < SHARED_MEMORY_NUM; ++i) { + int sharedMemCount = (config_->offlineSymbolization) ? SHARED_MEMORY_NUM : 1; + for (size_t i = 0; i < sharedMemCount; ++i) { int smbfd = context.ReceiveFileDiscriptor(); int eventfd = context.ReceiveFileDiscriptor(); smbFds_.push_back(smbfd); diff --git a/device/plugins/native_hook/test/unittest/hook_socket_client_test.cpp b/device/plugins/native_hook/test/unittest/hook_socket_client_test.cpp index a89acf515..3599ebe3d 100644 --- a/device/plugins/native_hook/test/unittest/hook_socket_client_test.cpp +++ b/device/plugins/native_hook/test/unittest/hook_socket_client_test.cpp @@ -106,8 +106,8 @@ HWTEST_F(HookSocketClientTest, FdListSize, TestSize.Level1) auto size = sizeof(clientConfig); HookSocketClient hookClient(1, &g_ClientConfigTest, &sampler, nullptr); ASSERT_TRUE(hookClient.ProtocolProc(socketContext, 0, ptr, size)); - ASSERT_EQ(hookClient.GetSmbFds().size(), OHOS::Developtools::NativeDaemon::SHARED_MEMORY_NUM); - ASSERT_EQ(hookClient.GetEventFds().size(), OHOS::Developtools::NativeDaemon::SHARED_MEMORY_NUM); + ASSERT_EQ(hookClient.GetSmbFds().size(), 1); + ASSERT_EQ(hookClient.GetEventFds().size(), 1); } /* -- Gitee From e1728f2197eb38fe1ca50f41a1f9df7f7160eb12 Mon Sep 17 00:00:00 2001 From: yuhaoqiang Date: Fri, 1 Aug 2025 10:43:33 +0800 Subject: [PATCH 04/27] =?UTF-8?q?hiappevent=E6=89=93=E7=82=B9=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I968592734c15d448a4af7ae1e0128259849a057c Signed-off-by: yuhaoqiang --- hidebug/frameworks/native/BUILD.gn | 3 + .../native/include}/hiappevent_util.h | 1 - .../native/src}/hiappevent_util.cpp | 23 +--- hidebug/interfaces/ets/ani/hidebug/BUILD.gn | 3 - .../ets/ani/hidebug/include/hiappevent_util.h | 38 ------ .../ets/ani/hidebug/src/ani_hidebug.cpp | 18 +-- .../ets/ani/hidebug/src/hiappevent_util.cpp | 111 ------------------ hidebug/interfaces/js/kits/napi/BUILD.gn | 3 - 8 files changed, 5 insertions(+), 195 deletions(-) rename hidebug/{interfaces/js/kits/napi/util => frameworks/native/include}/hiappevent_util.h (99%) rename hidebug/{interfaces/js/kits/napi/util => frameworks/native/src}/hiappevent_util.cpp (85%) delete mode 100644 hidebug/interfaces/ets/ani/hidebug/include/hiappevent_util.h delete mode 100644 hidebug/interfaces/ets/ani/hidebug/src/hiappevent_util.cpp diff --git a/hidebug/frameworks/native/BUILD.gn b/hidebug/frameworks/native/BUILD.gn index f3c9bd825..d83b3fcd0 100644 --- a/hidebug/frameworks/native/BUILD.gn +++ b/hidebug/frameworks/native/BUILD.gn @@ -57,6 +57,7 @@ ohos_shared_library("hidebug_native") { ] sources = [ + "src/hiappevent_util.cpp", "src/hidebug_app_thread_cpu.cpp", "src/hidebug_native_interface_impl.cpp", "src/hidebug_util.cpp", @@ -65,6 +66,8 @@ ohos_shared_library("hidebug_native") { external_deps = [ "ability_runtime:app_context", "c_utils:utils", + "ffrt:libffrt", + "hiappevent:hiappevent_innerapi", "hidumper:lib_dump_usage", "hilog:libhilog", "hitrace:hitrace_meter", diff --git a/hidebug/interfaces/js/kits/napi/util/hiappevent_util.h b/hidebug/frameworks/native/include/hiappevent_util.h similarity index 99% rename from hidebug/interfaces/js/kits/napi/util/hiappevent_util.h rename to hidebug/frameworks/native/include/hiappevent_util.h index 8d7dfd771..2b72de3f9 100644 --- a/hidebug/interfaces/js/kits/napi/util/hiappevent_util.h +++ b/hidebug/frameworks/native/include/hiappevent_util.h @@ -15,7 +15,6 @@ #ifndef HIAPPEVENT_UTIL_H_ #define HIAPPEVENT_UTIL_H_ -#include #include #include #include diff --git a/hidebug/interfaces/js/kits/napi/util/hiappevent_util.cpp b/hidebug/frameworks/native/src/hiappevent_util.cpp similarity index 85% rename from hidebug/interfaces/js/kits/napi/util/hiappevent_util.cpp rename to hidebug/frameworks/native/src/hiappevent_util.cpp index f025335d4..42f830087 100644 --- a/hidebug/interfaces/js/kits/napi/util/hiappevent_util.cpp +++ b/hidebug/frameworks/native/src/hiappevent_util.cpp @@ -39,28 +39,7 @@ void ApiRecordReporter::InitProcessor() using namespace HiAppEvent; ReportConfig config; config.name = "ha_app_event"; - config.appId = "com_huawei_hmos_sdk_ocg"; - config.routeInfo = "AUTO"; - constexpr int triggerTimeOut = 90; - config.triggerCond.timeout = triggerTimeOut; - constexpr int triggerRow = 30; - config.triggerCond.row = triggerRow; - config.eventConfigs.clear(); - config.eventConfigs.push_back({ - .domain = "api_diagnostic", - .name = "api_exec_end", - .isRealTime = false, - }); - config.eventConfigs.push_back({ - .domain = "api_diagnostic", - .name = "api_called_stat", - .isRealTime = true, - }); - config.eventConfigs.push_back({ - .domain = "api_diagnostic", - .name = "api_called_stat_cnt", - .isRealTime = true, - }); + config.configName = "SDK_OCG"; processId_ = AppEventProcessorMgr::AddProcessor(config); if (processId_ < 0) { HILOG_ERROR(LOG_CORE, "failed to init processor and ret: %{public}" PRId64, processId_); diff --git a/hidebug/interfaces/ets/ani/hidebug/BUILD.gn b/hidebug/interfaces/ets/ani/hidebug/BUILD.gn index 316944286..dde42feca 100644 --- a/hidebug/interfaces/ets/ani/hidebug/BUILD.gn +++ b/hidebug/interfaces/ets/ani/hidebug/BUILD.gn @@ -26,7 +26,6 @@ ohos_shared_library("hidebug_ani") { sources = [ "./src/ani_hidebug.cpp", "./src/ani_util.cpp", - "./src/hiappevent_util.cpp", ] deps = [ @@ -40,8 +39,6 @@ ohos_shared_library("hidebug_ani") { "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "c_utils:utils", - "ffrt:libffrt", - "hiappevent:hiappevent_innerapi", "hidumper:lib_dump_usage", "hilog:libhilog", "hitrace:hitrace_meter", diff --git a/hidebug/interfaces/ets/ani/hidebug/include/hiappevent_util.h b/hidebug/interfaces/ets/ani/hidebug/include/hiappevent_util.h deleted file mode 100644 index 66a926fe0..000000000 --- a/hidebug/interfaces/ets/ani/hidebug/include/hiappevent_util.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef DEVELOPTOOLS_PROFILER_HIDEBUG_HIAPPEVENT_UTIL_H -#define DEVELOPTOOLS_PROFILER_HIDEBUG_HIAPPEVENT_UTIL_H - -#include -#include - -namespace OHOS { -namespace HiviewDFX { -class ApiInvokeRecorder { -public: - explicit ApiInvokeRecorder(std::string apiName); - ~ApiInvokeRecorder(); - void SetErrorCode(int errorCode); - static void InitProcessor(); -private: - std::string apiName_; - int errorCode_{0}; - int64_t beginTime_; - static int64_t processId_; -}; -} // namespace HiviewDFX -} // namespace OHOS -#endif // DEVELOPTOOLS_PROFILER_HIDEBUG_HIAPPEVENT_UTIL_H diff --git a/hidebug/interfaces/ets/ani/hidebug/src/ani_hidebug.cpp b/hidebug/interfaces/ets/ani/hidebug/src/ani_hidebug.cpp index 345847cae..a2c387086 100644 --- a/hidebug/interfaces/ets/ani/hidebug/src/ani_hidebug.cpp +++ b/hidebug/interfaces/ets/ani/hidebug/src/ani_hidebug.cpp @@ -52,15 +52,7 @@ namespace { #define LOG_DOMAIN 0xD002D0A #undef LOG_TAG #define LOG_TAG "HiDebug_ANI" -constexpr int BYTE_2_KB_SHIFT_BITS = 10; -constexpr int PSS_MIN = 1024; -constexpr int PSS_MAX = 4 * 1024 * 1024; -constexpr int JS_MIN = 85; -constexpr int JS_MAX = 95; -constexpr int FD_MIN = 10; -constexpr int FD_MAX = 10000; -constexpr int THREAD_MIN = 1; -constexpr int THREAD_MAX = 1000; + constexpr int MAX_TAGS_ARRAY_LENGTH = 40; enum ErrorCode { PERMISSION_ERROR = 201, @@ -315,7 +307,6 @@ static ani_array_ref ConvertThreadCpuUsageMapToEts(ani_env *env, const std::map< ani_array GetAppThreadCpuUsage(ani_env *env) { ApiInvokeRecorder apiInvokeRecorder("getAppThreadCpuUsage"); - ani_array result = nullptr; std::map threadMap = HidebugNativeInterface::GetInstance().GetAppThreadCpuUsage(); return ConvertThreadCpuUsageMapToEts(env, threadMap); } @@ -381,7 +372,6 @@ ani_string StartAppTraceCapture(ani_env *env, std::vector tags; if (AniUtil::ParseAniEnum(env, flagAni, traceFlag) != ANI_OK || !GetTraceParam(env, tagsAni, tags)) { std::string paramErrorMessage = "Invalid argument"; - ani_object undefinedResult = AniUtil::CreateUndefined(env); apiInvokeRecorder.SetErrorCode(ErrorCode::PARAMETER_ERROR); AniUtil::ThrowErrorMessage(env, paramErrorMessage, ErrorCode::PARAMETER_ERROR); return nullptr; @@ -432,12 +422,6 @@ void StopAppTraceCapture(ani_env *env) } } -static bool CheckVersionType(const std::string& type, const std::string& key) -{ - auto versionType = OHOS::system::GetParameter(key, "unknown"); - return (versionType.find(type) != std::string::npos); -} - ani_double GetGraphicsMemorySync(ani_env *env) { ApiInvokeRecorder apiInvokeRecorder("getGraphicsMemorySync"); diff --git a/hidebug/interfaces/ets/ani/hidebug/src/hiappevent_util.cpp b/hidebug/interfaces/ets/ani/hidebug/src/hiappevent_util.cpp deleted file mode 100644 index 05f1dd519..000000000 --- a/hidebug/interfaces/ets/ani/hidebug/src/hiappevent_util.cpp +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include "hiappevent_util.h" - -#include -#include - -#include "app_event.h" -#include "app_event_processor_mgr.h" -#include "ffrt.h" -#include "hidebug_util.h" -#include "hilog/log.h" - -namespace OHOS { -namespace HiviewDFX { - -#undef LOG_DOMAIN -#define LOG_DOMAIN 0xD002D0A -#undef LOG_TAG -#define LOG_TAG "HIAPPEVENT_UTIL" - -int64_t ApiInvokeRecorder::processId_ = -1; - -ApiInvokeRecorder::ApiInvokeRecorder(std::string apiName) : apiName_(std::move(apiName)), - beginTime_(GetElapsedNanoSecondsSinceBoot()) {} - -ApiInvokeRecorder::~ApiInvokeRecorder() -{ - if (processId_ < 0 || beginTime_ < 0) { - return; - } - const int64_t costTime = GetElapsedNanoSecondsSinceBoot() - beginTime_; - if (costTime < 0) { - return; - } - int64_t realEndTime = GetRealNanoSecondsTimestamp(); - int64_t realBeginTime = realEndTime - costTime; - if (realBeginTime < 0 || realEndTime < 0) { - return; - } - std::string apiName(std::move(apiName_)); - int64_t beginTime(beginTime_); - int errorCode(errorCode_); - auto task = [apiName, realEndTime, realBeginTime, errorCode] { - HiAppEvent::Event event("api_diagnostic", "api_exec_end", HiAppEvent::BEHAVIOR); - event.AddParam("trans_id", std::string("transId_") + std::to_string(realBeginTime)); - event.AddParam("api_name", apiName); - event.AddParam("sdk_name", std::string("PerformanceAnalysisKit")); - constexpr int milliSecondsToNanoseconds = 1000 * 1000; - event.AddParam("begin_time", realBeginTime / milliSecondsToNanoseconds); - event.AddParam("end_time", realEndTime / milliSecondsToNanoseconds); - event.AddParam("result", static_cast(errorCode == 0)); - event.AddParam("error_code", errorCode); - Write(event); - }; - ffrt::submit(task, {}, {}); -} - -void ApiInvokeRecorder::SetErrorCode(int errorCode) -{ - errorCode_ = errorCode; -} - -void ApiInvokeRecorder::InitProcessor() -{ - ffrt::submit([] { - using namespace HiAppEvent; - ReportConfig config; - config.name = "ha_app_event"; - config.appId = "com_huawei_hmos_sdk_ocg"; - config.routeInfo = "AUTO"; - constexpr int triggerTimeOut = 90; - config.triggerCond.timeout = triggerTimeOut; - constexpr int triggerRow = 30; - config.triggerCond.row = triggerRow; - config.eventConfigs.clear(); - config.eventConfigs.push_back({ - .domain = "api_diagnostic", - .name = "api_exec_end", - .isRealTime = false, - }); - config.eventConfigs.push_back({ - .domain = "api_diagnostic", - .name = "api_called_stat", - .isRealTime = true, - }); - config.eventConfigs.push_back({ - .domain = "api_diagnostic", - .name = "api_called_stat_cnt", - .isRealTime = true, - }); - processId_ = AppEventProcessorMgr::AddProcessor(config); - if (processId_ < 0) { - HILOG_ERROR(LOG_CORE, "failed to init processor and ret: %{public}" PRId64, processId_); - } - }, {}, {}); -} -} -} diff --git a/hidebug/interfaces/js/kits/napi/BUILD.gn b/hidebug/interfaces/js/kits/napi/BUILD.gn index 7335ff762..f2fb89577 100644 --- a/hidebug/interfaces/js/kits/napi/BUILD.gn +++ b/hidebug/interfaces/js/kits/napi/BUILD.gn @@ -27,7 +27,6 @@ ohos_shared_library("hidebug") { "napi_hidebug_dump.cpp", "napi_hidebug_gc.cpp", "napi_hidebug_init.cpp", - "util/hiappevent_util.cpp", "util/napi_util.cpp", ] @@ -40,8 +39,6 @@ ohos_shared_library("hidebug") { "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "c_utils:utils", - "ffrt:libffrt", - "hiappevent:hiappevent_innerapi", "hidumper:lib_dump_usage", "hilog:libhilog", "hisysevent:libhisysevent", -- Gitee From c144f68425a5debd4d020c504af27a79bb7bf725 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=89=9B=E5=9B=BD=E4=BA=AE?= Date: Sat, 2 Aug 2025 14:45:46 +0800 Subject: [PATCH 05/27] =?UTF-8?q?=E5=BC=80=E6=BA=90=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E4=BB=93=E6=95=8F=E6=84=9F=E4=BF=A1=E6=81=AF=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 牛国亮 --- host/smartperf/client/client_command/cpu_info.cpp | 13 ++++++++----- .../client/client_command/include/common.h | 3 --- .../client/client_command/include/effective.h | 2 +- .../client/client_command/include/hiperf.h | 3 ++- .../client/client_command/smartperf_command.cpp | 1 + host/smartperf/client/client_command/sp_task.cpp | 2 +- host/smartperf/client/client_command/sp_utils.cpp | 5 ++++- .../src/main/ets/common/entity/DatabaseEntity.ets | 2 -- .../ets/common/profiler/base/ProfilerConstant.ts | 2 +- 9 files changed, 18 insertions(+), 15 deletions(-) diff --git a/host/smartperf/client/client_command/cpu_info.cpp b/host/smartperf/client/client_command/cpu_info.cpp index 946625e04..e4a62a4fa 100644 --- a/host/smartperf/client/client_command/cpu_info.cpp +++ b/host/smartperf/client/client_command/cpu_info.cpp @@ -25,7 +25,8 @@ namespace OHOS { namespace SmartPerf { namespace { -const std::string HIPERF_CMD = "/bin/hiperf stat -e hw-instructions,hw-cpu-cycles -d 1 -i 500 "; +const std::string HIPERF_CMD = "/bin/hiperf stat -e " + SPUtils::GetProductName() + "-instructions," + + SPUtils::GetProductName() + "-cpu-cycles -d 1 -i 500 "; } std::map CPUInfo::ItemData() { @@ -55,11 +56,11 @@ std::map CPUInfo::ItemData() }; while (std::getline(stream, line)) { - if (line.find("hw-cpu-cycles") != std::string::npos) { + if (line.find(SPUtils::GetProductName() + "-cpu-cycles") != std::string::npos) { findData(line, cpu_cycles_total, cpu_cycles_count); } - if (line.find("hw-instructions") != std::string::npos) { + if (line.find(SPUtils::GetProductName() + "-instructions") != std::string::npos) { findData(line, instructions_total, instructions_count); size_t comment_pos = line.find("|"); @@ -78,9 +79,11 @@ std::map CPUInfo::ItemData() } cpu_cycles_count == 0 ? "" : - result["hw-cpu-cycles"] = std::to_string(static_cast(cpu_cycles_total) / cpu_cycles_count); + result[SPUtils::GetProductName() + "-cpu-cycles"] = + std::to_string(static_cast(cpu_cycles_total) / cpu_cycles_count); instructions_count == 0 ? "" : - result["hw-instructions"] = std::to_string(static_cast(instructions_total) / instructions_count); + result[SPUtils::GetProductName() + "-instructions"] = + std::to_string(static_cast(instructions_total) / instructions_count); cpi_count == 0 ? "" : result["cycles per instruction"] = std::to_string(cpi_total / cpi_count); Start(); diff --git a/host/smartperf/client/client_command/include/common.h b/host/smartperf/client/client_command/include/common.h index b9b2bbddc..70a9aa019 100644 --- a/host/smartperf/client/client_command/include/common.h +++ b/host/smartperf/client/client_command/include/common.h @@ -113,7 +113,6 @@ enum class CommandType { CT_TRACE, CT_THREADS, CT_SNAPSHOT, - CT_HW, CT_SESSIONID, CT_INTERVAL, CT_NET, @@ -166,7 +165,6 @@ const std::unordered_map COMMAND_MAP = { { std::string("-threads"), CommandType::CT_THREADS }, { std::string("-snapshot"), CommandType::CT_SNAPSHOT }, { std::string("-SCREEN"), CommandType::CT_SNAPSHOT }, - { std::string("-hw"), CommandType::CT_HW }, { std::string("-d"), CommandType::CT_D }, { std::string("-DDR"), CommandType::CT_D }, { std::string("-INTERVAL"), CommandType::CT_INTERVAL }, @@ -204,7 +202,6 @@ const std::unordered_map COMMAND_MAP_REVERSE = { { CommandType::CT_TRACE, std::string("-trace") }, { CommandType::CT_THREADS, std::string("-threads") }, { CommandType::CT_SNAPSHOT, std::string("-snapshot") }, - { CommandType::CT_HW, std::string("-hw") }, { CommandType::CT_D, std::string("-d") }, { CommandType::CT_INTERVAL, std::string("-INTERVAL") }, { CommandType::CT_SESSIONID, std::string("-SESSIONID") }, diff --git a/host/smartperf/client/client_command/include/effective.h b/host/smartperf/client/client_command/include/effective.h index 8cd781f4a..42db10703 100644 --- a/host/smartperf/client/client_command/include/effective.h +++ b/host/smartperf/client/client_command/include/effective.h @@ -101,7 +101,7 @@ private: is_root: false outfile_name: "/data/local/tmp/)"; std::string strEight_ = R"(.data" - record_args: "-f 1000 -a --cpu-limit 100 -e hw-cpu-cycles,sched:sched_waking )"; + record_args: "-f 1000 -a --cpu-limit 100 -e " SPUtils::GetProductName() "-cpu-cycles,sched:sched_waking )"; std::string strTen_ = R"(--call-stack dwarf --clockid monotonic --offcpu -m 256" } })"; diff --git a/host/smartperf/client/client_command/include/hiperf.h b/host/smartperf/client/client_command/include/hiperf.h index 25ea47ddd..ede9f551f 100644 --- a/host/smartperf/client/client_command/include/hiperf.h +++ b/host/smartperf/client/client_command/include/hiperf.h @@ -50,7 +50,8 @@ private: std::string processId_; std::mutex hiperfLock_; std::map hiperfData_ = {}; - std::vector collectNodes_ = {std::string("hw-cpu-cycles"), std::string("hw-instructions")}; + std::vector collectNodes_ = {SPUtils::GetProductName() + + std::string("-cpu-cycles"), SPUtils::GetProductName() + std::string("-instructions")}; bool hiperfFirstCollect_ = true; }; } diff --git a/host/smartperf/client/client_command/smartperf_command.cpp b/host/smartperf/client/client_command/smartperf_command.cpp index b8e5f749f..30bef234e 100644 --- a/host/smartperf/client/client_command/smartperf_command.cpp +++ b/host/smartperf/client/client_command/smartperf_command.cpp @@ -41,6 +41,7 @@ SmartPerfCommand::SmartPerfCommand(std::vector& argv) taskMgr_.AddTask(argv); LOGD("SmartPerfCommand::SmartPerfCommand size(%u)", argv.size()); if (argv.size() == oneParam) { + SPUtils::KillStartDaemon(); SpThreadSocket::GetInstance().SetNeedUdpToken(false); DeviceServer(true); } diff --git a/host/smartperf/client/client_command/sp_task.cpp b/host/smartperf/client/client_command/sp_task.cpp index f02147af6..47abc793c 100644 --- a/host/smartperf/client/client_command/sp_task.cpp +++ b/host/smartperf/client/client_command/sp_task.cpp @@ -260,7 +260,7 @@ std::map SPTask::SetTaskInfo() { "endTime", std::to_string(endTime) }, { "testDuration", std::to_string(testDuration) }, { "taskName", "testtask" }, - { "board", "hw" }, + { "board", SPUtils::GetProductName() }, { "target_fps", refreshrate }, { "gpuDataVersion", gpuDataVersion }, { "battery_change", std::to_string(battaryEnd - battaryStart) }, diff --git a/host/smartperf/client/client_command/sp_utils.cpp b/host/smartperf/client/client_command/sp_utils.cpp index d38af3272..293530716 100644 --- a/host/smartperf/client/client_command/sp_utils.cpp +++ b/host/smartperf/client/client_command/sp_utils.cpp @@ -59,6 +59,9 @@ const unsigned int UI_DECIMALISM = 10; const unsigned int UI_INDEX_2 = 2; const int BUFFER_SIZE = 1024; const std::string SMART_PERF_VERSION = "1.0.9"; +const std::string LOWERCASE_H(1, (char)104); +const std::string LOWERCASE_W(1, (char)119); +const std::string PRODUCT_NAME = LOWERCASE_H + LOWERCASE_W; bool SPUtils::FileAccess(const std::string &fileName) { return (access(fileName.c_str(), F_OK) == 0); @@ -364,7 +367,7 @@ std::map SPUtils::GetDeviceInfo() resultMap["sn"] = OHOS::system::GetParameter((DEVICE_CMD_MAP.at(DeviceCmd::SN)), "Unknown"); resultMap["deviceTypeName"] = OHOS::system::GetParameter(DEVICE_CMD_MAP.at(DeviceCmd::DEVICET_NAME), "Unknown"); resultMap["brand"] = OHOS::system::GetParameter(DEVICE_CMD_MAP.at(DeviceCmd::BRAND), "Unknown"); - resultMap["board"] = "hw"; + resultMap["board"] = GetProductName(); resultMap["version"] = OHOS::system::GetParameter(DEVICE_CMD_MAP.at(DeviceCmd::VERSION), "Unknown"); resultMap["abilist"] = OHOS::system::GetParameter(DEVICE_CMD_MAP.at(DeviceCmd::ABILIST), "Unknown"); resultMap["name"] = OHOS::system::GetParameter(DEVICE_CMD_MAP.at(DeviceCmd::NAME), "Unknown"); diff --git a/host/smartperf/client/client_ui/entry/src/main/ets/common/entity/DatabaseEntity.ets b/host/smartperf/client/client_ui/entry/src/main/ets/common/entity/DatabaseEntity.ets index 736a565bc..a5f38face 100644 --- a/host/smartperf/client/client_ui/entry/src/main/ets/common/entity/DatabaseEntity.ets +++ b/host/smartperf/client/client_ui/entry/src/main/ets/common/entity/DatabaseEntity.ets @@ -194,10 +194,8 @@ export class TIndexInfo { public voltageNow: String; //ram public pss: String; - //HWCPipeGPU public cacheMisses: String; public instructions: String; - //HWCPipeGPU public gpuCycles: String; public vertexComputeCycles: String; public fragmentCycles: String; diff --git a/host/smartperf/client/client_ui/entry/src/main/ets/common/profiler/base/ProfilerConstant.ts b/host/smartperf/client/client_ui/entry/src/main/ets/common/profiler/base/ProfilerConstant.ts index 9a436baac..ce0835d48 100644 --- a/host/smartperf/client/client_ui/entry/src/main/ets/common/profiler/base/ProfilerConstant.ts +++ b/host/smartperf/client/client_ui/entry/src/main/ets/common/profiler/base/ProfilerConstant.ts @@ -44,7 +44,7 @@ export enum CollectorType { TYPE_GPU = 'GPU', TYPE_DDR = 'DDR', TYPE_FPS = 'FPS', - TYPE_HW_COUNTER = 'HW_COUNTER', + TYPE_COUNTER = 'COUNTER', TYPE_POWER = 'POWER', TYPE_TEMPERATURE = 'TEMP', TYPE_RAM = 'RAM', -- Gitee From 74a7233cc2f760dbd6bcf7b8ca389f6fdbcfb67d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=89=9B=E5=9B=BD=E4=BA=AE?= Date: Sat, 2 Aug 2025 16:03:34 +0800 Subject: [PATCH 06/27] =?UTF-8?q?=E4=BF=AE=E6=94=B9hiperf=E5=AD=97?= =?UTF-8?q?=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 牛国亮 --- .../client/client_command/cpu_info.cpp | 23 +++++++++---------- .../client/client_command/include/cpu_info.h | 1 + .../client/client_command/sp_utils.cpp | 4 ++-- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/host/smartperf/client/client_command/cpu_info.cpp b/host/smartperf/client/client_command/cpu_info.cpp index e4a62a4fa..821600405 100644 --- a/host/smartperf/client/client_command/cpu_info.cpp +++ b/host/smartperf/client/client_command/cpu_info.cpp @@ -32,16 +32,22 @@ std::map CPUInfo::ItemData() { Stop(); std::map result; + GetCpuInfoBuffer(result); + Start(); + LOGI("CPUInfo:ItemData map size(%u)", result.size()); + return result; +} + +void CPUInfo::GetCpuInfoBuffer(std::map &bufferResult) +{ std::istringstream stream(buffer_); std::string line; - uint64_t cpu_cycles_total = 0; uint64_t instructions_total = 0; double cpi_total = 0.0; size_t cpu_cycles_count = 0; size_t instructions_count = 0; size_t cpi_count = 0; - auto trim = [](std::string& s) { s.erase(0, s.find_first_not_of(" \t")); s.erase(s.find_last_not_of(" \t") + 1); @@ -54,12 +60,10 @@ std::map CPUInfo::ItemData() total += SPUtilesTye::StringToSometype(number_str); ++count; }; - while (std::getline(stream, line)) { if (line.find(SPUtils::GetProductName() + "-cpu-cycles") != std::string::npos) { findData(line, cpu_cycles_total, cpu_cycles_count); } - if (line.find(SPUtils::GetProductName() + "-instructions") != std::string::npos) { findData(line, instructions_total, instructions_count); @@ -77,18 +81,13 @@ std::map CPUInfo::ItemData() } } } - cpu_cycles_count == 0 ? "" : - result[SPUtils::GetProductName() + "-cpu-cycles"] = + bufferResult[SPUtils::GetProductName() + "-cpu-cycles"] = std::to_string(static_cast(cpu_cycles_total) / cpu_cycles_count); instructions_count == 0 ? "" : - result[SPUtils::GetProductName() + "-instructions"] = + bufferResult[SPUtils::GetProductName() + "-instructions"] = std::to_string(static_cast(instructions_total) / instructions_count); - cpi_count == 0 ? "" : result["cycles per instruction"] = std::to_string(cpi_total / cpi_count); - - Start(); - LOGI("CPUInfo:ItemData map size(%u)", result.size()); - return result; + cpi_count == 0 ? "" : bufferResult["cycles per instruction"] = std::to_string(cpi_total / cpi_count); } void CPUInfo::StartExecutionOnce(bool isPause) diff --git a/host/smartperf/client/client_command/include/cpu_info.h b/host/smartperf/client/client_command/include/cpu_info.h index 044823218..4dd22face 100644 --- a/host/smartperf/client/client_command/include/cpu_info.h +++ b/host/smartperf/client/client_command/include/cpu_info.h @@ -38,6 +38,7 @@ public: void SetPids(const std::string& pids); void Start(); void Stop(); + void GetCpuInfoBuffer(std::map &bufferResult); private: std::vector pids_; std::thread th_; diff --git a/host/smartperf/client/client_command/sp_utils.cpp b/host/smartperf/client/client_command/sp_utils.cpp index 293530716..15d3c00ce 100644 --- a/host/smartperf/client/client_command/sp_utils.cpp +++ b/host/smartperf/client/client_command/sp_utils.cpp @@ -59,8 +59,8 @@ const unsigned int UI_DECIMALISM = 10; const unsigned int UI_INDEX_2 = 2; const int BUFFER_SIZE = 1024; const std::string SMART_PERF_VERSION = "1.0.9"; -const std::string LOWERCASE_H(1, (char)104); -const std::string LOWERCASE_W(1, (char)119); +const std::string LOWERCASE_H(1, static_cast(char)104); +const std::string LOWERCASE_W(1, static_cast(char)119); const std::string PRODUCT_NAME = LOWERCASE_H + LOWERCASE_W; bool SPUtils::FileAccess(const std::string &fileName) { -- Gitee From b8f21f5b214a2321c81acfa9bf3885c2e663b4b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=89=9B=E5=9B=BD=E4=BA=AE?= Date: Sat, 2 Aug 2025 16:49:16 +0800 Subject: [PATCH 07/27] =?UTF-8?q?=E4=BF=AE=E6=94=B9codecheck?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 牛国亮 --- .../client/client_command/cpu_info.cpp | 44 +++++++++++-------- .../client/client_command/include/hiperf.h | 5 ++- 2 files changed, 28 insertions(+), 21 deletions(-) diff --git a/host/smartperf/client/client_command/cpu_info.cpp b/host/smartperf/client/client_command/cpu_info.cpp index 821600405..c22f6f1b2 100644 --- a/host/smartperf/client/client_command/cpu_info.cpp +++ b/host/smartperf/client/client_command/cpu_info.cpp @@ -61,25 +61,8 @@ void CPUInfo::GetCpuInfoBuffer(std::map &bufferResult) ++count; }; while (std::getline(stream, line)) { - if (line.find(SPUtils::GetProductName() + "-cpu-cycles") != std::string::npos) { - findData(line, cpu_cycles_total, cpu_cycles_count); - } - if (line.find(SPUtils::GetProductName() + "-instructions") != std::string::npos) { - findData(line, instructions_total, instructions_count); - - size_t comment_pos = line.find("|"); - if (comment_pos != std::string::npos) { - std::string comment = line.substr(comment_pos + 1); - trim(comment); - size_t cpi_pos = comment.find("cycles per instruction"); - if (cpi_pos != std::string::npos) { - size_t number_end = comment.find(" ", 0); - std::string cpi_str = comment.substr(0, number_end); - cpi_total += SPUtilesTye::StringToSometype(cpi_str); - ++cpi_count; - } - } - } + HandleCpuInfoData(line, cpu_cycles_total, cpu_cycles_count, instructions_count, + cpi_count, cpi_total); } cpu_cycles_count == 0 ? "" : bufferResult[SPUtils::GetProductName() + "-cpu-cycles"] = @@ -90,6 +73,29 @@ void CPUInfo::GetCpuInfoBuffer(std::map &bufferResult) cpi_count == 0 ? "" : bufferResult["cycles per instruction"] = std::to_string(cpi_total / cpi_count); } +void CPUInfo::HandleCpuInfoData(std::string line, uint64_t cpu_cycles_total, size_t cpu_cycles_count, + size_t instructions_count, size_t cpi_count, double cpi_total) +{ + if (line.find(SPUtils::GetProductName() + "-cpu-cycles") != std::string::npos) { + findData(line, cpu_cycles_total, cpu_cycles_count); + } + if (line.find(SPUtils::GetProductName() + "-instructions") != std::string::npos) { + findData(line, instructions_total, instructions_count); + size_t comment_pos = line.find("|"); + if (comment_pos != std::string::npos) { + std::string comment = line.substr(comment_pos + 1); + trim(comment); + size_t cpi_pos = comment.find("cycles per instruction"); + if (cpi_pos != std::string::npos) { + size_t number_end = comment.find(" ", 0); + std::string cpi_str = comment.substr(0, number_end); + cpi_total += SPUtilesTye::StringToSometype(cpi_str); + ++cpi_count; + } + } + } +} + void CPUInfo::StartExecutionOnce(bool isPause) { (void)isPause; diff --git a/host/smartperf/client/client_command/include/hiperf.h b/host/smartperf/client/client_command/include/hiperf.h index ede9f551f..9a40a2a4d 100644 --- a/host/smartperf/client/client_command/include/hiperf.h +++ b/host/smartperf/client/client_command/include/hiperf.h @@ -50,8 +50,9 @@ private: std::string processId_; std::mutex hiperfLock_; std::map hiperfData_ = {}; - std::vector collectNodes_ = {SPUtils::GetProductName() + - std::string("-cpu-cycles"), SPUtils::GetProductName() + std::string("-instructions")}; + const std::string cpuCycles = SPUtils::GetProductName() + "-cpu-cycles"; + const std::string inStructions = SPUtils::GetProductName() + "-instructions"; + std::vector collectNodes_ = {cpuCycles, inStructions}; bool hiperfFirstCollect_ = true; }; } -- Gitee From eb2db4f7c1c17a220526a371da7517b42f670d8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=89=9B=E5=9B=BD=E4=BA=AE?= Date: Sat, 2 Aug 2025 18:01:12 +0800 Subject: [PATCH 08/27] =?UTF-8?q?=E4=BF=AE=E6=94=B9codecheck?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 牛国亮 --- .../client/client_command/cpu_info.cpp | 57 ++++++++----------- .../client/client_command/hiperf.cpp | 1 - .../client/client_command/include/cpu_info.h | 1 + .../client/client_command/include/hiperf.h | 1 + .../client/client_command/include/sp_utils.h | 1 + .../client/client_command/sp_utils.cpp | 9 ++- 6 files changed, 35 insertions(+), 35 deletions(-) diff --git a/host/smartperf/client/client_command/cpu_info.cpp b/host/smartperf/client/client_command/cpu_info.cpp index c22f6f1b2..69d24a409 100644 --- a/host/smartperf/client/client_command/cpu_info.cpp +++ b/host/smartperf/client/client_command/cpu_info.cpp @@ -32,14 +32,6 @@ std::map CPUInfo::ItemData() { Stop(); std::map result; - GetCpuInfoBuffer(result); - Start(); - LOGI("CPUInfo:ItemData map size(%u)", result.size()); - return result; -} - -void CPUInfo::GetCpuInfoBuffer(std::map &bufferResult) -{ std::istringstream stream(buffer_); std::string line; uint64_t cpu_cycles_total = 0; @@ -48,10 +40,6 @@ void CPUInfo::GetCpuInfoBuffer(std::map &bufferResult) size_t cpu_cycles_count = 0; size_t instructions_count = 0; size_t cpi_count = 0; - auto trim = [](std::string& s) { - s.erase(0, s.find_first_not_of(" \t")); - s.erase(s.find_last_not_of(" \t") + 1); - }; auto findData = [](const std::string& targetStr, auto& total, auto& count) { size_t count_start = targetStr.find_first_not_of(" \t"); size_t count_end = targetStr.find(" ", count_start); @@ -61,8 +49,13 @@ void CPUInfo::GetCpuInfoBuffer(std::map &bufferResult) ++count; }; while (std::getline(stream, line)) { - HandleCpuInfoData(line, cpu_cycles_total, cpu_cycles_count, instructions_count, - cpi_count, cpi_total); + if (line.find(SPUtils::GetProductName() + "-cpu-cycles") != std::string::npos) { + findData(line, cpu_cycles_total, cpu_cycles_count); + } + if (line.find(SPUtils::GetProductName() + "-instructions") != std::string::npos) { + findData(line, instructions_total, instructions_count); + CalculateCPIInfo(line, cpi_total, cpi_count); + } } cpu_cycles_count == 0 ? "" : bufferResult[SPUtils::GetProductName() + "-cpu-cycles"] = @@ -71,27 +64,27 @@ void CPUInfo::GetCpuInfoBuffer(std::map &bufferResult) bufferResult[SPUtils::GetProductName() + "-instructions"] = std::to_string(static_cast(instructions_total) / instructions_count); cpi_count == 0 ? "" : bufferResult["cycles per instruction"] = std::to_string(cpi_total / cpi_count); + Start(); + LOGI("CPUInfo:ItemData map size(%u)", result.size()); + return result; } -void CPUInfo::HandleCpuInfoData(std::string line, uint64_t cpu_cycles_total, size_t cpu_cycles_count, - size_t instructions_count, size_t cpi_count, double cpi_total) +void CPUInfo::CalculateCPIInfo(const std::string line, double &cpi_total, size_t &cpi_count) { - if (line.find(SPUtils::GetProductName() + "-cpu-cycles") != std::string::npos) { - findData(line, cpu_cycles_total, cpu_cycles_count); - } - if (line.find(SPUtils::GetProductName() + "-instructions") != std::string::npos) { - findData(line, instructions_total, instructions_count); - size_t comment_pos = line.find("|"); - if (comment_pos != std::string::npos) { - std::string comment = line.substr(comment_pos + 1); - trim(comment); - size_t cpi_pos = comment.find("cycles per instruction"); - if (cpi_pos != std::string::npos) { - size_t number_end = comment.find(" ", 0); - std::string cpi_str = comment.substr(0, number_end); - cpi_total += SPUtilesTye::StringToSometype(cpi_str); - ++cpi_count; - } + auto trim = [](std::string& s) { + s.erase(0, s.find_first_not_of(" \t")); + s.erase(s.find_last_not_of(" \t") + 1); + }; + size_t comment_pos = line.find("|"); + if (comment_pos != std::string::npos) { + std::string comment = line.substr(comment_pos + 1); + trim(comment); + size_t cpi_pos = comment.find("cycles per instruction"); + if (cpi_pos != std::string::npos) { + size_t number_end = comment.find(" ", 0); + std::string cpi_str = comment.substr(0, number_end); + cpi_total += SPUtilesTye::StringToSometype(cpi_str); + ++cpi_count; } } } diff --git a/host/smartperf/client/client_command/hiperf.cpp b/host/smartperf/client/client_command/hiperf.cpp index 1fc3671b0..5e4a80d38 100644 --- a/host/smartperf/client/client_command/hiperf.cpp +++ b/host/smartperf/client/client_command/hiperf.cpp @@ -17,7 +17,6 @@ #include #include #include "include/hiperf.h" -#include "include/sp_utils.h" #include "include/sp_log.h" #include "include/sp_thread_socket.h" namespace OHOS { diff --git a/host/smartperf/client/client_command/include/cpu_info.h b/host/smartperf/client/client_command/include/cpu_info.h index 4dd22face..1086739ff 100644 --- a/host/smartperf/client/client_command/include/cpu_info.h +++ b/host/smartperf/client/client_command/include/cpu_info.h @@ -39,6 +39,7 @@ public: void Start(); void Stop(); void GetCpuInfoBuffer(std::map &bufferResult); + void CalculateCPIInfo(const std::string line, double &cpi_total, size_t &cpi_count); private: std::vector pids_; std::thread th_; diff --git a/host/smartperf/client/client_command/include/hiperf.h b/host/smartperf/client/client_command/include/hiperf.h index 9a40a2a4d..a68c645c2 100644 --- a/host/smartperf/client/client_command/include/hiperf.h +++ b/host/smartperf/client/client_command/include/hiperf.h @@ -21,6 +21,7 @@ #include "vector" #include #include "sp_profiler.h" +#include "sp_utils.h" namespace OHOS { namespace SmartPerf { class Hiperf : public SpProfiler { diff --git a/host/smartperf/client/client_command/include/sp_utils.h b/host/smartperf/client/client_command/include/sp_utils.h index 61bbeb14d..3e3a57172 100644 --- a/host/smartperf/client/client_command/include/sp_utils.h +++ b/host/smartperf/client/client_command/include/sp_utils.h @@ -169,6 +169,7 @@ std::string ExecuteCommand(const std::string& command); size_t GetFileSize(std::string filePath); bool IsFindDHGame(const std::string &pkg); std::string GetSurface(); +std::string GetProductName(); }; } } diff --git a/host/smartperf/client/client_command/sp_utils.cpp b/host/smartperf/client/client_command/sp_utils.cpp index 15d3c00ce..29f10195a 100644 --- a/host/smartperf/client/client_command/sp_utils.cpp +++ b/host/smartperf/client/client_command/sp_utils.cpp @@ -59,8 +59,8 @@ const unsigned int UI_DECIMALISM = 10; const unsigned int UI_INDEX_2 = 2; const int BUFFER_SIZE = 1024; const std::string SMART_PERF_VERSION = "1.0.9"; -const std::string LOWERCASE_H(1, static_cast(char)104); -const std::string LOWERCASE_W(1, static_cast(char)119); +const std::string LOWERCASE_H(1, static_cast(104)); +const std::string LOWERCASE_W(1, static_cast(119)); const std::string PRODUCT_NAME = LOWERCASE_H + LOWERCASE_W; bool SPUtils::FileAccess(const std::string &fileName) { @@ -966,5 +966,10 @@ std::string SPUtils::GetSurface() size_t positionNum = 1; return cmdResult.substr(positionLeft + positionNum, positionRight - positionLeft - positionNum); } + +std::string SPUtils::GetProductName() +{ + return PRODUCT_NAME; +} } } -- Gitee From 60dbc6cc499bb0fc4dd4687b86aad7f34cd5614b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=89=9B=E5=9B=BD=E4=BA=AE?= Date: Mon, 4 Aug 2025 09:57:07 +0800 Subject: [PATCH 09/27] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=BC=96=E8=AF=91?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 牛国亮 --- host/smartperf/client/client_command/cpu_info.cpp | 6 +++--- host/smartperf/client/client_command/include/cpu_info.h | 1 - 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/host/smartperf/client/client_command/cpu_info.cpp b/host/smartperf/client/client_command/cpu_info.cpp index 69d24a409..f1cdfa870 100644 --- a/host/smartperf/client/client_command/cpu_info.cpp +++ b/host/smartperf/client/client_command/cpu_info.cpp @@ -58,12 +58,12 @@ std::map CPUInfo::ItemData() } } cpu_cycles_count == 0 ? "" : - bufferResult[SPUtils::GetProductName() + "-cpu-cycles"] = + result[SPUtils::GetProductName() + "-cpu-cycles"] = std::to_string(static_cast(cpu_cycles_total) / cpu_cycles_count); instructions_count == 0 ? "" : - bufferResult[SPUtils::GetProductName() + "-instructions"] = + result[SPUtils::GetProductName() + "-instructions"] = std::to_string(static_cast(instructions_total) / instructions_count); - cpi_count == 0 ? "" : bufferResult["cycles per instruction"] = std::to_string(cpi_total / cpi_count); + cpi_count == 0 ? "" : result["cycles per instruction"] = std::to_string(cpi_total / cpi_count); Start(); LOGI("CPUInfo:ItemData map size(%u)", result.size()); return result; diff --git a/host/smartperf/client/client_command/include/cpu_info.h b/host/smartperf/client/client_command/include/cpu_info.h index 1086739ff..ae1c3b4fe 100644 --- a/host/smartperf/client/client_command/include/cpu_info.h +++ b/host/smartperf/client/client_command/include/cpu_info.h @@ -38,7 +38,6 @@ public: void SetPids(const std::string& pids); void Start(); void Stop(); - void GetCpuInfoBuffer(std::map &bufferResult); void CalculateCPIInfo(const std::string line, double &cpi_total, size_t &cpi_count); private: std::vector pids_; -- Gitee From 3f6ffa2ba46181d1fd468bf5ceb00a9345d44938 Mon Sep 17 00:00:00 2001 From: ganchuantao Date: Mon, 4 Aug 2025 11:55:53 +0800 Subject: [PATCH 10/27] add result file size log Signed-off-by: ganchuantao Change-Id: Ibced194c49d443187f6c97af8873b1fb076a2f13 --- device/services/profiler_service/src/profiler_service.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/device/services/profiler_service/src/profiler_service.cpp b/device/services/profiler_service/src/profiler_service.cpp index 81cb516c5..78af1b672 100644 --- a/device/services/profiler_service/src/profiler_service.cpp +++ b/device/services/profiler_service/src/profiler_service.cpp @@ -15,6 +15,7 @@ #define LOG_TAG "ProfilerService" #include "profiler_service.h" #include +#include #include #include "common.h" #include "logging.h" @@ -58,6 +59,7 @@ constexpr int MIN_SESSION_TIMEOUT_MS = 1000; constexpr int MAX_SESSION_TIMEOUT_MS = 1000 * 3600; constexpr int DEFAULT_KEEP_ALIVE_DELTA = 3000; constexpr uint64_t CHECK_HEARTBEAT_INTERVAL = 500; +constexpr long BYTE_PER_KB = 1024; const std::string HIPROFILER_PLUGINS_NAME("hiprofiler_plugins"); #ifdef PERFORMANCE_DEBUG constexpr uint64_t S_TO_NS = 1000 * 1000 * 1000; @@ -736,6 +738,12 @@ Status ProfilerService::DestroySession(ServerContext* context, "remove plugin session FAILED!"); PROFILER_LOG_INFO(LOG_CORE, "DestroySession %d %u done!", request->request_id(), sessionId); + struct stat fileInfo; + if (stat(ctx->sessionConfig.result_file().c_str(), &fileInfo) == 0) { + long result = static_cast(fileInfo.st_size() / BYTE_PER_KB); + PROFILER_LOG_INFO(LOG_CORE, "result file %s size is %ld KB", ctx->sessionConfig.result_file().c_str(), result); + } + if (ctx->sessionConfig.session_mode() == ProfilerSessionConfig::OFFLINE) { uint32_t pluginId = 0; PluginContextPtr pluginCtx = nullptr; -- Gitee From bef411f8e1f1324a253e32ab90be302a52c0ea17 Mon Sep 17 00:00:00 2001 From: ganchuantao Date: Mon, 4 Aug 2025 12:20:54 +0800 Subject: [PATCH 11/27] add result file size log Signed-off-by: ganchuantao Change-Id: Ib43d57a381cfdaa286078b5f5e64e7446850a01b --- device/services/profiler_service/src/profiler_service.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/device/services/profiler_service/src/profiler_service.cpp b/device/services/profiler_service/src/profiler_service.cpp index 78af1b672..b5e37d1e8 100644 --- a/device/services/profiler_service/src/profiler_service.cpp +++ b/device/services/profiler_service/src/profiler_service.cpp @@ -740,7 +740,7 @@ Status ProfilerService::DestroySession(ServerContext* context, struct stat fileInfo; if (stat(ctx->sessionConfig.result_file().c_str(), &fileInfo) == 0) { - long result = static_cast(fileInfo.st_size() / BYTE_PER_KB); + long result = static_cast(fileInfo.st_size / BYTE_PER_KB); PROFILER_LOG_INFO(LOG_CORE, "result file %s size is %ld KB", ctx->sessionConfig.result_file().c_str(), result); } -- Gitee From 24a8e3cea24cb9818edb3ee3978ae89aadb45001 Mon Sep 17 00:00:00 2001 From: ganchuantao Date: Mon, 4 Aug 2025 15:01:11 +0800 Subject: [PATCH 12/27] add result file size log Signed-off-by: ganchuantao Change-Id: I8d76e101ed7e096a566076030c17c805b5d47b45 --- device/plugins/native_daemon/src/stack_preprocess.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/device/plugins/native_daemon/src/stack_preprocess.cpp b/device/plugins/native_daemon/src/stack_preprocess.cpp index d90b3fcde..1fb9cab19 100644 --- a/device/plugins/native_daemon/src/stack_preprocess.cpp +++ b/device/plugins/native_daemon/src/stack_preprocess.cpp @@ -220,10 +220,6 @@ bool StackPreprocess::HandleNoStackEvent(HookRecordPtr& hookRecord) BaseStackRawData* mmapRawData = rawData->stackContext; std::string filePath(reinterpret_cast(rawData->data)); COMMON::AdaptSandboxPath(filePath, rawData->stackContext->pid); - PROFILER_LOG_DEBUG(LOG_CORE, "MMAP_FILE_TYPE curMmapAddr=%p, MAP_FIXED=%d, " - "PROT_EXEC=%d, offset=%" PRIu64 ", filePath=%s", - mmapRawData->addr, mmapRawData->mmapArgs.flags & MAP_FIXED, - mmapRawData->mmapArgs.flags & PROT_EXEC, mmapRawData->mmapArgs.offset, filePath.data()); std::lock_guard guard(mtx_); runtime_instance->HandleMapInfo({reinterpret_cast(mmapRawData->addr), mmapRawData->mallocSize, mmapRawData->mmapArgs.flags, mmapRawData->mmapArgs.offset}, filePath, -- Gitee From 42b18a779e4a4ab108debb6dba9c99e3ca785081 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=89=9B=E5=9B=BD=E4=BA=AE?= Date: Mon, 4 Aug 2025 15:50:43 +0800 Subject: [PATCH 13/27] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=BC=96=E8=AF=91?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 牛国亮 --- host/smartperf/client/client_command/cpu_info.cpp | 5 ----- host/smartperf/client/client_command/include/cpu_info.h | 3 ++- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/host/smartperf/client/client_command/cpu_info.cpp b/host/smartperf/client/client_command/cpu_info.cpp index f1cdfa870..84976bb24 100644 --- a/host/smartperf/client/client_command/cpu_info.cpp +++ b/host/smartperf/client/client_command/cpu_info.cpp @@ -24,10 +24,6 @@ #include "sp_log.h" namespace OHOS { namespace SmartPerf { -namespace { -const std::string HIPERF_CMD = "/bin/hiperf stat -e " + SPUtils::GetProductName() + "-instructions," + - SPUtils::GetProductName() + "-cpu-cycles -d 1 -i 500 "; -} std::map CPUInfo::ItemData() { Stop(); @@ -93,7 +89,6 @@ void CPUInfo::StartExecutionOnce(bool isPause) { (void)isPause; Stop(); - hiperfCmd_ = HIPERF_CMD; if (pids_.empty()) { hiperfCmd_ += "-a"; } else { diff --git a/host/smartperf/client/client_command/include/cpu_info.h b/host/smartperf/client/client_command/include/cpu_info.h index ae1c3b4fe..f4e717a7c 100644 --- a/host/smartperf/client/client_command/include/cpu_info.h +++ b/host/smartperf/client/client_command/include/cpu_info.h @@ -42,7 +42,8 @@ public: private: std::vector pids_; std::thread th_; - std::string hiperfCmd_; + std::string hiperfCmd_ = "/bin/hiperf stat -e " + SPUtils::GetProductName() + "-instructions," + + SPUtils::GetProductName() + "-cpu-cycles -d 1 -i 500 "; std::atomic_bool running_ {false}; std::condition_variable cond_; std::mutex mtx_; -- Gitee From 8d15db66a4461a5c88a5ee701215b9c3fb699b1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=89=9B=E5=9B=BD=E4=BA=AE?= Date: Mon, 4 Aug 2025 16:52:10 +0800 Subject: [PATCH 14/27] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=BC=96=E8=AF=91?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 牛国亮 --- host/smartperf/client/client_command/cpu_info.cpp | 1 - host/smartperf/client/client_command/include/cpu_info.h | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/host/smartperf/client/client_command/cpu_info.cpp b/host/smartperf/client/client_command/cpu_info.cpp index 84976bb24..98f87d0aa 100644 --- a/host/smartperf/client/client_command/cpu_info.cpp +++ b/host/smartperf/client/client_command/cpu_info.cpp @@ -14,7 +14,6 @@ */ #include "cpu_info.h" -#include "sp_utils.h" #include #include diff --git a/host/smartperf/client/client_command/include/cpu_info.h b/host/smartperf/client/client_command/include/cpu_info.h index f4e717a7c..46c892004 100644 --- a/host/smartperf/client/client_command/include/cpu_info.h +++ b/host/smartperf/client/client_command/include/cpu_info.h @@ -17,6 +17,7 @@ #define CPU_INFO_H #include "sp_profiler.h" +#include "sp_utils.h" #include #include #include -- Gitee From 8b53b4283426887160c7dcb7d33aedf95a90c2ee Mon Sep 17 00:00:00 2001 From: zyxzyx Date: Mon, 4 Aug 2025 17:07:00 +0800 Subject: [PATCH 15/27] fix bundle names Signed-off-by: zyxzyx --- .../test/utresources/proc/dumpMem.txt | 3 - .../proc/window_manager_service.txt | 83 ------------------- .../config_nativehook_dwarf.txt | 2 +- .../inputfiles/nativehook/config13.txt | 2 +- .../scripts/inputfiles/nativehook/config7.txt | 2 +- .../scripts/inputfiles/nativehook/config9.txt | 2 +- .../xpower_plugin/config_xpower.txt | 2 +- .../scripts/testReliability/test_appfreeze.py | 12 +-- test/scripts/testReliability/test_crash.py | 2 +- test/scripts/testRoot/test_allplugin.py | 2 +- test/scripts/testRoot/test_hidump_plugin.py | 8 -- test/scripts/testRoot/test_memory_plugin.py | 6 +- test/scripts/testRoot/test_nativehook.py | 8 +- .../scripts/testRoot/test_nativehook_32bit.py | 5 +- test/scripts/testRoot/test_xpower.py | 6 -- 15 files changed, 20 insertions(+), 125 deletions(-) diff --git a/device/plugins/memory_plugin/test/utresources/proc/dumpMem.txt b/device/plugins/memory_plugin/test/utresources/proc/dumpMem.txt index 984aa76b5..a3c4e917a 100644 --- a/device/plugins/memory_plugin/test/utresources/proc/dumpMem.txt +++ b/device/plugins/memory_plugin/test/utresources/proc/dumpMem.txt @@ -167,9 +167,6 @@ Total GPU memory usage: 8367072 bytes, 7.98 MB (7.98 MB is purgeable) --------------- -Skia GPU Caches:com.huawei.hmsapp.intelligententryMainWindowExtAbility0 12605729013761 - skia/gr_text_blob_cache: - Other: 3.33 KB (1 entry) Total GPU memory usage: 3408 bytes, 3.33 KB (0.00 bytes is purgeable) diff --git a/device/plugins/memory_plugin/test/utresources/proc/window_manager_service.txt b/device/plugins/memory_plugin/test/utresources/proc/window_manager_service.txt index 0b4efb68a..73234a732 100644 --- a/device/plugins/memory_plugin/test/utresources/proc/window_manager_service.txt +++ b/device/plugins/memory_plugin/test/utresources/proc/window_manager_service.txt @@ -26,86 +26,3 @@ music0 0 25177 24 1 1 0 -1 0 [ 0 Focus window: 14 Total window num: 24 -Current mission lists: - MissionList Type #NORMAL - Mission ID #17 mission name #[#com.huawei.hmos.hwupgradeguide::GuideHomeAbility] lockedState #0 - app name [com.huawei.hmos.hwupgradeguide] - main name [GuideHomeAbility] - bundle name [com.huawei.hmos.hwupgradeguide] - ability type [PAGE] - state #BACKGROUND - app state #BACKGROUND - callee connections: - Mission ID #18 mission name #[#com.huawei.hmos.settings:phone_settings:com.huawei.hmos.settings.MainAbility] lockedState #0 - app name [com.huawei.hmos.settings] - main name [com.huawei.hmos.settings.MainAbility] - bundle name [com.huawei.hmos.settings] - ability type [PAGE] - state #BACKGROUND - app state #BACKGROUND - callee connections: - Mission ID #19 mission name #[#com.huawei.hms.hmscore:hmscore_account:AccountBasicAbility] lockedState #0 - app name [com.huawei.hms.hmscore] - main name [AccountBasicAbility] - bundle name [com.huawei.hms.hmscore] - ability type [PAGE] - state #BACKGROUND - app state #BACKGROUND - callee connections: - Mission ID #20 mission name #[#com.huawei.hmsapp.himovie:entry:MainAbility] lockedState #0 - app name [com.huawei.hmsapp.himovie] - main name [MainAbility] - bundle name [com.huawei.hmsapp.himovie] - ability type [PAGE] - state #BACKGROUND - app state #BACKGROUND - callee connections: - Mission ID #21 mission name #[#com.huawei.hmos.calendar:phone:MainAbility] lockedState #0 - app name [com.huawei.hmos.calendar] - main name [MainAbility] - bundle name [com.huawei.hmos.calendar] - ability type [PAGE] - state #BACKGROUND - app state #BACKGROUND - callee connections: - Mission ID #23 mission name #[#com.huawei.hmos.photos:phone_photos:com.huawei.hmos.photos.MainAbility] lockedState #0 - app name [com.huawei.hmos.photos] - main name [com.huawei.hmos.photos.MainAbility] - bundle name [com.huawei.hmos.photos] - ability type [PAGE] - state #BACKGROUND - app state #BACKGROUND - callee connections: - Mission ID #24 mission name #[#com.huawei.hmsapp.music:phone:MainAbility] lockedState #0 - app name [com.huawei.hmsapp.music] - main name [MainAbility] - bundle name [com.huawei.hmsapp.music] - ability type [PAGE] - state #BACKGROUND - app state #BACKGROUND - callee connections: - Mission ID #25 mission name #[#com.taobao.taobao:entry:EntryAbility] lockedState #0 - app name [com.taobao.taobao] - main name [EntryAbility] - bundle name [com.taobao.taobao] - ability type [PAGE] - state #BACKGROUND - app state #BACKGROUND - callee connections: - Mission ID #26 mission name #[#com.tencent.mm:entry:EntryAbility] lockedState #0 - app name [com.tencent.mm] - main name [EntryAbility] - bundle name [com.tencent.mm] - ability type [PAGE] - state #BACKGROUND - app state #BACKGROUND - callee connections: - Mission ID #28 mission name #[#com.taobao.taobao:entry:EntryAbility] lockedState #0 - app name [com.taobao.taobao] - main name [EntryAbility] - bundle name [com.taobao.taobao] - ability type [PAGE] - state #BACKGROUND - app state #BACKGROUND - callee connections: - diff --git a/test/scripts/inputfiles/native_hook_32bit/config_nativehook_dwarf.txt b/test/scripts/inputfiles/native_hook_32bit/config_nativehook_dwarf.txt index 9ed013570..3768b0af2 100644 --- a/test/scripts/inputfiles/native_hook_32bit/config_nativehook_dwarf.txt +++ b/test/scripts/inputfiles/native_hook_32bit/config_nativehook_dwarf.txt @@ -11,7 +11,7 @@ plugin_configs { save_file: false smb_pages: 16384 max_stack_depth: 8 - process_name: "com.huawei.hmos.settings" + process_name: "com.ohos.launcher" string_compressed: true fp_unwind: false blocked: true diff --git a/test/scripts/inputfiles/nativehook/config13.txt b/test/scripts/inputfiles/nativehook/config13.txt index d70995857..0c3967854 100644 --- a/test/scripts/inputfiles/nativehook/config13.txt +++ b/test/scripts/inputfiles/nativehook/config13.txt @@ -12,7 +12,7 @@ filter_size: 4096 smb_pages: 16384 max_stack_depth: 20 - process_name: "com.huawei.hmos.settings" + process_name: "com.ohos.launcher" string_compressed: true fp_unwind: true blocked: true diff --git a/test/scripts/inputfiles/nativehook/config7.txt b/test/scripts/inputfiles/nativehook/config7.txt index 74c87e0ea..af74e7129 100644 --- a/test/scripts/inputfiles/nativehook/config7.txt +++ b/test/scripts/inputfiles/nativehook/config7.txt @@ -12,7 +12,7 @@ filter_size: 4096 smb_pages: 16384 max_stack_depth: 20 - process_name: "com.ohos.sceneboard" + process_name: "com.ohos.launcher" string_compressed: true fp_unwind: true blocked: true diff --git a/test/scripts/inputfiles/nativehook/config9.txt b/test/scripts/inputfiles/nativehook/config9.txt index 78ff07751..9fec91953 100644 --- a/test/scripts/inputfiles/nativehook/config9.txt +++ b/test/scripts/inputfiles/nativehook/config9.txt @@ -12,7 +12,7 @@ filter_size: 4096 smb_pages: 16384 max_stack_depth: 20 - process_name: "com.ohos.sceneboard" + process_name: "com.ohos.launcher" string_compressed: true fp_unwind: true blocked: true diff --git a/test/scripts/inputfiles/xpower_plugin/config_xpower.txt b/test/scripts/inputfiles/xpower_plugin/config_xpower.txt index d240b4fb5..aea700b8d 100644 --- a/test/scripts/inputfiles/xpower_plugin/config_xpower.txt +++ b/test/scripts/inputfiles/xpower_plugin/config_xpower.txt @@ -11,7 +11,7 @@ request_id: 1 sample_interval:2000 is_protobuf_serialize:true config_data { - bundle_name: "com.huawei.hmos.settings" + bundle_name: "com.ohos.launcher" message_type: REAL_BATTERY message_type: APP_STATISTIC message_type: APP_DETAIL diff --git a/test/scripts/testReliability/test_appfreeze.py b/test/scripts/testReliability/test_appfreeze.py index f51bb4eef..b33b03109 100644 --- a/test/scripts/testReliability/test_appfreeze.py +++ b/test/scripts/testReliability/test_appfreeze.py @@ -49,7 +49,7 @@ def check_faultlog(): with open(r'.\..\outputfiles\faultlog.txt', 'r') as file: lines = file.readlines() for line in lines: - if "com.ohos.sceneboard" in line and ("syswarning" not in line): + if "com.ohos.launcher" in line and ("syswarning" not in line): check = False if "render_service" in line: check = False @@ -96,7 +96,7 @@ class TestHiprofilerReliability: subprocess.check_output("hdc shell killall com.example.insight_test_stage") subprocess.check_output("hdc shell param set hiview.memleak.test disable") subprocess.check_output("hdc shell killall hiview") - sceneboard = get_pid("com.ohos.sceneboard") + sceneboard = get_pid("com.ohos.launcher") i = 0 while i < CLICK_TIMES: @@ -114,7 +114,7 @@ class TestHiprofilerReliability: with open(r'.\..\outputfiles\faultlog.txt', 'r') as file: lines = file.readlines() for line in lines: - if "com.ohos.sceneboard" in line and ("syswarning" not in line): + if "com.ohos.launcher" in line and ("syswarning" not in line): check = False if "render_service" in line: check = False @@ -160,8 +160,8 @@ class TestHiprofilerReliability: task_thread.start() i = 0 time.sleep(SLEEP_TWO) - subprocess.check_output("hdc shell killall com.huawei.hmos.settings") - subprocess.check_output("hdc shell aa start -a EntryAbility -b com.huawei.hmos.settings") + subprocess.check_output("hdc shell killall com.ohos.launcher") + subprocess.check_output("hdc shell aa start -a EntryAbility -b com.ohos.launcher") time.sleep(SLEEP_FIVE) while (i < SWIPE_TIMES): subprocess.check_output("hdc shell uinput -T -m 200 1500 200 200") @@ -175,7 +175,7 @@ class TestHiprofilerReliability: with open(r'.\..\outputfiles\faultlog.txt', 'r') as file: lines = file.readlines() for line in lines: - if "com.huawei.hmos.settings" in line: + if "com.ohos.launcher" in line: check = False if "render_service" in line: check = False diff --git a/test/scripts/testReliability/test_crash.py b/test/scripts/testReliability/test_crash.py index 4e4f94e8c..82d5bf7ca 100644 --- a/test/scripts/testReliability/test_crash.py +++ b/test/scripts/testReliability/test_crash.py @@ -37,6 +37,6 @@ class TestHiprofilerReliability: check = False if "com.example.insight_test_stage" in line: check = False - if "com.ohos.sceneboard" in line: + if "com.ohos.launcher" in line: check = False assert check == True \ No newline at end of file diff --git a/test/scripts/testRoot/test_allplugin.py b/test/scripts/testRoot/test_allplugin.py index e23892b6c..b34de3f30 100644 --- a/test/scripts/testRoot/test_allplugin.py +++ b/test/scripts/testRoot/test_allplugin.py @@ -51,7 +51,7 @@ class TestHiprofilerFtrace: with open(r'.\..\outputfiles\test8_result.txt', 'r') as file: lines = file.readlines() for line in lines: - if "com.ohos.sceneboard" in line: + if "com.ohos.launcher" in line: check_sceneboard = True if "cpu5" in line: check_cpu = True diff --git a/test/scripts/testRoot/test_hidump_plugin.py b/test/scripts/testRoot/test_hidump_plugin.py index 5b5d5ea59..08b6d0717 100644 --- a/test/scripts/testRoot/test_hidump_plugin.py +++ b/test/scripts/testRoot/test_hidump_plugin.py @@ -76,11 +76,7 @@ class TestHiprofilerHidumpPlugin: time.sleep(3) subprocess.check_output(f"hdc shell uitest uiInput keyEvent Home", shell=False, text=True, encoding="utf-8") - subprocess.check_output(f"hdc shell aa start -a com.huawei.hmos.settings.MainAbility -b com.huawei.hmos.settings", shell=False, - text=True, encoding="utf-8") time.sleep(5) - subprocess.check_output(f"hdc shell aa start -a MainAbility -b com.huawei.hmos.calendar", shell=False, - text=True, encoding="utf-8") subprocess.check_output(f"hdc shell uinput -T -c 650 2447", shell=False, text=True, encoding="utf-8") time.sleep(1) subprocess.check_output(f"hdc shell uinput -T -c 104 1532", shell=False, text=True, encoding="utf-8") @@ -186,11 +182,7 @@ class TestHiprofilerHidumpPlugin: time.sleep(3) subprocess.check_output(f"hdc shell uitest uiInput keyEvent Home", shell=False, text=True, encoding="utf-8") - subprocess.check_output(f"hdc shell aa start -a com.huawei.hmos.settings.MainAbility -b com.huawei.hmos.settings", shell=False, - text=True, encoding="utf-8") time.sleep(5) - subprocess.check_output(f"hdc shell aa start -a MainAbility -b com.huawei.hmos.calendar", shell=False, - text=True, encoding="utf-8") subprocess.check_output(f"hdc shell uinput -T -c 650 2447", shell=False, text=True, encoding="utf-8") time.sleep(1) subprocess.check_output(f"hdc shell uinput -T -c 104 1532", shell=False, text=True, encoding="utf-8") diff --git a/test/scripts/testRoot/test_memory_plugin.py b/test/scripts/testRoot/test_memory_plugin.py index 976978c3f..510d05f80 100644 --- a/test/scripts/testRoot/test_memory_plugin.py +++ b/test/scripts/testRoot/test_memory_plugin.py @@ -138,12 +138,8 @@ class TestHiprofilerMemoryPlugin: time.sleep(2) pid_text = subprocess.run(f"hdc shell pidof 'com.ohos.settings'", stdout=subprocess.PIPE, text=True, check=True) else: - #打开系统设置的应用 - subprocess.check_output(f"hdc shell aa start -a com.huawei.hmos.settings.MainAbility -b com.huawei.hmos.settings", shell=False, - text=True, encoding="utf-8") - time.sleep(2) #获得该应用的进程PID - pid_text = subprocess.run(f"hdc shell pidof 'com.huawei.hmos.settings'", stdout=subprocess.PIPE, text=True, check=True) + pid_text = subprocess.run(f"hdc shell pidof 'com.ohos.launcher'", stdout=subprocess.PIPE, text=True, check=True) pidinfo = pid_text.stdout #读文本文件,修改对应的pid file_content = Template('request_id: 1 \n' diff --git a/test/scripts/testRoot/test_nativehook.py b/test/scripts/testRoot/test_nativehook.py index ceaf61468..1b401f1ef 100644 --- a/test/scripts/testRoot/test_nativehook.py +++ b/test/scripts/testRoot/test_nativehook.py @@ -384,7 +384,7 @@ def check_nativehook_multipleprocess(statistics, startup, offline, sample_interv with open(r".\..\inputfiles\nativehook\config_multipleprocess_template.txt", 'r') as file: content = file.read() subprocess.check_output("hdc shell power-shell setmode 602") - sceneboard = get_pid("com.ohos.sceneboard") + sceneboard = get_pid("com.ohos.launcher") modified_content = content.replace('sample_interval: 256', 'sample_interval: ' + str(sample_interval)) if malloc_match_interval == 0: modified_content = modified_content.replace('statistics_interval: 10', 'statistics_interval: ' + str(statistics)) @@ -449,7 +449,7 @@ def check_nativehook_multipleprocess(statistics, startup, offline, sample_interv cursor.execute('SELECT * FROM process') result = cursor.fetchall() ipid = 0 - sceneboard = get_pid("com.ohos.sceneboard") + sceneboard = get_pid("com.ohos.launcher") for row in result: if row[PID_INDEX] == int(sceneboard): ipid = row[1] @@ -596,7 +596,7 @@ def check_sa_result(kill_process=False, check_dump_catch=False, multithread=Fals return False if (multithread): - sceneboard_file = get_profiler_test_trace("com.ohos.sceneboard") + sceneboard_file = get_profiler_test_trace("com.ohos.launcher") subprocess.check_output("hdc shell cp /data/log/reliability/resource_leak/memory_leak/" + sceneboard_file + " /data/local/tmp/test.htrace") subprocess.check_output("hdc shell ls -lh /data/local/tmp/ > /data/local/tmp/tmp.txt") subprocess.check_output(f"hdc file recv /data/local/tmp/tmp.txt .\..\outputfiles\ ", text=True, encoding="utf-8") @@ -1124,7 +1124,7 @@ class TestNativehook: with open(r'.\..\outputfiles\faultlog.txt', 'r') as file: lines = file.readlines() for line in lines: - if "com.ohos.sceneboard" in line and ("syswarning" not in line): + if "com.ohos.launcher" in line and ("syswarning" not in line): check = False if "com.example.insight_test_stage" in line: check = False diff --git a/test/scripts/testRoot/test_nativehook_32bit.py b/test/scripts/testRoot/test_nativehook_32bit.py index 6f610b7f0..a07bf1bc9 100644 --- a/test/scripts/testRoot/test_nativehook_32bit.py +++ b/test/scripts/testRoot/test_nativehook_32bit.py @@ -101,7 +101,6 @@ def hidumper_op_nostart_func(ability_name, bundle_name): def nativehook_dwarf_startup(statistics_int, ability_name, bundle_name, op_func): - #获得该应用的进程PID com.huawei.hmos.settings pid_text = subprocess.run(f"hdc shell pidof '{bundle_name}'", stdout=subprocess.PIPE, text=True, check=True) pidinfo = pid_text.stdout if pidinfo.strip() != "": @@ -286,7 +285,7 @@ class TestHiprofilerMemoryPlugin: assert nativehook_dwarf_check_data(False) else: #非统计模式 - nativehook_dwarf_startup(0, "com.huawei.hmos.settings.MainAbility", "com.huawei.hmos.settings", hap_op_func) + nativehook_dwarf_startup(0, "com.ohos.launcher", "com.ohos.launcher", hap_op_func) assert nativehook_dwarf_check_data(False) @pytest.mark.L0 @@ -301,7 +300,7 @@ class TestHiprofilerMemoryPlugin: assert nativehook_dwarf_check_data(True) else: #统计模式 - nativehook_dwarf_startup(10, "com.huawei.hmos.settings.MainAbility", "com.huawei.hmos.settings", hap_op_func) + nativehook_dwarf_startup(10, "com.ohos.launcher", "com.ohos.launcher", hap_op_func) assert nativehook_dwarf_check_data(True) @pytest.mark.L0 diff --git a/test/scripts/testRoot/test_xpower.py b/test/scripts/testRoot/test_xpower.py index d7b7ef2c5..e0a17b1fc 100644 --- a/test/scripts/testRoot/test_xpower.py +++ b/test/scripts/testRoot/test_xpower.py @@ -40,8 +40,6 @@ class TestHiprofilerXPowerPlugin: def test_xpowerplugin_app(self): subprocess.check_output(f"hdc file send ..\\inputfiles\\xpower_plugin\\config_xpower.txt /data/local/tmp/", shell=False, text=True, encoding="utf-8") - subprocess.check_output(f"hdc shell aa start -a com.huawei.hmos.settings.MainAbility -b com.huawei.hmos.settings", shell=False, - text=True, encoding="utf-8") task_thread = threading.Thread(target=task, args=()) task_thread.start() task_thread.join() @@ -85,10 +83,6 @@ class TestHiprofilerXPowerPlugin: text=True, encoding="utf-8") task_thread = threading.Thread(target=task_total, args=()) task_thread.start() - subprocess.check_output(f"hdc shell aa start -a com.huawei.hmos.settings.MainAbility -b com.huawei.hmos.settings", shell=False, - text=True, encoding="utf-8") - subprocess.check_output(f"hdc shell aa start -a com.huawei.hmos.photos.MainAbility -b com.huawei.hmos.photos", shell=False, - text=True, encoding="utf-8") task_thread.join() subprocess.check_output(f"hdc file recv /data/local/tmp/test_xpower_total.htrace ../outputfiles/ ", shell=False, text=True, encoding="utf-8") -- Gitee From ea73957b7f4f307e8b465243cb95563a9514df81 Mon Sep 17 00:00:00 2001 From: ganchuantao Date: Wed, 6 Aug 2025 02:50:54 +0000 Subject: [PATCH 16/27] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=97=A0=E7=94=A8?= =?UTF-8?q?=E7=9A=84=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: ganchuantao --- device/services/profiler_service/src/trace_file_writer.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/device/services/profiler_service/src/trace_file_writer.cpp b/device/services/profiler_service/src/trace_file_writer.cpp index 00b714756..9094d3590 100644 --- a/device/services/profiler_service/src/trace_file_writer.cpp +++ b/device/services/profiler_service/src/trace_file_writer.cpp @@ -540,7 +540,6 @@ bool TraceFileWriter::GetMemory(uint32_t size, uint8_t** memory, uint32_t* offse { if ((fileWriteLength_ + PIECE_HEAD_LEN + messageWriteOffset_ + size) >= fileLength_) { if ((fileLength_ + DEFULT_PAGES * pageSize_) > GB_TO_BYTE) { - PROFILER_LOG_INFO(LOG_CORE, "The file is too large :file length file(%zu)", fileLength_); return false; } -- Gitee From 256d5a1edb283e90e97078d58559516e35054004 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=89=9B=E5=9B=BD=E4=BA=AE?= Date: Wed, 6 Aug 2025 15:27:26 +0800 Subject: [PATCH 17/27] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=A9=AC=E8=BE=BE?= =?UTF-8?q?=E5=85=AC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 牛国亮 --- .../client_command/include/sp_server_socket.h | 1 + .../client/client_command/sp_server_socket.cpp | 14 ++++++++++++++ .../client/client_command/sp_thread_socket.cpp | 6 +++++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/host/smartperf/client/client_command/include/sp_server_socket.h b/host/smartperf/client/client_command/include/sp_server_socket.h index cd680c2ff..4b0929579 100644 --- a/host/smartperf/client/client_command/include/sp_server_socket.h +++ b/host/smartperf/client/client_command/include/sp_server_socket.h @@ -39,6 +39,7 @@ public: // 关闭 void Close(); std::string RecvBuf() const; + bool IsValid(); private: int sock = -1; diff --git a/host/smartperf/client/client_command/sp_server_socket.cpp b/host/smartperf/client/client_command/sp_server_socket.cpp index 539ebb15e..2abd844f5 100644 --- a/host/smartperf/client/client_command/sp_server_socket.cpp +++ b/host/smartperf/client/client_command/sp_server_socket.cpp @@ -135,5 +135,19 @@ std::string SpServerSocket::RecvBuf() const std::string recvBuf = rbuf; return recvBuf; } + +bool SpServerSocket::IsValid() +{ + if (sock < 0) { + LOGE("SpServerSocket::Init Socket Create Failed"); + return false; + } + int error = 0; + socklen_t len = sizeof(error); + if (gersocket(sock, SOL_SOCKER, SO_ERROR, &error, &len) < 0) { + return false; + } + return (error == 0); +} } } diff --git a/host/smartperf/client/client_command/sp_thread_socket.cpp b/host/smartperf/client/client_command/sp_thread_socket.cpp index 7d49de452..eaa1d4158 100644 --- a/host/smartperf/client/client_command/sp_thread_socket.cpp +++ b/host/smartperf/client/client_command/sp_thread_socket.cpp @@ -465,7 +465,11 @@ void SpThreadSocket::UdpStartInitFunc(const std::string& recvBuf, SpServerSocket taskMgr_->WriteToCSV(); } taskMgr_ = std::make_shared(true); - auto lambdaTask = [&spSocket](const std::string &data) { spSocket.Sendto(data); }; + auto lambdaTask = [spSocket = std::ref(spSocket)](const std::string &data) mutable { + if (spSocket.get().IsValid()) { + spSocket.get().Sendto(data); + } + }; taskMgr_->SetIPCCallback(lambdaTask); taskMgr_->AddTask(recvBuf); spTask.SetAppCmd(recvBuf); -- Gitee From 055edd6172e2c42b8c1e131e67a54b328ad98eb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=89=9B=E5=9B=BD=E4=BA=AE?= Date: Wed, 6 Aug 2025 16:53:53 +0800 Subject: [PATCH 18/27] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=BC=96=E8=AF=91?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 牛国亮 --- host/smartperf/client/client_command/RAM.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/host/smartperf/client/client_command/RAM.cpp b/host/smartperf/client/client_command/RAM.cpp index 70d898e34..97028ae65 100644 --- a/host/smartperf/client/client_command/RAM.cpp +++ b/host/smartperf/client/client_command/RAM.cpp @@ -88,10 +88,8 @@ std::map RAM::ItemData() } else { procRamInfomation = ProcMemNaInfo(); } - result = {}; result.merge(procRamInfomation); } else if (!packageName.empty() && processId.empty()) { - result = {}; result.merge(RAM::ProcMemNaInfo()); } LOGI("RAM:ItemData map size(%u)", result.size()); -- Gitee From e8911cb9e77fd7890bd9c3fa984885adeb6b2505 Mon Sep 17 00:00:00 2001 From: ganchuantao Date: Thu, 7 Aug 2025 09:21:19 +0800 Subject: [PATCH 19/27] =?UTF-8?q?fix=EF=BC=9A=E6=94=AF=E6=8C=81=E6=99=BA?= =?UTF-8?q?=E8=83=BD=E8=A1=A8ccm=E5=AE=9A=E5=88=B6=E5=8C=96=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=20Signed-off-by:ganchuantao=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: ganchuantao --- device/ohos_test.xml | 2 + device/plugins/native_daemon/BUILD.gn | 1 + .../native_daemon/include/hook_manager.h | 1 + .../plugins/native_daemon/include/utilities.h | 2 + .../native_memory_profiler_sa_service.h | 2 + .../src/native_memory_profiler_sa_service.cpp | 6 ++- .../native_memory_profiler_sa/test/BUILD.gn | 1 + .../native_daemon/src/hook_manager.cpp | 8 ++-- .../plugins/native_daemon/src/utilities.cpp | 28 +++++++++++ device/plugins/native_daemon/test/BUILD.gn | 1 + .../unittest/common/native/utilities_test.cpp | 48 +++++++++++++++++++ .../resource/testdata/hiprofiler_cfg.json | 3 ++ .../resource/testdata/hiprofiler_cfg2.json | 4 ++ device/plugins/native_hook/BUILD.gn | 1 + device/plugins/native_hook/test/BUILD.gn | 1 + 15 files changed, 104 insertions(+), 5 deletions(-) create mode 100644 device/plugins/native_daemon/test/unittest/resource/testdata/hiprofiler_cfg.json create mode 100644 device/plugins/native_daemon/test/unittest/resource/testdata/hiprofiler_cfg2.json diff --git a/device/ohos_test.xml b/device/ohos_test.xml index 254d8b20e..c8cca99d3 100644 --- a/device/ohos_test.xml +++ b/device/ohos_test.xml @@ -117,6 +117,8 @@