From 3115d679ce46bced6c74804d1a5fe45e3cb9414d Mon Sep 17 00:00:00 2001 From: zyxzyx Date: Mon, 22 Apr 2024 10:33:13 +0800 Subject: [PATCH 01/27] remove sharememblock and send end msg Signed-off-by: zyxzyx --- .../native_daemon/include/hook_common.h | 6 ++ .../native_daemon/include/hook_manager.h | 5 +- .../native_daemon/include/stack_preprocess.h | 4 ++ .../src/native_memory_profiler_sa_service.cpp | 19 +++--- .../native_daemon/src/hook_manager.cpp | 58 ++++++++----------- .../native_daemon/src/hook_service.cpp | 6 +- .../native_daemon/src/stack_preprocess.cpp | 8 +-- .../native_hook/include/hook_socket_client.h | 8 ++- .../plugins/native_hook/src/hook_client.cpp | 8 ++- .../native_hook/src/hook_socket_client.cpp | 42 ++++++++++---- .../test/unittest/hook_socket_client_test.cpp | 1 - 11 files changed, 92 insertions(+), 73 deletions(-) diff --git a/device/plugins/native_daemon/include/hook_common.h b/device/plugins/native_daemon/include/hook_common.h index 1a46f9860..6acc62d74 100644 --- a/device/plugins/native_daemon/include/hook_common.h +++ b/device/plugins/native_daemon/include/hook_common.h @@ -72,6 +72,8 @@ enum { THREAD_NAME_MSG, PR_SET_VMA_MSG, JS_STACK_MSG, + NMD_MSG, + END_MSG, }; struct alignas(8) MmapFileRawData { // 8 is 8 bit @@ -145,6 +147,8 @@ struct alignas(8) ClientConfig { // 8 is 8 bit memtraceEnable = false; responseLibraryMode = false; freeEventOnlyAddrEnable = false; + printNmd = false; + nmdType = -1; arktsConfig.maxJsStackDepth = 0; arktsConfig.jsStackReport = false; arktsConfig.jsFpunwind = false; @@ -181,6 +185,8 @@ struct alignas(8) ClientConfig { // 8 is 8 bit bool memtraceEnable = false; bool responseLibraryMode = false; bool freeEventOnlyAddrEnable = false; + bool printNmd = false; + int nmdType = -1; ArkTsClientConfig arktsConfig = {0}; }; #endif // HOOK_COMMON_H \ No newline at end of file diff --git a/device/plugins/native_daemon/include/hook_manager.h b/device/plugins/native_daemon/include/hook_manager.h index 9a670c093..52fbf2399 100644 --- a/device/plugins/native_daemon/include/hook_manager.h +++ b/device/plugins/native_daemon/include/hook_manager.h @@ -100,7 +100,7 @@ public: int32_t CreatePluginSession(); void RegisterWriter(const std::shared_ptr writer); void WriteHookConfig(); - std::vector GetFds(int32_t pid, const std::string& name); + std::pair GetFds(int32_t pid, const std::string& name); inline void SetSaServiceConfig(bool saFlag, bool isProtobufSerialize) { isSaService_ = saFlag; @@ -111,7 +111,7 @@ public: { return noDataQueue_; } - bool PrintStat(uint32_t fd, int type); + bool PrintStat(uint32_t fd, const char* result); void SetPid(int pid) { pid_ = pid; @@ -148,7 +148,6 @@ private: std::shared_ptr writer_{nullptr}; constexpr static uint32_t MAX_BUFFER_SIZE = 100 * 1024 * 1024; uint64_t shareMemorySize_{MAX_BUFFER_SIZE}; - std::shared_ptr shareMemoryNmd_ = nullptr; NmdParam nmdParamInfo_; }; } diff --git a/device/plugins/native_daemon/include/stack_preprocess.h b/device/plugins/native_daemon/include/stack_preprocess.h index ffb65f01d..747375d0d 100644 --- a/device/plugins/native_daemon/include/stack_preprocess.h +++ b/device/plugins/native_daemon/include/stack_preprocess.h @@ -62,6 +62,10 @@ public: { pid_ = pid; } + inline void SetStopFlag(bool flag) + { + isStopTakeData_ = flag; + } void SaveMemTag(uint32_t tagId, const std::string& tagName); bool GetMemTag(uint32_t tagId, std::string& tagName); void SaveJsRawStack(uint64_t jsChainId, const char* jsRawStack); 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 e60c96ff1..b88daf422 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 @@ -143,13 +143,6 @@ void NativeMemoryProfilerSaService::StopHook(uint32_t pid, std::string name, boo return; } - if (config->hookMgr->GetPid() > 0) { - std::lock_guard nmdGuard(nmdMtx_); - if (nmdPidType_.find(config->hookMgr->GetPid()) != nmdPidType_.end()) { - config->hookMgr->SetNmdInfo(nmdPidType_[config->hookMgr->GetPid()]); - } - } - config->hookMgr->StopPluginSession({}); config->hookMgr->DestroyPluginSession({}); if (timeout) { @@ -207,6 +200,12 @@ int32_t NativeMemoryProfilerSaService::StartHook(std::shared_ptrRegisterWriter(writeFile); hook->SetHookConfig(config); hook->SetSaServiceConfig(true, false); + if (config->pid_ > 0) { + std::lock_guard nmdGuard(nmdMtx_); + if (nmdPidType_.find(config->pid_) != nmdPidType_.end()) { + hook->SetNmdInfo(nmdPidType_[config->pid_]); + } + } if (hook->CreatePluginSession() != RET_OK) { return RET_ERR; } @@ -338,11 +337,8 @@ bool NativeMemoryProfilerSaService::ProtocolProc(SocketContext &context, uint32_ std::lock_guard guard(mtx_); if (auto iter = pidCtx_.find(peerConfig); iter != pidCtx_.end()) { - std::vector vec = iter->second->hookMgr->GetFds(peerConfig, bundleName); + auto [eventFd, smbFd] = iter->second->hookMgr->GetFds(peerConfig, bundleName); iter->second->hookMgr->SetPid(peerConfig); - auto eventFd = vec[0]; - auto smbFd = vec[1]; - auto nmdFd = vec[2]; if (eventFd == smbFd) { PROFILER_LOG_ERROR(LOG_CORE, "Get eventFd and smbFd failed!, name: %s, pid: %d", bundleName.c_str(), peerConfig); @@ -359,7 +355,6 @@ bool NativeMemoryProfilerSaService::ProtocolProc(SocketContext &context, uint32_ context.SendHookConfig(reinterpret_cast(&clientConfig), sizeof(clientConfig)); context.SendFileDescriptor(smbFd); context.SendFileDescriptor(eventFd); - context.SendFileDescriptor(nmdFd); iter->second->hookMgr->ResetStartupParam(); } else { PROFILER_LOG_ERROR(LOG_CORE, "ProtocolProc: send config failed"); diff --git a/device/plugins/native_daemon/src/hook_manager.cpp b/device/plugins/native_daemon/src/hook_manager.cpp index a5f710aec..7012a623f 100644 --- a/device/plugins/native_daemon/src/hook_manager.cpp +++ b/device/plugins/native_daemon/src/hook_manager.cpp @@ -47,9 +47,6 @@ constexpr int SIGNAL_STOP_HOOK = 37; const std::string VERSION = "1.02"; constexpr int32_t RESPONSE_MAX_PID_COUNT = 8; constexpr int32_t MAX_PID_COUNT = 4; -constexpr uint32_t SHARED_MEMORY_SIZE = 307200; -constexpr uint32_t WAIT_TIME = 100; -constexpr uint32_t MAX_WAIT_TIME = 500; } bool HookManager::CheckProcess() @@ -215,6 +212,8 @@ void HookManager::GetClientConfig(ClientConfig& clientConfig) clientConfig.sampleInterval = hookConfig_.sample_interval(); clientConfig.responseLibraryMode = hookConfig_.response_library_mode(); clientConfig.arktsConfig.jsStackReport = hookConfig_.js_stack_report(); + clientConfig.printNmd = printMallocNmd_; + clientConfig.nmdType = nmdParamInfo_.type; // -1 is save '\0' int ret = memcpy_s(clientConfig.arktsConfig.filterNapiName, sizeof(clientConfig.arktsConfig.filterNapiName) - 1, hookConfig_.filter_napi_name().c_str(), hookConfig_.filter_napi_name().size()); @@ -409,6 +408,15 @@ void HookManager::ReadShareMemory(const std::shared_ptr& hookCtx "memcpy_s raw data failed!"); rawStack->stackConext = reinterpret_cast(rawStack->baseStackData.get()); + + if (rawStack->stackConext->type == NMD_MSG && printMallocNmd_) { + rawStack->data = rawStack->baseStackData.get() + sizeof(BaseStackRawData); + PrintStat(nmdParamInfo_.fd, reinterpret_cast(rawStack->data)); + return true; + } else if (rawStack->stackConext->type == END_MSG) { + hookCtx->stackPreprocess->SetStopFlag(true); + return true; + } rawStack->data = rawStack->baseStackData.get() + sizeof(BaseStackRawData); rawStack->reportFlag = true; if (rawStack->stackConext->type == MEMORY_TAG || rawStack->stackConext->type == THREAD_NAME_MSG || @@ -444,6 +452,13 @@ void HookManager::ReadShareMemory(const std::shared_ptr& hookCtx hookCtx->stackPreprocess->SaveJsRawStack(rawStack->stackConext->jsChainId, reinterpret_cast(rawStack->data)); continue; + } else if (rawStack->stackConext->type == END_MSG) { + if (!hookCtx->stackData->PutRawStack(nullptr, false)) { + break; + } + continue; + } else if (rawStack->stackConext->type == NMD_MSG) { + continue; } if (!hookCtx->stackData->PutRawStack(rawStack, hookCtx->isRecordAccurately)) { break; @@ -523,21 +538,6 @@ bool HookManager::StopPluginSession(const std::vector& pluginIds) item->stackData->Close(); } } - - if (printMallocNmd_) { - if (nmdParamInfo_.fd == 0) { - return false; - } - if (nmdParamInfo_.type == 0) { - PrintStat(nmdParamInfo_.fd, 0); - } else if (nmdParamInfo_.type == 1) { - int waitTime = 0; - while ((!PrintStat(nmdParamInfo_.fd, 1)) && waitTime < MAX_WAIT_TIME) { - std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_TIME)); - waitTime += WAIT_TIME; - } - } - } return true; } @@ -681,33 +681,23 @@ void HookManager::WriteHookConfig() std::vector HookManager::GetFds(int32_t pid, const std::string& name) { - shareMemoryNmd_ = ShareMemoryAllocator::GetInstance().CreateMemoryBlockLocal("nmd " + std::to_string(pid), - SHARED_MEMORY_SIZE); for (const auto& item : hookCtx_) { if (item->pid == pid || item->processName == name) { if (item->pid == -1) { item->pid = pid; } item->stackPreprocess->SetPid(pid); - return {item->eventNotifier->GetFd(), item->shareMemoryBlock->GetfileDescriptor(), - shareMemoryNmd_->GetfileDescriptor()}; + return {item->eventNotifier->GetFd(), item->shareMemoryBlock->GetfileDescriptor()}; } } - return {-1, -1, -1}; + return {-1, -1}; } -bool HookManager::PrintStat(uint32_t fd, int type) +bool HookManager::PrintStat(uint32_t fd, const char* result) { - CHECK_NOTNULL(shareMemoryNmd_, false, "PrintStat failed, sharedMemoryNmd empty"); - bool ret = shareMemoryNmd_->TakeData( - [&](const int8_t data[], uint32_t size) -> bool { - const char* result = reinterpret_cast(data); - lseek(fd, 0, SEEK_END); - (void)write(fd, result, strlen(result)); - return true; - } - ); - return ret; + lseek(fd, 0, SEEK_END); + (void)write(fd, result, strlen(result)); + return true; } void HookManager::SetNmdInfo(std::pair info) diff --git a/device/plugins/native_daemon/src/hook_service.cpp b/device/plugins/native_daemon/src/hook_service.cpp index db951ad62..9cfe1589d 100644 --- a/device/plugins/native_daemon/src/hook_service.cpp +++ b/device/plugins/native_daemon/src/hook_service.cpp @@ -88,10 +88,7 @@ bool HookService::ProtocolProc(SocketContext &context, uint32_t pnum, const int8 return false; } firstProcess = false; - std::vector vec = hookMgr_->GetFds(peerConfig, procName); - auto eventFd = vec[0]; - auto smbFd = vec[1]; - auto nmdFd = vec[2]; + auto [eventFd, smbFd] = hookMgr_->GetFds(peerConfig, procName); if (eventFd == smbFd) { PROFILER_LOG_ERROR(LOG_CORE, "Get eventFd and smbFd failed!, name: %s, pid: %d", procName.c_str(), peerConfig); return false; @@ -102,7 +99,6 @@ bool HookService::ProtocolProc(SocketContext &context, uint32_t pnum, const int8 context.SendHookConfig(reinterpret_cast(&clientConfig_), sizeof(clientConfig_)); context.SendFileDescriptor(smbFd); context.SendFileDescriptor(eventFd); - context.SendFileDescriptor(nmdFd); hookMgr_->ResetStartupParam(); return true; } diff --git a/device/plugins/native_daemon/src/stack_preprocess.cpp b/device/plugins/native_daemon/src/stack_preprocess.cpp index fb87e9e43..f49899a80 100644 --- a/device/plugins/native_daemon/src/stack_preprocess.cpp +++ b/device/plugins/native_daemon/src/stack_preprocess.cpp @@ -167,14 +167,11 @@ bool StackPreprocess::StopTakeResults() { PROFILER_LOG_INFO(LOG_CORE, "start StopTakeResults"); if (!dataRepeater_) { - isStopTakeData_ = true; return true; } CHECK_NOTNULL(dataRepeater_, false, "data repeater null"); CHECK_TRUE(thread_.get_id() != std::thread::id(), false, "thread invalid"); - isStopTakeData_ = true; - dataRepeater_->PutRawStack(nullptr, false); PROFILER_LOG_INFO(LOG_CORE, "StopTakeResults Wait thread join"); if (thread_.joinable()) { @@ -331,9 +328,12 @@ void StackPreprocess::TakeResults() PROFILER_LOG_INFO(LOG_CORE, "TakeResults thread %d, start!", gettid()); while (1) { RawStackPtr batchRawStack[MAX_BATCH_CNT] = {nullptr}; + if (isStopTakeData_) { + break; + } auto result = dataRepeater_->TakeRawData(hookConfig_.malloc_free_matching_interval(), hookDataClockId_, MAX_BATCH_CNT, batchRawStack); - if (!result || isStopTakeData_) { + if (!result) { break; } for (unsigned int i = 0; i < MAX_BATCH_CNT; i++) { diff --git a/device/plugins/native_hook/include/hook_socket_client.h b/device/plugins/native_hook/include/hook_socket_client.h index a01576683..78f46f1cb 100644 --- a/device/plugins/native_hook/include/hook_socket_client.h +++ b/device/plugins/native_hook/include/hook_socket_client.h @@ -44,17 +44,21 @@ public: void DisableHook(); bool PeerIsConnected(); bool SendNmdInfo(); + bool SendEndMsg(); + int GetNmdType() + { + return nmdType_; + } private: std::shared_ptr unixSocketClient_; int smbFd_; int eventFd_; int pid_; - int nmdFd_; + int nmdType_ = -1; ClientConfig *config_ = nullptr; Sampling *sampler_ = nullptr; std::shared_ptr stackWriter_; - std::shared_ptr shareMemoryBlockNmd_; void (*disableHookCallback_)(){nullptr}; }; diff --git a/device/plugins/native_hook/src/hook_client.cpp b/device/plugins/native_hook/src/hook_client.cpp index 9366acff5..823829839 100644 --- a/device/plugins/native_hook/src/hook_client.cpp +++ b/device/plugins/native_hook/src/hook_client.cpp @@ -284,8 +284,14 @@ void* ohos_release_on_end(void*) bool ohos_malloc_hook_on_end(void) { if (g_hookClient != nullptr) { - g_hookClient->SendNmdInfo(); + if (g_hookClient->GetNmdType() == 1) { + PROFILER_LOG_INFO(LOG_CORE, "sending nmd info after hook"); + g_hookClient->SendNmdInfo(); + } + g_hookClient->SendEndMsg(); g_hookClient->Flush(); + } else { + PROFILER_LOG_ERROR(LOG_CORE, "ohos_malloc_hook_on_end, g_hookClient is nullptr"); } pthread_t threadEnd; if (pthread_create(&threadEnd, nullptr, ohos_release_on_end, nullptr)) { diff --git a/device/plugins/native_hook/src/hook_socket_client.cpp b/device/plugins/native_hook/src/hook_socket_client.cpp index 606063c75..f3431eeb0 100644 --- a/device/plugins/native_hook/src/hook_socket_client.cpp +++ b/device/plugins/native_hook/src/hook_socket_client.cpp @@ -32,10 +32,8 @@ namespace { constexpr int FLUSH_FLAG = 20; std::atomic g_flushCount = 0; -std::atomic g_memIndex = 0; std::atomic g_disableHook = false; constexpr uint32_t MEMCHECK_DETAILINFO_MAXSIZE = 102400; -constexpr uint32_t SHARED_MEMORY_SIZE = 307200; struct OptArg { int pos; @@ -127,17 +125,16 @@ bool HookSocketClient::ProtocolProc(SocketContext &context, uint32_t pnum, const PROFILER_LOG_INFO(LOG_CORE, "%s sample interval %" PRIu64 "", __func__, sampler_->GetSampleInterval()); smbFd_ = context.ReceiveFileDiscriptor(); eventFd_ = context.ReceiveFileDiscriptor(); - nmdFd_ = context.ReceiveFileDiscriptor(); std::string smbName = "hooknativesmb_" + std::to_string(pid_); stackWriter_ = std::make_shared(smbName, config_->shareMemorySize, smbFd_, eventFd_, config_->isBlocked); - shareMemoryBlockNmd_ = - ShareMemoryAllocator::GetInstance().CreateMemoryBlockRemote("nmd" + std::to_string(g_memIndex), - SHARED_MEMORY_SIZE, nmdFd_); - ++g_memIndex; struct mallinfo2 mi = mallinfo2(); COMMON::PrintMallinfoLog("stackWriter init(byte) => ", mi); - SendNmdInfo(); + nmdType_ = config_->nmdType; + if (nmdType_ == 0) { + PROFILER_LOG_INFO(LOG_CORE, "sending nmd info before hook"); + SendNmdInfo(); + } return true; } @@ -206,12 +203,35 @@ bool HookSocketClient::PeerIsConnected() bool HookSocketClient::SendNmdInfo() { - CHECK_TRUE(nmdFd_ != -1, false, "HookSocketClient::SendNmdInfo failed, invalid nmdFd_"); - CHECK_NOTNULL(shareMemoryBlockNmd_, false, "HookSocketClient::SendNmdInfo failed, sharedMemoryBlock error"); + if (!config_->printNmd) { + return false; + } void* nmdBuf = malloc(MEMCHECK_DETAILINFO_MAXSIZE); CHECK_NOTNULL(nmdBuf, false, "HookSocketClient::SendNmdInfo failed, nmdBuf malloc failed"); struct OptArg opt = {0, reinterpret_cast(nmdBuf) }; malloc_stats_print(NmdWriteStat, &opt, "a"); - shareMemoryBlockNmd_->PutRawTimeout(reinterpret_cast(opt.buf), strlen(opt.buf) + 1); + StackRawData radata = {{{{0}}}}; + rawdata.type = NMD_MSG; + if (stackWriter_) { + bool ret = stackWriter_->WriteWithPayloadTimeout(&rawdata, sizeof(BaseStackRawData), + reinterpret_cast(opt.buf), strlen(opt.buf) + 1, + std::bind(&HookSocketClient::PeerIsConnected, this); + PROFILER_LOG_INFO(LOG_CORE, "SendEndMsg ret val: %d", ret); + } else { + PROFILER_LOG_ERROR(LOG_CORE, "SendEndMsg stackWriter_ is nullptr"); + } + return true; +} + +bool HookSocketClient::SendEndMsg() +{ + StackRawData radata = {{{{0}}}}; + rawdata.type = END_MSG; + if (stackWriter_) { + bool ret = stackWriter_->WriteTimeout(&rawdata, sizeof(BaseStackRawData)); + PROFILER_LOG_INFO(LOG_CORE, "SendEndMsg ret val: %d", ret); + } else { + PROFILER_LOG_ERROR(LOG_CORE, "SendEndMsg stackWriter_ is nullptr"); + } return true; } \ No newline at end of file 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 89141bed0..f57db35f3 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 @@ -149,7 +149,6 @@ HWTEST_F(HookSocketClientTest, SendNmdInfo, TestSize.Level1) if (memcpy_s(buffer.get(), metaSize, &ts, sizeof(ts)) != EOK) { PROFILER_LOG_ERROR(LOG_CORE, "memcpy_s ts failed"); } - ASSERT_EQ(hookClient.nmdFd_, -1); ASSERT_FALSE(hookClient.SendNmdInfo()); } } // namespace From e4db620e1a711480db5d43e256602baaa9391eab Mon Sep 17 00:00:00 2001 From: zyxzyx Date: Wed, 8 May 2024 17:26:11 +0800 Subject: [PATCH 02/27] add scheduled task Signed-off-by: zyxzyx --- .../native_daemon/include/hook_manager.h | 1 - .../native_daemon/include/stack_preprocess.h | 12 ++++--- .../native_daemon/src/hook_manager.cpp | 16 ++++----- .../native_daemon/src/stack_preprocess.cpp | 33 +++++++++++++++++++ 4 files changed, 48 insertions(+), 14 deletions(-) diff --git a/device/plugins/native_daemon/include/hook_manager.h b/device/plugins/native_daemon/include/hook_manager.h index 52fbf2399..f5241ea5d 100644 --- a/device/plugins/native_daemon/include/hook_manager.h +++ b/device/plugins/native_daemon/include/hook_manager.h @@ -111,7 +111,6 @@ public: { return noDataQueue_; } - bool PrintStat(uint32_t fd, const char* result); void SetPid(int pid) { pid_ = pid; diff --git a/device/plugins/native_daemon/include/stack_preprocess.h b/device/plugins/native_daemon/include/stack_preprocess.h index 74e7d8863..ea0bcc719 100644 --- a/device/plugins/native_daemon/include/stack_preprocess.h +++ b/device/plugins/native_daemon/include/stack_preprocess.h @@ -33,6 +33,7 @@ #include "native_hook_result.pb.h" #include "native_hook_result.pbencoder.h" #include "safe_map.h" +#include "schedule_task_manager.h" using WriterStructPtr = std::unique_ptr::pointer; class StackPreprocess { @@ -58,14 +59,11 @@ public: bool StopTakeResults(); bool FlushRecordStatistics(); void FlushRecordApplyAndReleaseMatchData(); + void ForceStop(); inline void SetPid(int32_t pid) { pid_ = pid; } - inline void SetStopFlag(bool flag) - { - isStopTakeData_ = flag; - } void SaveMemTag(uint32_t tagId, const std::string& tagName); bool GetMemTag(uint32_t tagId, std::string& tagName); void SaveJsRawStack(uint64_t jsChainId, const char* jsRawStack); @@ -73,6 +71,10 @@ public: void ReportBasicData(); void WriteHookConfig(); void TakeResultsFromShmem(const std::shared_ptr&, const std::shared_ptr&); + void SetNmdFd(uint32_t fd) + { + nmdFd_ = fd; + } void SetFlushSize(uint64_t size) { double tenth = static_cast(size) / 10.0; @@ -231,6 +233,8 @@ private: std::vector prctlPeriodTags_; // applyAndReleaseMatchInterval mode used std::vector fpJsCallStacks_; std::atomic napiIndex_{1}; + ScheduleTaskManager scheduleTaskManager_; + uint32_t nmdFd_ = 0; }; #endif // STACK_PREPROCESS_H \ No newline at end of file diff --git a/device/plugins/native_daemon/src/hook_manager.cpp b/device/plugins/native_daemon/src/hook_manager.cpp index 3d6d8c7de..faf3756de 100644 --- a/device/plugins/native_daemon/src/hook_manager.cpp +++ b/device/plugins/native_daemon/src/hook_manager.cpp @@ -268,6 +268,7 @@ bool HookManager::HandleHookContext(const std::shared_ptr& ctx) ctx->stackPreprocess = std::make_shared(nullptr, hookConfig_, pluginDataClockId, fpHookData_, isHookStandalone_, isSaService_, isProtobufSerialize_); ctx->stackPreprocess->SetFlushSize(shareMemorySize_); + ctx->stackPreprocess->SetNmdFd(nmdParamInfo_.fd); ctx->eventPoller->AddFileDescriptor( ctx->eventNotifier->GetFd(), std::bind(&StackPreprocess::TakeResultsFromShmem, ctx->stackPreprocess, @@ -411,10 +412,11 @@ void HookManager::ReadShareMemory(const std::shared_ptr& hookCtx if (rawStack->stackConext->type == NMD_MSG && printMallocNmd_) { rawStack->data = rawStack->baseStackData.get() + sizeof(BaseStackRawData); - PrintStat(nmdParamInfo_.fd, reinterpret_cast(rawStack->data)); + const char* nmdResult = reinterpret_cast(rawStack->data); + lseek(nmdParamInfo_.fd, 0, SEEK_END); + (void)write(nmdParamInfo_.fd, nmdResult, strlen(nmdResult)); return true; } else if (rawStack->stackConext->type == END_MSG) { - hookCtx->stackPreprocess->SetStopFlag(true); return true; } rawStack->data = rawStack->baseStackData.get() + sizeof(BaseStackRawData); @@ -453,6 +455,9 @@ void HookManager::ReadShareMemory(const std::shared_ptr& hookCtx reinterpret_cast(rawStack->data)); continue; } else if (rawStack->stackConext->type == END_MSG) { + if (!hookCtx->stackData->PutRawStack(rawStack, hookCtx->isRecordAccurately)) { + break; + } if (!hookCtx->stackData->PutRawStack(nullptr, false)) { break; } @@ -693,13 +698,6 @@ std::vector HookManager::GetFds(int32_t pid, const std::string& name) return {-1, -1}; } -bool HookManager::PrintStat(uint32_t fd, const char* result) -{ - lseek(fd, 0, SEEK_END); - (void)write(fd, result, strlen(result)); - return true; -} - void HookManager::SetNmdInfo(std::pair info) { printMallocNmd_ = true; diff --git a/device/plugins/native_daemon/src/stack_preprocess.cpp b/device/plugins/native_daemon/src/stack_preprocess.cpp index 00f4aa87b..0689dcbbd 100644 --- a/device/plugins/native_daemon/src/stack_preprocess.cpp +++ b/device/plugins/native_daemon/src/stack_preprocess.cpp @@ -40,6 +40,8 @@ constexpr static uint32_t LG_TINY_MAXCLASS = 3; constexpr static uint32_t MAX_MATCH_CNT = 1000; constexpr static uint32_t MAX_MATCH_INTERVAL = 3600; constexpr static uint32_t LOG_PRINT_TIMES = 10000; +constexpr static uint32_t WAIT_STOP_TIME = 5000; +constexpr static uint32_t WAIT_TIME_ONCE = 10; constexpr static uint32_t MAX_BATCH_CNT = 5; constexpr static uint32_t RIGHT_MOVE_1 = 1; constexpr static uint32_t RIGHT_MOVE_2 = 2; @@ -168,7 +170,16 @@ bool StackPreprocess::StartTakeResults() bool StackPreprocess::StopTakeResults() { PROFILER_LOG_INFO(LOG_CORE, "start StopTakeResults"); + int32_t timerFd = scheduleTaskManager_.ScheduleTask( + std::bind(&StackPreprocess::ForceStop, this), WAIT_STOP_TIME, true, false); + if (timeFd == -1) { + PROFILER_LOG_ERROR(LOG_CORE, "StopTakeResults ScheduleTask failed!"); + return false; + } if (!dataRepeater_) { + while (!isStopTakeData_) { + std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_TIME_ONCE)); + } return true; } CHECK_NOTNULL(dataRepeater_, false, "data repeater null"); @@ -234,6 +245,14 @@ bool StackPreprocess::HandleNoStackEvent(RawStackPtr& rawData) return true; } +void StackPreprocess::ForceStop() +{ + isStopTakeData_ = true; + if (dataRepeater_ != nullptr) { + dataRepeater_->Close(); + } +} + void StackPreprocess::TakeResultsFromShmem(const std::shared_ptr& eventNotifier, const std::shared_ptr& shareMemoryBlock) { @@ -280,6 +299,14 @@ void StackPreprocess::TakeResultsFromShmem(const std::shared_ptr& } else if (rawData->stackConext->type == MUNMAP_MSG) { std::lock_guard guard(mtx_); runtime_instance->RemoveMaps(reinterpret_cast(rawData->stackConext->addr)); + } else if (rawData->stackConext->type == NMD_MSG) { + const char* nmdResult = reinterpret_cast(rawData->data); + lseek(nmdFd_, 0, SEEK_END); + (void)write(nmdFd_, nmdResult, strlen(nmdResult)); + return true; + } else if (rawData->stackConext->type == END_MSG) { + isStopTakeData_ = true; + return true; } { std::lock_guard guard(mtx_); @@ -343,6 +370,12 @@ void StackPreprocess::TakeResults() if (!rawData || isStopTakeData_) { break; } + if (rawData->stackConext->type == NMD_MSG) { + continue; + } else if (rawData->stackConext->type == END_MSG) { + isStopTakeData_ = true; + break; + } #ifdef PERFORMANCE_DEBUG struct timespec start = {}; clock_gettime(CLOCK_REALTIME, &start); From 1cb97a0b707e8705261303fc55bba34e2c8bbaa4 Mon Sep 17 00:00:00 2001 From: zyxzyx Date: Fri, 10 May 2024 15:21:37 +0800 Subject: [PATCH 03/27] fix format Signed-off-by: zyxzyx --- .../native_daemon/native_daemon_client.cpp | 3 --- device/plugins/native_daemon/src/hook_manager.cpp | 2 +- .../native_daemon/src/stack_preprocess.cpp | 2 +- .../unittest/common/native/hook_manager_test.cpp | 15 --------------- .../native_hook/src/hook_socket_client.cpp | 10 +++++----- 5 files changed, 7 insertions(+), 25 deletions(-) diff --git a/device/plugins/native_daemon/native_daemon_client.cpp b/device/plugins/native_daemon/native_daemon_client.cpp index c8e397e82..e86c830a7 100644 --- a/device/plugins/native_daemon/native_daemon_client.cpp +++ b/device/plugins/native_daemon/native_daemon_client.cpp @@ -164,11 +164,8 @@ int32_t main(int32_t argc, char* argv[]) close(fd); } else if (config->printNmd_) { uint32_t fdFirst = TestDumpFile(std::to_string(0)); - uint32_t fdSecond = TestDumpFile(std::to_string(1)); NativeMemoryProfilerSaClientManager::GetMallocStats(fdFirst, config->pid_, 0); - NativeMemoryProfilerSaClientManager::GetMallocStats(fdSecond, config->pid_, 1); close(fdFirst); - close(fdSecond); } else { NativeMemoryProfilerSaClientManager::Start(config); } diff --git a/device/plugins/native_daemon/src/hook_manager.cpp b/device/plugins/native_daemon/src/hook_manager.cpp index 55b0fe347..4197f396e 100644 --- a/device/plugins/native_daemon/src/hook_manager.cpp +++ b/device/plugins/native_daemon/src/hook_manager.cpp @@ -694,7 +694,7 @@ void HookManager::WriteHookConfig() } } -std::vector HookManager::GetFds(int32_t pid, const std::string& name) +std::pair HookManager::GetFds(int32_t pid, const std::string& name) { for (const auto& item : hookCtx_) { if (item->pid == pid || item->processName == name) { diff --git a/device/plugins/native_daemon/src/stack_preprocess.cpp b/device/plugins/native_daemon/src/stack_preprocess.cpp index 069486e64..14ff50a4a 100644 --- a/device/plugins/native_daemon/src/stack_preprocess.cpp +++ b/device/plugins/native_daemon/src/stack_preprocess.cpp @@ -172,7 +172,7 @@ bool StackPreprocess::StopTakeResults() PROFILER_LOG_INFO(LOG_CORE, "start StopTakeResults"); int32_t timerFd = scheduleTaskManager_.ScheduleTask( std::bind(&StackPreprocess::ForceStop, this), WAIT_STOP_TIME, true, false); - if (timeFd == -1) { + if (timerFd == -1) { PROFILER_LOG_ERROR(LOG_CORE, "StopTakeResults ScheduleTask failed!"); return false; } diff --git a/device/plugins/native_daemon/test/unittest/common/native/hook_manager_test.cpp b/device/plugins/native_daemon/test/unittest/common/native/hook_manager_test.cpp index ffc8ba4d5..aa519a746 100644 --- a/device/plugins/native_daemon/test/unittest/common/native/hook_manager_test.cpp +++ b/device/plugins/native_daemon/test/unittest/common/native/hook_manager_test.cpp @@ -185,19 +185,4 @@ HWTEST_F(HookManagerTest, CheckProcess, TestSize.Level1) EXPECT_TRUE(hookManager.CheckProcessName()); } -/* - * @tc.name: PrintStat - * @tc.desc: test PrintStat with false case. - * @tc.type: FUNC - */ -HWTEST_F(HookManagerTest, PrintStat, TestSize.Level1) -{ - HookManager hookManager; - NativeHookConfig nativeConfig; - nativeConfig.set_process_name("HookManagerTest"); - nativeConfig.set_startup_mode(true); - hookManager.SetHookConfig(nativeConfig); - hookManager.GetFds(9, ""); - EXPECT_TRUE((hookManager.shareMemoryNmd_ && hookManager.shareMemoryNmd_->GetName() == "nmd 9")); -} } // namespace \ No newline at end of file diff --git a/device/plugins/native_hook/src/hook_socket_client.cpp b/device/plugins/native_hook/src/hook_socket_client.cpp index aab317b5c..b506b7fd3 100644 --- a/device/plugins/native_hook/src/hook_socket_client.cpp +++ b/device/plugins/native_hook/src/hook_socket_client.cpp @@ -210,22 +210,22 @@ bool HookSocketClient::SendNmdInfo() CHECK_NOTNULL(nmdBuf, false, "HookSocketClient::SendNmdInfo failed, nmdBuf malloc failed"); struct OptArg opt = {0, reinterpret_cast(nmdBuf) }; malloc_stats_print(NmdWriteStat, &opt, "a"); - StackRawData radata = {{{{0}}}}; + StackRawData rawdata = {{{{0}}}}; rawdata.type = NMD_MSG; if (stackWriter_) { bool ret = stackWriter_->WriteWithPayloadTimeout(&rawdata, sizeof(BaseStackRawData), reinterpret_cast(opt.buf), strlen(opt.buf) + 1, - std::bind(&HookSocketClient::PeerIsConnected, this); - PROFILER_LOG_INFO(LOG_CORE, "SendEndMsg ret val: %d", ret); + std::bind(&HookSocketClient::PeerIsConnected, this)); + PROFILER_LOG_INFO(LOG_CORE, "SendNmdMsg ret val: %d", ret); } else { - PROFILER_LOG_ERROR(LOG_CORE, "SendEndMsg stackWriter_ is nullptr"); + PROFILER_LOG_ERROR(LOG_CORE, "SendNmdMsg stackWriter_ is nullptr"); } return true; } bool HookSocketClient::SendEndMsg() { - StackRawData radata = {{{{0}}}}; + StackRawData rawdata = {{{{0}}}}; rawdata.type = END_MSG; if (stackWriter_) { bool ret = stackWriter_->WriteTimeout(&rawdata, sizeof(BaseStackRawData)); From 80869fadf7cd4237fef14f8b78fdc99eda4ebd5c Mon Sep 17 00:00:00 2001 From: zyxzyx Date: Sat, 11 May 2024 16:56:18 +0800 Subject: [PATCH 04/27] fix realpath func Signed-off-by: zyxzyx --- device/base/src/common.cpp | 40 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/device/base/src/common.cpp b/device/base/src/common.cpp index 081d5f202..b4e3ec63f 100644 --- a/device/base/src/common.cpp +++ b/device/base/src/common.cpp @@ -438,6 +438,42 @@ bool CheckApplicationPermission(int pid, const std::string& processName) return true; } +const char* RealPath(std::string &filePath) +{ + if (filePath.find('.') == -1) { + return filePath.c_str(); + } + std::vector paths; + for (auto charac : filePath) { + if (charac != '/') { + (paths.back()) += charac; + } else { + paths.emplace_back(""); + } + } + std::vector validPaths; + for (std::string& pathName: paths) { + if (pathName == "..") { + if (validPaths.size() == 0) { + return NULL; + } else { + validPaths.pop_back(); + } + } else { + validPaths.emplace_back(pathName); + } + } + if (validPaths.back() == "") { + validPaths.pop_back(); + } + filePath = "/"; + for (std::string &pathName : validPaths) { + filePath += pathName; + filePath += "/"; + } + return filePath.c_str(); +} + bool VerifyPath(const std::string& filePath, const std::vector& validPaths) { if (validPaths.size() == 0) { @@ -454,11 +490,11 @@ bool VerifyPath(const std::string& filePath, const std::vector& val bool ReadFile(const std::string &filePath, const std::vector& validPaths, std::string& fileContent) { - char* realFilePath = realpath(filePath.c_str(), nullptr); + std::string pathName = filePath; + const char* realFilePath = RealPath(pathName); CHECK_NOTNULL(realFilePath, false, "Fail to realPath: %s", filePath.c_str()); std::string realFilePathStr(realFilePath); - free(realFilePath); CHECK_TRUE(VerifyPath(realFilePathStr, validPaths), false, "Fail to VerifyPath: %s", realFilePathStr.c_str()); std::ifstream fileStream(realFilePathStr, std::ios::in); From 5c1a83d643194e13a25ffa711d9aeba60e4a9a3d Mon Sep 17 00:00:00 2001 From: zyxzyx Date: Tue, 14 May 2024 20:57:59 +0800 Subject: [PATCH 05/27] use splitstring Signed-off-by: zyxzyx --- device/base/src/common.cpp | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/device/base/src/common.cpp b/device/base/src/common.cpp index b4e3ec63f..1141064cb 100644 --- a/device/base/src/common.cpp +++ b/device/base/src/common.cpp @@ -444,13 +444,7 @@ const char* RealPath(std::string &filePath) return filePath.c_str(); } std::vector paths; - for (auto charac : filePath) { - if (charac != '/') { - (paths.back()) += charac; - } else { - paths.emplace_back(""); - } - } + SplitString(filePath, "/", paths) std::vector validPaths; for (std::string& pathName: paths) { if (pathName == "..") { From 09a0ea890e078517973a6e0723dcdbf9de1c93c6 Mon Sep 17 00:00:00 2001 From: zyxzyx Date: Fri, 17 May 2024 10:41:24 +0800 Subject: [PATCH 06/27] fix error Signed-off-by: zyxzyx --- device/base/src/common.cpp | 9 +++++---- device/plugins/native_daemon/src/hook_manager.cpp | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/device/base/src/common.cpp b/device/base/src/common.cpp index 1141064cb..4e842ab18 100644 --- a/device/base/src/common.cpp +++ b/device/base/src/common.cpp @@ -440,6 +440,9 @@ bool CheckApplicationPermission(int pid, const std::string& processName) const char* RealPath(std::string &filePath) { + if (filePath.size() > 0 && (filePath.back() == '/' || filePath.back() == '.')) { + return nullptr; + } if (filePath.find('.') == -1) { return filePath.c_str(); } @@ -449,7 +452,7 @@ const char* RealPath(std::string &filePath) for (std::string& pathName: paths) { if (pathName == "..") { if (validPaths.size() == 0) { - return NULL; + return nullptr; } else { validPaths.pop_back(); } @@ -457,14 +460,12 @@ const char* RealPath(std::string &filePath) validPaths.emplace_back(pathName); } } - if (validPaths.back() == "") { - validPaths.pop_back(); - } filePath = "/"; for (std::string &pathName : validPaths) { filePath += pathName; filePath += "/"; } + filePath.pop_back(); return filePath.c_str(); } diff --git a/device/plugins/native_daemon/src/hook_manager.cpp b/device/plugins/native_daemon/src/hook_manager.cpp index d17281785..97c01f198 100644 --- a/device/plugins/native_daemon/src/hook_manager.cpp +++ b/device/plugins/native_daemon/src/hook_manager.cpp @@ -692,7 +692,7 @@ void HookManager::WriteHookConfig() std::vector HookManager::GetFds(int32_t pid, const std::string& name) { shareMemoryNmd_ = ShareMemoryAllocator::GetInstance().CreateMemoryBlockLocal("nmd " + std::to_string(pid), - SHARED_MEMORY_SIZE); + SHARED_MEMORY_SIZE); for (const auto& item : hookCtx_) { if (item->pid == pid || item->processName == name) { if (item->pid == -1) { From 7c577d111db58c0e6d3960cb7d348b803b0aa654 Mon Sep 17 00:00:00 2001 From: zyxzyx Date: Mon, 20 May 2024 19:27:05 +0800 Subject: [PATCH 07/27] fix format Signed-off-by: zyxzyx --- device/base/src/common.cpp | 2 +- device/plugins/native_daemon/src/hook_manager.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/device/base/src/common.cpp b/device/base/src/common.cpp index 4e842ab18..53c6ab01a 100644 --- a/device/base/src/common.cpp +++ b/device/base/src/common.cpp @@ -447,7 +447,7 @@ const char* RealPath(std::string &filePath) return filePath.c_str(); } std::vector paths; - SplitString(filePath, "/", paths) + SplitString(filePath, "/", paths); std::vector validPaths; for (std::string& pathName: paths) { if (pathName == "..") { diff --git a/device/plugins/native_daemon/src/hook_manager.cpp b/device/plugins/native_daemon/src/hook_manager.cpp index 97c01f198..d17281785 100644 --- a/device/plugins/native_daemon/src/hook_manager.cpp +++ b/device/plugins/native_daemon/src/hook_manager.cpp @@ -692,7 +692,7 @@ void HookManager::WriteHookConfig() std::vector HookManager::GetFds(int32_t pid, const std::string& name) { shareMemoryNmd_ = ShareMemoryAllocator::GetInstance().CreateMemoryBlockLocal("nmd " + std::to_string(pid), - SHARED_MEMORY_SIZE); + SHARED_MEMORY_SIZE); for (const auto& item : hookCtx_) { if (item->pid == pid || item->processName == name) { if (item->pid == -1) { From 7da076a697730b1e96aed27cbe2afc44b7bfe9bc Mon Sep 17 00:00:00 2001 From: zyxzyx Date: Wed, 29 May 2024 00:18:24 +0800 Subject: [PATCH 08/27] reduce flush time error Signed-off-by: zyxzyx --- device/plugins/native_daemon/include/stack_preprocess.h | 5 +++++ device/plugins/native_daemon/src/hook_manager.cpp | 1 + device/plugins/native_daemon/src/stack_preprocess.cpp | 5 ++--- device/plugins/native_hook/include/hook_socket_client.h | 1 + device/plugins/native_hook/src/hook_socket_client.cpp | 9 ++++++--- 5 files changed, 15 insertions(+), 6 deletions(-) diff --git a/device/plugins/native_daemon/include/stack_preprocess.h b/device/plugins/native_daemon/include/stack_preprocess.h index 1765d94dd..30e780aba 100644 --- a/device/plugins/native_daemon/include/stack_preprocess.h +++ b/device/plugins/native_daemon/include/stack_preprocess.h @@ -62,6 +62,10 @@ public: { pid_ = pid; } + inline void InitStatisticsTime() + { + lastStatisticsTime_ = std::chrono::steady_clock::now(); + } void SaveMemTag(uint32_t tagId, const std::string& tagName); bool GetMemTag(uint32_t tagId, std::string& tagName); void SaveJsRawStack(uint64_t jsChainId, const char* jsRawStack); @@ -172,6 +176,7 @@ private: void FillDwarfErrorStack(); void FillNapiStack(std::string& tagName, std::vector& callFrames, uint64_t napiIndex); private: + std::chrono::steady_clock time_point lastStatisticsTime_ = std::chrono::steady_clock::now(); std::shared_ptr writer_ = nullptr; StackDataRepeaterPtr dataRepeater_ = nullptr; std::thread thread_ {}; diff --git a/device/plugins/native_daemon/src/hook_manager.cpp b/device/plugins/native_daemon/src/hook_manager.cpp index d17281785..c9b370b00 100644 --- a/device/plugins/native_daemon/src/hook_manager.cpp +++ b/device/plugins/native_daemon/src/hook_manager.cpp @@ -664,6 +664,7 @@ void HookManager::StartPluginSession() if (!noDataQueue_) { item->stackPreprocess->StartTakeResults(); } + item->stackPreprocess->InitStatisticsTime(); if (item->pid > 0) { PROFILER_LOG_INFO(LOG_CORE, "start command : send 36 signal to process %d", item->pid); if (kill(item->pid, SIGNAL_START_HOOK) == -1) { diff --git a/device/plugins/native_daemon/src/stack_preprocess.cpp b/device/plugins/native_daemon/src/stack_preprocess.cpp index 2a400a78e..6d3d90bcc 100644 --- a/device/plugins/native_daemon/src/stack_preprocess.cpp +++ b/device/plugins/native_daemon/src/stack_preprocess.cpp @@ -190,11 +190,10 @@ inline void StackPreprocess::IntervalFlushRecordStatistics() { // interval reporting statistics if (hookConfig_.statistics_interval() > 0) { - static auto lastStatisticsTime = std::chrono::steady_clock::now(); auto currentTime = std::chrono::steady_clock::now(); - auto elapsedTime = std::chrono::duration_cast(currentTime - lastStatisticsTime); + auto elapsedTime = std::chrono::duration_cast(currentTime - lastStatisticsTime_); if (elapsedTime >= statisticsInterval_) { - lastStatisticsTime = currentTime; + lastStatisticsTime_ = currentTime; FlushRecordStatistics(); } } diff --git a/device/plugins/native_hook/include/hook_socket_client.h b/device/plugins/native_hook/include/hook_socket_client.h index 6ead4a58a..ea3920d5e 100644 --- a/device/plugins/native_hook/include/hook_socket_client.h +++ b/device/plugins/native_hook/include/hook_socket_client.h @@ -47,6 +47,7 @@ public: private: std::shared_ptr unixSocketClient_; + std::recursive_timed_mutex socketMutex_; int smbFd_; int eventFd_; int pid_; diff --git a/device/plugins/native_hook/src/hook_socket_client.cpp b/device/plugins/native_hook/src/hook_socket_client.cpp index 3a8c577e8..1bb129ff0 100644 --- a/device/plugins/native_hook/src/hook_socket_client.cpp +++ b/device/plugins/native_hook/src/hook_socket_client.cpp @@ -173,9 +173,12 @@ bool HookSocketClient::SendStackWithPayload(const void* data, size_t size, const DisableHook(); return false; } - ++g_flushCount; - if (g_flushCount % FLUSH_FLAG == 0) { - stackWriter_->Flush(); + { + std::lock_guard guard(socketMutex_); + ++g_flushCount; + if (g_flushCount % FLUSH_FLAG == 0) { + stackWriter_->Flush(); + } } return true; } From 2aa89f96549dd89b03ea2ab9ae5f2c7a12e53e0f Mon Sep 17 00:00:00 2001 From: zyxzyx Date: Mon, 3 Jun 2024 21:00:14 +0800 Subject: [PATCH 09/27] fix error Signed-off-by: zyxzyx --- device/plugins/native_hook/include/hook_socket_client.h | 1 - device/plugins/native_hook/src/hook_socket_client.cpp | 9 +++------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/device/plugins/native_hook/include/hook_socket_client.h b/device/plugins/native_hook/include/hook_socket_client.h index ea3920d5e..6ead4a58a 100644 --- a/device/plugins/native_hook/include/hook_socket_client.h +++ b/device/plugins/native_hook/include/hook_socket_client.h @@ -47,7 +47,6 @@ public: private: std::shared_ptr unixSocketClient_; - std::recursive_timed_mutex socketMutex_; int smbFd_; int eventFd_; int pid_; diff --git a/device/plugins/native_hook/src/hook_socket_client.cpp b/device/plugins/native_hook/src/hook_socket_client.cpp index 1bb129ff0..3a8c577e8 100644 --- a/device/plugins/native_hook/src/hook_socket_client.cpp +++ b/device/plugins/native_hook/src/hook_socket_client.cpp @@ -173,12 +173,9 @@ bool HookSocketClient::SendStackWithPayload(const void* data, size_t size, const DisableHook(); return false; } - { - std::lock_guard guard(socketMutex_); - ++g_flushCount; - if (g_flushCount % FLUSH_FLAG == 0) { - stackWriter_->Flush(); - } + ++g_flushCount; + if (g_flushCount % FLUSH_FLAG == 0) { + stackWriter_->Flush(); } return true; } From b9a45cd07a1ff6f5e027f521565a7faeef73dc77 Mon Sep 17 00:00:00 2001 From: wylyw78 Date: Wed, 12 Jun 2024 20:03:44 +0800 Subject: [PATCH 10/27] =?UTF-8?q?=E9=80=82=E9=85=8DLinux=20arm=20host=20op?= =?UTF-8?q?enharmony=E7=BC=96=E8=AF=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wylyw78 --- protos/protos.gni | 8 ++++---- protos/services/BUILD.gn | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/protos/protos.gni b/protos/protos.gni index d60797fcb..79c14dc66 100644 --- a/protos/protos.gni +++ b/protos/protos.gni @@ -15,18 +15,18 @@ import("../build/config.gni") subsys_name = OHOS_PROFILER_SUBSYS_NAME part_name = OHOS_PROFILER_PART_NAME -subsys_x64_out = "clang_x64/thirdparty/grpc" -proto_gen_ipc_dir = "clang_x64/$subsys_name/$part_name" +subsys_x64_out = "clang_${host_cpu}/thirdparty/grpc" +proto_gen_ipc_dir = "clang_${host_cpu}/$subsys_name/$part_name" libc_dir_proto = rebase_path("$asdk_libs_dir", "//") root_output_dir_proto = rebase_path("$root_out_dir", "//") #host:clang_x64 default:arm mingw:mingw_x86_64 if (current_toolchain != host_toolchain) { if (current_toolchain == default_toolchain) { - root_output_dir_proto = "$root_output_dir_proto/clang_x64" + root_output_dir_proto = "$root_output_dir_proto/clang_${host_cpu}" } else { root_output_dir_proto = - get_path_info("$root_output_dir_proto", "dir") + "/clang_x64" + get_path_info("$root_output_dir_proto", "dir") + "/clang_${host_cpu}" } } protoc = root_output_dir_proto diff --git a/protos/services/BUILD.gn b/protos/services/BUILD.gn index f24b41ca8..4e74b4cd7 100644 --- a/protos/services/BUILD.gn +++ b/protos/services/BUILD.gn @@ -148,8 +148,8 @@ action("profiler_service_interface_gen") { args += rebase_path(sources, root_build_dir) deps = [ ":all_type_gen", - "${OHOS_PROFILER_3RDPARTY_GRPC_DIR}:grpc_cpp_plugin(//build/toolchain/linux:clang_x64)", - "${OHOS_PROFILER_3RDPARTY_PROTOBUF_DIR}:protoc(//build/toolchain/linux:clang_x64)", + "${OHOS_PROFILER_3RDPARTY_GRPC_DIR}:grpc_cpp_plugin(//build/toolchain/linux:clang_${host_cpu})", + "${OHOS_PROFILER_3RDPARTY_PROTOBUF_DIR}:protoc(//build/toolchain/linux:clang_${host_cpu})", ] } From 0dab280537c4a4e71b99fd785c5cba0467fdea90 Mon Sep 17 00:00:00 2001 From: wenlong_12 Date: Thu, 13 Jun 2024 12:18:33 +0000 Subject: [PATCH 11/27] =?UTF-8?q?=E6=B8=85=E7=90=86=E5=91=8A=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wenlong_12 --- device/plugins/native_hook/src/hook_client.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/device/plugins/native_hook/src/hook_client.cpp b/device/plugins/native_hook/src/hook_client.cpp index 2b42d4414..a3cab34e5 100644 --- a/device/plugins/native_hook/src/hook_client.cpp +++ b/device/plugins/native_hook/src/hook_client.cpp @@ -427,7 +427,7 @@ void* hook_malloc(void* (*fn)(size_t), size_t size) void* stackAddr = nullptr; size_t coroutineStackSize = 0; if (ffrt_get_current_coroutine_stack(&stackAddr, &coroutineStackSize)) { - stackSize = coroutineStackSize; + stackSize = static_cast(coroutineStackSize); } else { stackptr = reinterpret_cast(__builtin_frame_address(0)); GetRuntimeStackEnd(stackptr, &stackendptr, g_hookPid, GetCurThreadId()); // stack end pointer @@ -530,7 +530,7 @@ void* hook_aligned_alloc(void* (*fn)(size_t, size_t), size_t align, size_t len) void* stackAddr = nullptr; size_t coroutineStackSize = 0; if (ffrt_get_current_coroutine_stack(&stackAddr, &coroutineStackSize)) { - stackSize = coroutineStackSize; + stackSize = static_cast(coroutineStackSize); } else { stackptr = reinterpret_cast(__builtin_frame_address(0)); GetRuntimeStackEnd(stackptr, &stackendptr, g_hookPid, GetCurThreadId()); // stack end pointer @@ -633,7 +633,7 @@ void* hook_calloc(void* (*fn)(size_t, size_t), size_t number, size_t size) void* stackAddr = nullptr; size_t coroutineStackSize = 0; if (ffrt_get_current_coroutine_stack(&stackAddr, &coroutineStackSize)) { - stackSize = coroutineStackSize; + stackSize = static_cast(coroutineStackSize); } else { stackptr = reinterpret_cast(__builtin_frame_address(0)); GetRuntimeStackEnd(stackptr, &stackendptr, g_hookPid, GetCurThreadId()); // stack end pointer @@ -741,7 +741,7 @@ void* hook_realloc(void* (*fn)(void*, size_t), void* ptr, size_t size) void* stackAddr = nullptr; size_t coroutineStackSize = 0; if (ffrt_get_current_coroutine_stack(&stackAddr, &coroutineStackSize)) { - stackSize = coroutineStackSize; + stackSize = static_cast(coroutineStackSize); } else { stackptr = reinterpret_cast(__builtin_frame_address(0)); GetRuntimeStackEnd(stackptr, &stackendptr, g_hookPid, GetCurThreadId()); // stack end pointer @@ -873,7 +873,7 @@ void hook_free(void (*free_func)(void*), void* p) void* stackAddr = nullptr; size_t coroutineStackSize = 0; if (ffrt_get_current_coroutine_stack(&stackAddr, &coroutineStackSize)) { - stackSize = coroutineStackSize; + stackSize = static_cast(coroutineStackSize); } else { stackptr = reinterpret_cast(__builtin_frame_address(0)); GetRuntimeStackEnd(stackptr, &stackendptr, g_hookPid, GetCurThreadId()); // stack end pointer @@ -990,7 +990,7 @@ void* hook_mmap(void*(*fn)(void*, size_t, int, int, int, off_t), void* stackAddr = nullptr; size_t coroutineStackSize = 0; if (ffrt_get_current_coroutine_stack(&stackAddr, &coroutineStackSize)) { - stackSize = coroutineStackSize; + stackSize = static_cast(coroutineStackSize); } else { stackptr = reinterpret_cast(__builtin_frame_address(0)); GetRuntimeStackEnd(stackptr, &stackendptr, g_hookPid, GetCurThreadId()); // stack end pointer @@ -1092,7 +1092,7 @@ int hook_munmap(int(*fn)(void*, size_t), void* addr, size_t length) void* stackAddr = nullptr; size_t coroutineStackSize = 0; if (ffrt_get_current_coroutine_stack(&stackAddr, &coroutineStackSize)) { - stackSize = coroutineStackSize; + stackSize = static_cast(coroutineStackSize); } else { stackptr = reinterpret_cast(__builtin_frame_address(0)); GetRuntimeStackEnd(stackptr, &stackendptr, g_hookPid, GetCurThreadId()); // stack end pointer @@ -1213,7 +1213,7 @@ void hook_memtrace(void* addr, size_t size, const char* tag, bool isUsing) void* stackAddr = nullptr; size_t coroutineStackSize = 0; if (ffrt_get_current_coroutine_stack(&stackAddr, &coroutineStackSize)) { - stackSize = coroutineStackSize; + stackSize = static_cast(coroutineStackSize); } else { stackptr = reinterpret_cast(__builtin_frame_address(0)); GetRuntimeStackEnd(stackptr, &stackendptr, g_hookPid, GetCurThreadId()); // stack end pointer From 8f083b40ab45d6dce651d6de94d7c80c6a64b55a Mon Sep 17 00:00:00 2001 From: hhl Date: Fri, 14 Jun 2024 09:37:37 +0800 Subject: [PATCH 12/27] add js test Signed-off-by: hhl --- .../test/unittest/js/ExampleJsunit.test.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/hidebug/test/unittest/js/ExampleJsunit.test.js b/hidebug/test/unittest/js/ExampleJsunit.test.js index 97c9a11bc..9960e365e 100644 --- a/hidebug/test/unittest/js/ExampleJsunit.test.js +++ b/hidebug/test/unittest/js/ExampleJsunit.test.js @@ -455,4 +455,23 @@ describe("HidebugJsTest", function () { expect(error.message === "Invalid parameter, unknown property.").assertTrue(); } }) + + /** + * @tc.name: HidebugJsTest_019 + * @tc.desc: setAppResourceLimit正常测试 + * @tc.type: FUNC + * @tc.require: issueI5VY8L + */ + it('HidebugJsTest_019', 0, function () { + console.info("---------------------------HidebugJsTest_019----------------------------------"); + try { + let type = "js_heap"; + let value = 85; + let enabledDebugLog = false; + hidebug.setAppResourceLimit(type, value, enabledDebugLog); + } catch (error) { + console.info(error.code); + expect(error.code === "401").assertTrue(); + } + }) }) From 4aacb93cf5bf7bb3d60d49baa4eeb9a56cc91ea1 Mon Sep 17 00:00:00 2001 From: wenlong_12 Date: Fri, 14 Jun 2024 11:48:36 +0800 Subject: [PATCH 13/27] =?UTF-8?q?=20=20=20=20=20=E4=BC=98=E5=8C=96napi=20m?= =?UTF-8?q?emtrace=20=E7=9A=84=E5=8A=9F=E8=83=BD=20=20=20=20=20=20Signed-o?= =?UTF-8?q?ff-by:shuxinyi4=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wenlong_12 --- .../native_daemon/src/stack_preprocess.cpp | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/device/plugins/native_daemon/src/stack_preprocess.cpp b/device/plugins/native_daemon/src/stack_preprocess.cpp index 5c7c5da0a..dc1cd114a 100644 --- a/device/plugins/native_daemon/src/stack_preprocess.cpp +++ b/device/plugins/native_daemon/src/stack_preprocess.cpp @@ -578,9 +578,13 @@ inline uint32_t StackPreprocess::GetCallStackId(const RawStackPtr& rawStack, std callStack_.clear(); bool isNapi = false; if (rawStack->stackConext->type == MEMORY_USING_MSG && hookConfig_.js_stack_report() == NAPI_CALL_STACK) { - callStack_.reserve(callFrames.size() + 1); // 1 : insert a frame - callStack_.push_back((DWARF_NAPI_CALLBACK + napiIndex_) | JS_OFFLINE_IP_MASK); - isNapi = true; + std::string tagName; + GetMemTag(rawStack->stackConext->tagId, tagName); + if (tagName.find("napi") != std::string::npos) { + callStack_.reserve(callFrames.size() + 1); // 1 : insert a frame + callStack_.push_back((DWARF_NAPI_CALLBACK + napiIndex_) | JS_OFFLINE_IP_MASK); + isNapi = true; + } } else { callStack_.reserve(callFrames.size()); } @@ -701,9 +705,13 @@ void StackPreprocess::SetAllocStatisticsFrame(const RawStackPtr& rawStack, std:: callStack_.clear(); bool isNapi = false; if (hookConfig_.js_stack_report() == NAPI_CALL_STACK) { - callStack_.reserve(callFrames.size() + FRAME_DEPTH); - callStack_.push_back((DWARF_NAPI_CALLBACK + napiIndex_) | JS_OFFLINE_IP_MASK); - isNapi = true; + std::string tagName; + GetMemTag(rawStack->stackConext->tagId, tagName); + if (tagName.find("napi") != std::string::npos) { + callStack_.reserve(callFrames.size() + FRAME_DEPTH); // insert a frame + callStack_.push_back((DWARF_NAPI_CALLBACK + napiIndex_) | JS_OFFLINE_IP_MASK); + isNapi = true; + } } else { callStack_.reserve(callFrames.size() + 1); } From f2790b50b267a6406999696a6970f615a761f8b2 Mon Sep 17 00:00:00 2001 From: zyxzyx Date: Mon, 17 Jun 2024 15:13:19 +0800 Subject: [PATCH 14/27] fix multithread set time problem Signed-off-by: zyxzyx --- device/plugins/native_hook/src/hook_client.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/device/plugins/native_hook/src/hook_client.cpp b/device/plugins/native_hook/src/hook_client.cpp index a3cab34e5..a65b6746f 100644 --- a/device/plugins/native_hook/src/hook_client.cpp +++ b/device/plugins/native_hook/src/hook_client.cpp @@ -824,14 +824,16 @@ size_t hook_malloc_usable_size(size_t (*fn)(void*), void* ptr) void hook_free(void (*free_func)(void*), void* p) { - if (free_func) { + if (!free_func) { free_func(p); } if (g_ClientConfig.mallocDisable || IsPidChanged()) { + free_func(p); return; } if (g_ClientConfig.sampleInterval >= THRESHOLD) { if (!IsAddrExist(p)) { + free_func(p); return; } } @@ -911,6 +913,7 @@ void hook_free(void (*free_func)(void*), void* p) } holder->SendStackWithPayload(&rawdata, realSize, stackptr, stackSize); } + free_func(p); #ifdef PERFORMANCE_DEBUG g_mallocTimes++; struct timespec end = {}; @@ -1067,10 +1070,11 @@ void* hook_mmap(void*(*fn)(void*, size_t, int, int, int, off_t), int hook_munmap(int(*fn)(void*, size_t), void* addr, size_t length) { int ret = -1; - if (fn) { - ret = fn(addr, length); + if (!fn) { + return; } if (g_ClientConfig.mmapDisable || IsPidChanged()) { + ret = fn(addr, length); return ret; } @@ -1130,6 +1134,7 @@ int hook_munmap(int(*fn)(void*, size_t), void* addr, size_t length) } holder->SendStackWithPayload(&rawdata, realSize, stackptr, stackSize); } + ret = fn(addr, length); #ifdef PERFORMANCE_DEBUG g_mallocTimes++; struct timespec end = {}; From 5d703f1b3903f1ea8748cd911f02ce102f52c516 Mon Sep 17 00:00:00 2001 From: zyxzyx Date: Mon, 17 Jun 2024 15:16:38 +0800 Subject: [PATCH 15/27] fix format Signed-off-by: zyxzyx --- device/plugins/native_hook/src/hook_client.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/device/plugins/native_hook/src/hook_client.cpp b/device/plugins/native_hook/src/hook_client.cpp index a65b6746f..c5ab1bf54 100644 --- a/device/plugins/native_hook/src/hook_client.cpp +++ b/device/plugins/native_hook/src/hook_client.cpp @@ -1069,10 +1069,10 @@ void* hook_mmap(void*(*fn)(void*, size_t, int, int, int, off_t), int hook_munmap(int(*fn)(void*, size_t), void* addr, size_t length) { - int ret = -1; if (!fn) { return; } + int ret = -1; if (g_ClientConfig.mmapDisable || IsPidChanged()) { ret = fn(addr, length); return ret; From 280f1821beb2432dee2652a75132c99603cfd091 Mon Sep 17 00:00:00 2001 From: zyxzyx Date: Mon, 17 Jun 2024 15:20:23 +0800 Subject: [PATCH 16/27] fix error Signed-off-by: zyxzyx --- device/plugins/native_hook/src/hook_client.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/device/plugins/native_hook/src/hook_client.cpp b/device/plugins/native_hook/src/hook_client.cpp index c5ab1bf54..ebaa3f729 100644 --- a/device/plugins/native_hook/src/hook_client.cpp +++ b/device/plugins/native_hook/src/hook_client.cpp @@ -825,7 +825,7 @@ size_t hook_malloc_usable_size(size_t (*fn)(void*), void* ptr) void hook_free(void (*free_func)(void*), void* p) { if (!free_func) { - free_func(p); + return; } if (g_ClientConfig.mallocDisable || IsPidChanged()) { free_func(p); From 1a8245dd6caa3b7c933f3075fc3baef3f9f8d1cf Mon Sep 17 00:00:00 2001 From: zyxzyx Date: Mon, 17 Jun 2024 15:28:34 +0800 Subject: [PATCH 17/27] fix compile error Signed-off-by: zyxzyx --- device/plugins/native_hook/src/hook_client.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/device/plugins/native_hook/src/hook_client.cpp b/device/plugins/native_hook/src/hook_client.cpp index ebaa3f729..94f6d6080 100644 --- a/device/plugins/native_hook/src/hook_client.cpp +++ b/device/plugins/native_hook/src/hook_client.cpp @@ -1069,10 +1069,10 @@ void* hook_mmap(void*(*fn)(void*, size_t, int, int, int, off_t), int hook_munmap(int(*fn)(void*, size_t), void* addr, size_t length) { - if (!fn) { - return; - } int ret = -1; + if (!fn) { + return ret; + } if (g_ClientConfig.mmapDisable || IsPidChanged()) { ret = fn(addr, length); return ret; From 489aa96e0d99088022504bc55d5277d6a7af1819 Mon Sep 17 00:00:00 2001 From: zyxzyx Date: Tue, 18 Jun 2024 10:32:28 +0800 Subject: [PATCH 18/27] fix nativehook_ut Signed-off-by: zyxzyx --- .../plugins/native_hook/test/unittest/check_hook_data_test.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/device/plugins/native_hook/test/unittest/check_hook_data_test.cpp b/device/plugins/native_hook/test/unittest/check_hook_data_test.cpp index 19b26966b..3ca42d4f3 100644 --- a/device/plugins/native_hook/test/unittest/check_hook_data_test.cpp +++ b/device/plugins/native_hook/test/unittest/check_hook_data_test.cpp @@ -760,6 +760,7 @@ HWTEST_F(CheckHookDataTest, DFX_DFR_Hiprofiler_0120, Function | MediumTest | Lev uint16_t applyCount = std::atoi(resultVec[1].c_str()); std::cout << "applyCount: " << applyCount << std::endl; EXPECT_TRUE(applyCount > 0); + sleep(SLEEP_TIME); } } @@ -1029,6 +1030,7 @@ HWTEST_F(CheckHookDataTest, DFX_DFR_Hiprofiler_0180, Function | MediumTest | Lev uint16_t applyCount = std::atoi(resultVec[1].c_str()); std::cout << "applyCount: " << applyCount << std::endl; EXPECT_TRUE(applyCount > 0); + sleep(SLEEP_TIME); } } @@ -1137,6 +1139,7 @@ HWTEST_F(CheckHookDataTest, DFX_DFR_Hiprofiler_0200, Function | MediumTest | Lev uint16_t applyCount = std::atoi(resultVec[1].c_str()); std::cout << "applyCount: " << applyCount << std::endl; EXPECT_TRUE(applyCount > 0); + sleep(SLEEP_TIME); } } } From 58ff71dbccd948bdf13c9eaa4c4d75d9e13017c3 Mon Sep 17 00:00:00 2001 From: wenlong_12 Date: Tue, 18 Jun 2024 03:00:09 +0000 Subject: [PATCH 19/27] =?UTF-8?q?=E4=BC=98=E5=8C=96stopsession?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wenlong_12 --- device/services/profiler_service/src/profiler_service.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/device/services/profiler_service/src/profiler_service.cpp b/device/services/profiler_service/src/profiler_service.cpp index 15efd434a..295f76508 100644 --- a/device/services/profiler_service/src/profiler_service.cpp +++ b/device/services/profiler_service/src/profiler_service.cpp @@ -168,7 +168,6 @@ bool ProfilerService::SessionContext::StartPluginSessions() bool ProfilerService::SessionContext::StopPluginSessions() { - std::unique_lock lock(sessionMutex); if (sessionConfig.session_mode() == ProfilerSessionConfig::OFFLINE) { if (offlineScheduleTaskFd != -1) { stopExpireTask.UnscheduleTaskLockless(offlineScheduleTaskFd); From 16543347fe40a55f2f369d3784588a1b56aa5eef Mon Sep 17 00:00:00 2001 From: yuhaoqiang Date: Tue, 18 Jun 2024 11:10:07 +0800 Subject: [PATCH 20/27] =?UTF-8?q?error=20code=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yuhaoqiang --- hidebug/interfaces/js/kits/napi/napi_hidebug.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/hidebug/interfaces/js/kits/napi/napi_hidebug.cpp b/hidebug/interfaces/js/kits/napi/napi_hidebug.cpp index 8823ed27e..f1d086823 100644 --- a/hidebug/interfaces/js/kits/napi/napi_hidebug.cpp +++ b/hidebug/interfaces/js/kits/napi/napi_hidebug.cpp @@ -540,7 +540,7 @@ static napi_value GetServiceDump(napi_env env, napi_callback_info info) sptr sa = sam->CheckSystemAbility(serviceAbilityId); if (sa == nullptr) { HILOG_ERROR(LOG_CORE, "no this system ability."); - std::string idErrorMessage = "service id is invalid, system ability is not exist."; + std::string idErrorMessage = "ServiceId invalid. The system ability does not exist."; napi_throw_error(env, std::to_string(ErrorCode::SYSTEM_ABILITY_NOT_FOUND).c_str(), idErrorMessage.c_str()); return CreateUndefined(env); } @@ -568,7 +568,7 @@ static napi_value GetSystemCpuUsage(napi_env env, napi_callback_info info) { auto cpuUsageOptional = HidebugNativeInterface::CreateInstance()->GetSystemCpuUsage(); if (!cpuUsageOptional.has_value()) { - std::string paramErrorMessage = "The status of the system cpu usage is abnormal."; + std::string paramErrorMessage = "The status of the system CPU usage is abnormal."; napi_throw_error(env, std::to_string(ErrorCode::SYSTEM_STATUS_ABNORMAL).c_str(), paramErrorMessage.c_str()); return CreateUndefined(env); } @@ -832,14 +832,14 @@ napi_value StartAppTraceCapture(napi_env env, napi_callback_info info) napi_throw_error(env, std::to_string(ErrorCode::PARAMETER_ERROR).c_str(), errorMessage.c_str()); } if (ret == HAVA_ALREADY_TRACE) { - std::string errorMessage = "Have already capture trace"; + std::string errorMessage = "Capture trace already enabled."; napi_throw_error(env, std::to_string(ErrorCode::HAVA_ALREADY_TRACE).c_str(), errorMessage.c_str()); } if (ret == WITHOUT_WRITE_PERMISSON) { - std::string errorMessage = "Without write permission on the file"; + std::string errorMessage = "No write permission on the file."; napi_throw_error(env, std::to_string(ErrorCode::WITHOUT_WRITE_PERMISSON).c_str(), errorMessage.c_str()); } - std::string errorMessage = "The status of the trace is abnormal"; + std::string errorMessage = "Abnormal trace status."; napi_throw_error(env, std::to_string(ErrorCode::SYSTEM_STATUS_ABNORMAL).c_str(), errorMessage.c_str()); return CreateUndefined(env); } From 30445a41f7a4b97af22b926ba985f44df6fae849 Mon Sep 17 00:00:00 2001 From: zyxzyx Date: Tue, 18 Jun 2024 17:10:42 +0800 Subject: [PATCH 21/27] fix compile error Signed-off-by: zyxzyx --- device/plugins/native_daemon/include/stack_preprocess.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/device/plugins/native_daemon/include/stack_preprocess.h b/device/plugins/native_daemon/include/stack_preprocess.h index 30e780aba..0bc7d7ce5 100644 --- a/device/plugins/native_daemon/include/stack_preprocess.h +++ b/device/plugins/native_daemon/include/stack_preprocess.h @@ -176,7 +176,7 @@ private: void FillDwarfErrorStack(); void FillNapiStack(std::string& tagName, std::vector& callFrames, uint64_t napiIndex); private: - std::chrono::steady_clock time_point lastStatisticsTime_ = std::chrono::steady_clock::now(); + std::chrono::steady_clock::time_point lastStatisticsTime_ = std::chrono::steady_clock::now(); std::shared_ptr writer_ = nullptr; StackDataRepeaterPtr dataRepeater_ = nullptr; std::thread thread_ {}; From f8726d17b045f4679fde0c0ed0ab2a1442bdbd93 Mon Sep 17 00:00:00 2001 From: yanmengzhao1 Date: Thu, 20 Jun 2024 14:48:59 +0800 Subject: [PATCH 22/27] feat: support for checking hongmeng kernel. Signed-off-by: yanmengzhao1 --- device/plugins/ftrace_plugin/src/ftrace_fs_ops.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/device/plugins/ftrace_plugin/src/ftrace_fs_ops.cpp b/device/plugins/ftrace_plugin/src/ftrace_fs_ops.cpp index b53863659..f1ffa11d9 100644 --- a/device/plugins/ftrace_plugin/src/ftrace_fs_ops.cpp +++ b/device/plugins/ftrace_plugin/src/ftrace_fs_ops.cpp @@ -61,7 +61,7 @@ bool FtraceFsOps::IsHmKernel() utsname unameBuf; if ((uname(&unameBuf)) == 0) { std::string osRelease = unameBuf.release; - isHM = osRelease.find("hmkernel") != std::string::npos; + isHM = osRelease.find("HongMeng") != std::string::npos; } return isHM; } From 3fb4d7cd1cc0ca2e22491e01000bff2bbfe702ae Mon Sep 17 00:00:00 2001 From: zyxzyx Date: Fri, 21 Jun 2024 14:04:01 +0800 Subject: [PATCH 23/27] remove hilog Signed-off-by: zyxzyx --- device/services/shared_memory/src/share_memory_block.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/device/services/shared_memory/src/share_memory_block.cpp b/device/services/shared_memory/src/share_memory_block.cpp index 032d992af..c933127e8 100644 --- a/device/services/shared_memory/src/share_memory_block.cpp +++ b/device/services/shared_memory/src/share_memory_block.cpp @@ -423,7 +423,6 @@ bool ShareMemoryBlock::PutWithPayloadSync(const int8_t* header, uint32_t headerS return false; } pthread_mutex_unlock(&header_->info.mutex_); - PROFILER_LOG_DEBUG(LOG_CORE, "%s:%d block", __FUNCTION__, __LINE__); usleep(WAIT_RELEASE_TIMEOUT_US); pthread_mutex_lock(&header_->info.mutex_); rawMemory = GetFreeMemory(headerSize + payloadSize); From b62d407c85002414afe8cfa7e286ad726c85eb25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=92=B1=E7=8E=89=E8=8B=B1?= Date: Fri, 21 Jun 2024 14:46:45 +0800 Subject: [PATCH 24/27] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=BB=93=E6=9D=9F?= =?UTF-8?q?=E6=97=B6=E5=A2=9E=E5=8A=A0=E4=BF=9D=E5=AD=98=E4=B8=AD=E7=9A=84?= =?UTF-8?q?=E7=8A=B6=E6=80=81=EF=BC=8C=E5=A2=9E=E5=8A=A0=E7=BB=B4=E6=B5=8B?= =?UTF-8?q?=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 钱玉英 --- .../main/ets/common/profiler/ProfilerTask.ets | 11 ++---- .../profiler/base/BaseProfilerUtils.ets | 1 - .../src/main/ets/common/profiler/item/CPU.ets | 2 - .../src/main/ets/common/profiler/item/DDR.ets | 1 - .../src/main/ets/common/profiler/item/FPS.ets | 1 - .../main/ets/common/profiler/item/Power.ets | 10 ----- .../src/main/ets/common/ui/main/Report.ets | 2 +- .../entry/src/main/ets/pages/FloatBall.ets | 37 +++++++++++++------ 8 files changed, 31 insertions(+), 34 deletions(-) diff --git a/host/smartperf/client/client_ui/entry/src/main/ets/common/profiler/ProfilerTask.ets b/host/smartperf/client/client_ui/entry/src/main/ets/common/profiler/ProfilerTask.ets index d51bc5253..d9bd8f6b5 100644 --- a/host/smartperf/client/client_ui/entry/src/main/ets/common/profiler/ProfilerTask.ets +++ b/host/smartperf/client/client_ui/entry/src/main/ets/common/profiler/ProfilerTask.ets @@ -45,7 +45,6 @@ export class ProfilerTask { for (var key of keys) { if (globalThis.collectConfigs[key]) { let typeCollect = ProfilerFactory.getProfilerByConfig(key.toString()); - SPLogger.DEBUG(ProfilerTask.name, 'ProfilerTask initModule: ' + typeCollect); if (typeCollect == null) { continue; } else { @@ -102,7 +101,6 @@ export class ProfilerTask { } taskStart() { - SPLogger.DEBUG(ProfilerTask.name, 'ProfilerTask taskStart call'); var gpDataArr: GPData[] = []; this.collectItems.forEach((moduleName) => { let typeCollect = ProfilerFactory.getProfilerByConfig(moduleName.toString()); @@ -112,7 +110,6 @@ export class ProfilerTask { gpDataArr.push(typeCollect.readCPULoad()); } gpDataArr.push(gpData); - SPLogger.DEBUG(ProfilerTask.name, 'profiler ProfilerTask:curData:' + gpData); } }); @@ -124,13 +121,9 @@ export class ProfilerTask { CommonEvent.publish('event', { code: 0, data: JSON.stringify(tTndex) }, (err) => {}); } globalThis.collectIntervalNum++; - SPLogger.DEBUG(ProfilerTask.name, 'profiler globalThis.collectIntervalNum ' + globalThis.collectIntervalNum); - - SPLogger.DEBUG(ProfilerTask.name, 'ProfilerTask taskStart called'); } taskSingleItemStart(collectorType: CollectorType) { - SPLogger.ERROR('ProfilerTaskTest', 'ProfilerTask taskStart call collectorType' + collectorType.toString()); let typeCollect = ProfilerFactory.getProfilerByConfig(collectorType.toString()); if (typeCollect instanceof Power) { typeCollect.readFourTimesData(); @@ -146,10 +139,12 @@ export class ProfilerTask { database.insertData('t_index_info', globalThis.dbTime, tTndex); } } + SPLogger.DEBUG(ProfilerTask.name, 'ProfilerTask insertData success'); createFilePath( globalThis.abilityContext.getApplicationContext().filesDir + '/' + globalThis.dbTime + '/t_index_info.csv', csvTIndexInfo(globalThis.tTndexs) ); + SPLogger.DEBUG(ProfilerTask.name, 'ProfilerTask createFilePath index_info success'); // t_general_info 入库 globalThis.endTime = new Date().getTime(); let tGeneralInfo = new TGeneralInfo( @@ -168,7 +163,9 @@ export class ProfilerTask { tGeneralInfo.brand = deviceInfo.brand; tGeneralInfo.version = deviceInfo.displayVersion; tGeneralInfo.sn = deviceInfo.serial; + SPLogger.DEBUG(ProfilerTask.name, 'ProfilerTask insertGeneraData'); database.insertGeneraData('t_general_info', tGeneralInfo); + SPLogger.DEBUG(ProfilerTask.name, 'ProfilerTask insertGeneraData success'); createFilePath( globalThis.abilityContext.getApplicationContext().filesDir + '/' + globalThis.dbTime + '/t_general_info.csv', csvGeneralInfo(tGeneralInfo) diff --git a/host/smartperf/client/client_ui/entry/src/main/ets/common/profiler/base/BaseProfilerUtils.ets b/host/smartperf/client/client_ui/entry/src/main/ets/common/profiler/base/BaseProfilerUtils.ets index c493d5411..94195a06b 100644 --- a/host/smartperf/client/client_ui/entry/src/main/ets/common/profiler/base/BaseProfilerUtils.ets +++ b/host/smartperf/client/client_ui/entry/src/main/ets/common/profiler/base/BaseProfilerUtils.ets @@ -88,7 +88,6 @@ export function travelFile(path: string, regexp: string): Array { } let name: String = dirent.name; if (name.match(regexp)) { - SPLogger.DEBUG(TAG, 'travelFile get name:' + dirent.name); fileNames.push(name); } if (regexp == '') { diff --git a/host/smartperf/client/client_ui/entry/src/main/ets/common/profiler/item/CPU.ets b/host/smartperf/client/client_ui/entry/src/main/ets/common/profiler/item/CPU.ets index 610b4a018..022162a37 100644 --- a/host/smartperf/client/client_ui/entry/src/main/ets/common/profiler/item/CPU.ets +++ b/host/smartperf/client/client_ui/entry/src/main/ets/common/profiler/item/CPU.ets @@ -65,11 +65,9 @@ export class CPU extends BaseProfiler { try { var fd = -1; fd = fileio.openSync(path, 0o0); - SPLogger.DEBUG(CPU.name, 'readCPULoad fd:' + fd); let buf = new ArrayBuffer(2048); fileio.readSync(fd, buf); let cpuStr: String = String.fromCharCode.apply(null, new Uint8Array(buf)); - SPLogger.DEBUG(CPU.name, 'readCPULoad cpuStr:' + cpuStr); let cpuStrArr = []; cpuStr = cpuStr.substring(0, cpuStr.indexOf('intr')); let nextj = 0; diff --git a/host/smartperf/client/client_ui/entry/src/main/ets/common/profiler/item/DDR.ets b/host/smartperf/client/client_ui/entry/src/main/ets/common/profiler/item/DDR.ets index a7e84cf87..55c5a0ab6 100644 --- a/host/smartperf/client/client_ui/entry/src/main/ets/common/profiler/item/DDR.ets +++ b/host/smartperf/client/client_ui/entry/src/main/ets/common/profiler/item/DDR.ets @@ -48,7 +48,6 @@ export class DDR extends BaseProfiler { const path = DdrConfig.DDR_BASE; let ddr = fileOpen(path); this.ddrMap.set('ddrFreq', ddr); - SPLogger.DEBUG(DDR.name, 'profile_readDDR' + ddr); return createGPData('DDR', this.ddrMap); } } diff --git a/host/smartperf/client/client_ui/entry/src/main/ets/common/profiler/item/FPS.ets b/host/smartperf/client/client_ui/entry/src/main/ets/common/profiler/item/FPS.ets index a478c4b88..a7bba679a 100644 --- a/host/smartperf/client/client_ui/entry/src/main/ets/common/profiler/item/FPS.ets +++ b/host/smartperf/client/client_ui/entry/src/main/ets/common/profiler/item/FPS.ets @@ -58,7 +58,6 @@ export class FPS extends BaseProfiler implements SocketProfiler { readMessageQueue() { mainWorker.postMessage({ fps: true, pkg: globalThis.collectPkg }); - SPLogger.DEBUG(FPS.name, 'messageQueue for fps' + globalThis.fpsArr.length); if (globalThis.fpsArr.length > 0) { let fpsQueue: String[] = globalThis.fpsArr; let fpsJitterQueue: String[] = globalThis.fpsJitterArr; diff --git a/host/smartperf/client/client_ui/entry/src/main/ets/common/profiler/item/Power.ets b/host/smartperf/client/client_ui/entry/src/main/ets/common/profiler/item/Power.ets index 71ca851ba..acf1c86b1 100644 --- a/host/smartperf/client/client_ui/entry/src/main/ets/common/profiler/item/Power.ets +++ b/host/smartperf/client/client_ui/entry/src/main/ets/common/profiler/item/Power.ets @@ -45,10 +45,6 @@ export class Power extends BaseProfiler { } }); }); - SPLogger.DEBUG( - Power.name, - 'pathNodes init length:' + pathNodes.length + 'support items:' + JSON.stringify(this.supportItemKey) - ); return CollectorType.TYPE_POWER; } @@ -83,13 +79,11 @@ export class Power extends BaseProfiler { if (powerKey == 'current_now') { let powerValue = fileOpen(PowerConfig.POWER_PATH + '/' + powerKey); globalThis.powerCurArr.push(powerValue); - console.error('last CurrentNow-->push' + powerValue); } if (powerKey == 'voltage_now') { let powerValue = fileOpen(PowerConfig.POWER_PATH + '/' + powerKey); globalThis.powerVoltArr.push(powerValue); - console.error('last VoltageNow-->push' + powerValue); } } } @@ -101,10 +95,8 @@ export class Power extends BaseProfiler { let lastValue = 0; while (powerQueue.length >= 4) { lastValue += StringUtils.s2L(powerQueue.pop().toString()); - console.error('last CurrentNow-->pop' + lastValue); } let avgCurrentNum = (lastValue / 4).toString(); - console.error('last CurrentNowAVG-->' + avgCurrentNum); return avgCurrentNum; } @@ -114,10 +106,8 @@ export class Power extends BaseProfiler { let lastValue = 0; while (powerQueue.length >= 4) { lastValue += StringUtils.s2L(powerQueue.pop().toString()); - console.error('last VoltageNow-->pop' + lastValue); } let avgCurrentNum = (lastValue / 4).toString(); - console.error('last VoltageNowAVG-->' + avgCurrentNum); return avgCurrentNum; } } diff --git a/host/smartperf/client/client_ui/entry/src/main/ets/common/ui/main/Report.ets b/host/smartperf/client/client_ui/entry/src/main/ets/common/ui/main/Report.ets index 401462600..2b7e93804 100644 --- a/host/smartperf/client/client_ui/entry/src/main/ets/common/ui/main/Report.ets +++ b/host/smartperf/client/client_ui/entry/src/main/ets/common/ui/main/Report.ets @@ -93,7 +93,7 @@ export struct Report { }) } } - }, item => item.toString()) + }, item => item.startTime.toString()) } .edgeEffect(EdgeEffect.None) // 滑动到边缘无效果 .chainAnimation(false) // 联动特效关闭 diff --git a/host/smartperf/client/client_ui/entry/src/main/ets/pages/FloatBall.ets b/host/smartperf/client/client_ui/entry/src/main/ets/pages/FloatBall.ets index 84c4b5dc5..2db7c591b 100644 --- a/host/smartperf/client/client_ui/entry/src/main/ets/pages/FloatBall.ets +++ b/host/smartperf/client/client_ui/entry/src/main/ets/pages/FloatBall.ets @@ -102,18 +102,13 @@ struct FloatBall { longEvent() { console.log('cm-floatBall-longEvent') + this.playerState = TaskStatus.task_stop ProfilerTask.getInstance().taskStop() - this.destroyAllWindow() - this.clearAllInterVal() - var now = new Date(); - var exitTime = now.getTime() + 1000; - while (true) { - now = new Date(); - if (now.getTime() > exitTime) { - break; - } - } - ProfilerTask.getInstance().taskGetDubai() + setTimeout(() => { + this.destroyAllWindow() + this.clearAllInterVal() + ProfilerTask.getInstance().taskGetDubai() + }, 5000) } async dubai_data_to_disk() { mainWorker.postMessage({'setDuBaiDb': true}) @@ -264,6 +259,26 @@ struct FloatBall { }) )) } + if (this.playerState == TaskStatus.task_stop) { + Circle() + .width('90vp') + .height('90vp') + .fill(Color.White) + .fillOpacity(0) + .opacity(0.8) + .border({ radius: '90vp', width: '0.5vp', color: $r('app.color.colorPrimary') }) + .linearGradient({ + angle: 135, + direction: GradientDirection.Left, + colors: [[$r('app.color.colorPrimary'), 1.0], [$r('app.color.colorPrimary'), 1.0]] + }) + Text('saving..') + .fontSize(12) + .textAlign(TextAlign.Center) + .fontColor($r('app.color.color_fff')) + .width('100%') + .height('100%') + } }.width('100%').height('100%') } From 56edbb8a9d117f638761186d0eb33787a143d255 Mon Sep 17 00:00:00 2001 From: wwx1285007 Date: Fri, 21 Jun 2024 15:13:42 +0800 Subject: [PATCH 25/27] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=88=AA=E5=9B=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wwx1285007 --- host/smartperf/client/client_command/Capture.cpp | 11 +++++++---- host/smartperf/client/client_command/Power.cpp | 14 +------------- .../client/client_command/include/Power.h | 4 +--- .../client_command/include/smartperf_command.h | 2 +- .../client/client_command/profiler_fps.cpp | 3 ++- .../client/client_command/smartperf_command.cpp | 6 ++++-- host/smartperf/client/client_command/sp_task.cpp | 3 +++ host/smartperf/client/client_command/sp_utils.cpp | 2 +- .../client/client_command/stalling_rate_trace.cpp | 5 ++++- .../client/client_command/startup_delay.cpp | 2 +- 10 files changed, 25 insertions(+), 27 deletions(-) diff --git a/host/smartperf/client/client_command/Capture.cpp b/host/smartperf/client/client_command/Capture.cpp index cd7098102..cf141f3c7 100644 --- a/host/smartperf/client/client_command/Capture.cpp +++ b/host/smartperf/client/client_command/Capture.cpp @@ -82,6 +82,9 @@ void Capture::ThreadGetCatch(const std::string &curTime) const void Capture::ThreadGetCatchSocket(const std::string &curTime) const { + if (curTime.empty()) { + return; + } auto savePath = "/data/local/tmp/capture/screenCap_" + curTime + ".jpeg"; std::string cmdResult; if (!SPUtils::FileAccess("/data/local/tmp/capture")) { @@ -89,12 +92,12 @@ void Capture::ThreadGetCatchSocket(const std::string &curTime) const printf("/data/local/tmp/capture created! \n"); LOGI("/data/local/tmp/capture created!"); }; - char resolvedPath[PATH_MAX] = {0x00}; - if (realpath(savePath.c_str(), resolvedPath) == nullptr) { - std::cout << "Error: Unable to get resolved path." << std::endl; + + if (SPUtils::FileAccess(savePath)) { + std::cout << "" << std::endl; return; } - auto fd = open(resolvedPath, O_RDWR | O_CREAT, 0644); + auto fd = open(savePath.c_str(), O_RDWR | O_CREAT, 0644); SPUtils::LoadCmd("snapshot_display -f " + savePath, cmdResult); (void)close(fd); } diff --git a/host/smartperf/client/client_command/Power.cpp b/host/smartperf/client/client_command/Power.cpp index 5a98e9ab8..d62065a72 100644 --- a/host/smartperf/client/client_command/Power.cpp +++ b/host/smartperf/client/client_command/Power.cpp @@ -13,8 +13,6 @@ * limitations under the License. */ #include -#include -#include #include "include/sp_utils.h" #include "include/Power.h" #include "include/sp_log.h" @@ -24,17 +22,7 @@ std::map Power::ItemData() { std::map result; std::string currentNow; - double avgCurrent = 0.0; - SPUtils::LoadFile(currentNowPath, curAvgCurrent); - const double number = 3.6; - if (lastAvgCurrent != "0") { - int diffAvgCurrent = std::stoi(curAvgCurrent) - std::stoi(lastAvgCurrent); - avgCurrent = diffAvgCurrent * number; - } - std::stringstream ss; - ss << std::fixed << std::setprecision(1) << avgCurrent; - currentNow = ss.str(); - lastAvgCurrent = curAvgCurrent; + SPUtils::LoadFile(currentNowPath, currentNow); std::string voltageNow; SPUtils::LoadFile(voltageNowPath, voltageNow); result["currentNow"] = currentNow; diff --git a/host/smartperf/client/client_command/include/Power.h b/host/smartperf/client/client_command/include/Power.h index 9e27e36a2..19cdbaaf6 100644 --- a/host/smartperf/client/client_command/include/Power.h +++ b/host/smartperf/client/client_command/include/Power.h @@ -31,10 +31,8 @@ private: Power() {}; Power(const Power &); Power &operator = (const Power &); - const std::string currentNowPath = "/sys/class/power_supply/Battery/charge_counter"; + const std::string currentNowPath = "/sys/class/power_supply/Battery/current_now"; const std::string voltageNowPath = "/sys/class/power_supply/Battery/voltage_now"; - std::string curAvgCurrent; - std::string lastAvgCurrent = "0"; }; } } diff --git a/host/smartperf/client/client_command/include/smartperf_command.h b/host/smartperf/client/client_command/include/smartperf_command.h index b2e03d4a8..214721900 100644 --- a/host/smartperf/client/client_command/include/smartperf_command.h +++ b/host/smartperf/client/client_command/include/smartperf_command.h @@ -67,7 +67,7 @@ public: void HelpCommand(CommandHelp type) const; void HandleCommand(std::string argStr, const std::string &argStr1); int GetItemInfo(std::multimap &spMap); - void printfExecCommand(const std::map data); + void PrintfExecCommand(const std::map data) const; // 采集次数 int num = 0; // 包名 diff --git a/host/smartperf/client/client_command/profiler_fps.cpp b/host/smartperf/client/client_command/profiler_fps.cpp index 480124c41..a3f9761ff 100644 --- a/host/smartperf/client/client_command/profiler_fps.cpp +++ b/host/smartperf/client/client_command/profiler_fps.cpp @@ -183,6 +183,7 @@ void ProfilerFPS::PrintSections(int msCount, long long currTimeLast, } long long timeN = (currTimeLast - currTimeStart) / conversionTime; if (timeN == 0) { + printf("sectionsFps:%d|%lld\n", 0, currLastTime); return; } long long fpsSections = (fpsNums * conversionFps) / timeN; @@ -237,7 +238,7 @@ void ProfilerFPS::GetSectionsFps(FpsInfoProfiler &fpsInfoResult, int nums) const PrintSections(msCount, currTimeLast, currTimeStart, currLastTime); currTimeLast = currTime; printCount++; - GetSectionsPrint(printCount, currLastTime, nums, msJiange); + GetSectionsPrint(printCount, currLastTime, nums, harTime); } count++; } diff --git a/host/smartperf/client/client_command/smartperf_command.cpp b/host/smartperf/client/client_command/smartperf_command.cpp index bbf340946..20d09eda2 100644 --- a/host/smartperf/client/client_command/smartperf_command.cpp +++ b/host/smartperf/client/client_command/smartperf_command.cpp @@ -211,16 +211,18 @@ std::string SmartPerfCommand::ExecCommand() } if (callGpuCounterResult) { const std::map data = GpuCounter::GetInstance().ItemData(); - printfExecCommand(data); + PrintfExecCommand(data); SPData spdata; spdata.values.insert(data.begin(), data.end()); vmap.push_back(spdata); } std::this_thread::sleep_for(std::chrono::milliseconds(freq)); + LOGI("SmartPerfCommand::WriteCsv start"); SpCsvUtil::WriteCsv(std::string(outPath.c_str()), vmap); + LOGI("SmartPerfCommand::WriteCsv finish"); return std::string("command exec finished!"); } -void SmartPerfCommand::printfExecCommand(const std::map data) +void SmartPerfCommand::PrintfExecCommand(const std::map data) const; { int i = 0; for (auto a = data.cbegin(); a != data.cend(); ++a) { diff --git a/host/smartperf/client/client_command/sp_task.cpp b/host/smartperf/client/client_command/sp_task.cpp index 23e2c5506..ab8b0d6c0 100644 --- a/host/smartperf/client/client_command/sp_task.cpp +++ b/host/smartperf/client/client_command/sp_task.cpp @@ -228,6 +228,9 @@ ErrCode SPTask::StartTask(std::function msgTask) std::this_thread::sleep_for(std::chrono::milliseconds(curTaskInfo.freq - costTime)); } } + if (!isRunning) { + vmap.clear(); + } }); LOGI("SPTask::StartTask complete"); return ErrCode::OK; diff --git a/host/smartperf/client/client_command/sp_utils.cpp b/host/smartperf/client/client_command/sp_utils.cpp index bb6acf78c..f2281d5f0 100644 --- a/host/smartperf/client/client_command/sp_utils.cpp +++ b/host/smartperf/client/client_command/sp_utils.cpp @@ -587,7 +587,7 @@ bool SPUtils::IsHmKernel() utsname unameBuf; if ((uname(&unameBuf)) == 0) { std::string osRelease = unameBuf.release; - isHM = osRelease.find("hmkernel") != std::string::npos; + isHM = osRelease.find("HongMeng") != std::string::npos; } return isHM; } diff --git a/host/smartperf/client/client_command/stalling_rate_trace.cpp b/host/smartperf/client/client_command/stalling_rate_trace.cpp index 68e8ee884..653c509c9 100644 --- a/host/smartperf/client/client_command/stalling_rate_trace.cpp +++ b/host/smartperf/client/client_command/stalling_rate_trace.cpp @@ -91,7 +91,10 @@ void StallingRateTrace::AppList(std::string line, const std::string &signS, cons if (line.find("H:LAUNCHER_APP_LAUNCH_FROM_ICON,") != std::string::npos || line.find("H:APP_LIST_FLING,") != std::string::npos || line.find("H:WEB_LIST_FLING") != std::string::npos || - line.find("H:ABILITY_OR_PAGE_SWITCH,") != std::string::npos) { + line.find("H:ABILITY_OR_PAGE_SWITCH,") != std::string::npos || + line.find("H:APP_TRANSITION_TO_OTHER_APP,") != std::string::npos || + line.find("H:LUNCHER_APP_LUNCH_FORH_DOCK,") != std::string::npos || + line.find("H:LUNCHER_APP_LUNCH_FORM_APPCENTER,") != std::string::npos) { if (animalFlag) { dynamicFinishTime = GetTimes(line, signF); LOGI("dynamicFinishTime=====: %s", std::to_string(dynamicFinishTime).c_str()); diff --git a/host/smartperf/client/client_command/startup_delay.cpp b/host/smartperf/client/client_command/startup_delay.cpp index 8088a54d7..ffa1350fd 100644 --- a/host/smartperf/client/client_command/startup_delay.cpp +++ b/host/smartperf/client/client_command/startup_delay.cpp @@ -34,7 +34,7 @@ void StartUpDelay::GetTrace(const std::string &sessionID, const std::string &tra if (SPUtils::IsHmKernel()) { cmdString = "hitrace --trace_clock mono -t 5 -b 102400 --overwrite idle ace app ohos ability graphic nweb "; } else { - cmdString = "hitrace --trace_clock mono -t 5 -b 20480 --overwrite idle ace app ohos ability graphic nweb "; + cmdString = "hitrace --trace_clock mono -t 5 -b 204800 --overwrite idle ace app ohos ability graphic nweb "; } std::string cmdStringEnd { "sched freq sync workq multimodalinput > " }; SPUtils::LoadCmd(cmdString + cmdStringEnd + traceName, result); From 85471f7ada79413f5f34200f2b0a03daed508931 Mon Sep 17 00:00:00 2001 From: wwx1285007 Date: Fri, 21 Jun 2024 17:37:42 +0800 Subject: [PATCH 26/27] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=88=AA=E5=9B=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wwx1285007 --- host/smartperf/client/client_command/Capture.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/host/smartperf/client/client_command/Capture.cpp b/host/smartperf/client/client_command/Capture.cpp index cf141f3c7..6136f398c 100644 --- a/host/smartperf/client/client_command/Capture.cpp +++ b/host/smartperf/client/client_command/Capture.cpp @@ -95,7 +95,6 @@ void Capture::ThreadGetCatchSocket(const std::string &curTime) const if (SPUtils::FileAccess(savePath)) { std::cout << "" << std::endl; - return; } auto fd = open(savePath.c_str(), O_RDWR | O_CREAT, 0644); SPUtils::LoadCmd("snapshot_display -f " + savePath, cmdResult); From ea8a69c5a8c998ad4c9a915cabd873acc1d0694c Mon Sep 17 00:00:00 2001 From: wwx1285007 Date: Sat, 22 Jun 2024 10:47:37 +0800 Subject: [PATCH 27/27] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=88=AA=E5=9B=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wwx1285007 --- host/smartperf/client/client_command/smartperf_command.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/host/smartperf/client/client_command/smartperf_command.cpp b/host/smartperf/client/client_command/smartperf_command.cpp index 20d09eda2..b0adfc43f 100644 --- a/host/smartperf/client/client_command/smartperf_command.cpp +++ b/host/smartperf/client/client_command/smartperf_command.cpp @@ -222,7 +222,7 @@ std::string SmartPerfCommand::ExecCommand() LOGI("SmartPerfCommand::WriteCsv finish"); return std::string("command exec finished!"); } -void SmartPerfCommand::PrintfExecCommand(const std::map data) const; +void SmartPerfCommand::PrintfExecCommand(const std::map data) const { int i = 0; for (auto a = data.cbegin(); a != data.cend(); ++a) {