From bf04fc1c99e71e6533610b1dda12dc931dab4155 Mon Sep 17 00:00:00 2001 From: ganchuantao Date: Wed, 3 Sep 2025 11:56:56 +0800 Subject: [PATCH 01/11] =?UTF-8?q?=20=20=20=20cpudataplugin=20=E8=B6=85?= =?UTF-8?q?=E5=A4=A7=E5=87=BD=E6=95=B0=E6=95=B4=E6=94=B9=20=20=20=20=20Sig?= =?UTF-8?q?ned-off-by:ganchuantao1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: ganchuantao --- .../cpu_plugin/include/cpu_data_plugin.h | 2 + .../cpu_plugin/src/cpu_data_plugin.cpp | 110 ++++++++++-------- .../plugins/native_hook/test/malloc_test.cpp | 45 +++---- 3 files changed, 86 insertions(+), 71 deletions(-) diff --git a/device/plugins/cpu_plugin/include/cpu_data_plugin.h b/device/plugins/cpu_plugin/include/cpu_data_plugin.h index fad86ad2e..ef9759190 100644 --- a/device/plugins/cpu_plugin/include/cpu_data_plugin.h +++ b/device/plugins/cpu_plugin/include/cpu_data_plugin.h @@ -121,6 +121,8 @@ private: path_ = path; } void SetFreqPath(std::string path); + template bool SetSystemCpuUsage(T& cpuUsageInfo, CpuLoadData& cpuLoadData, CpuTimeData& cpuTimeData); + template bool SetCpuCoreInfo(const std::string& cpuUsageStr, T& cpuUsageInfo, CpuTimeData& cpuTimeData); private: /* data */ diff --git a/device/plugins/cpu_plugin/src/cpu_data_plugin.cpp b/device/plugins/cpu_plugin/src/cpu_data_plugin.cpp index 22bc40a46..65a13c7e0 100644 --- a/device/plugins/cpu_plugin/src/cpu_data_plugin.cpp +++ b/device/plugins/cpu_plugin/src/cpu_data_plugin.cpp @@ -432,6 +432,63 @@ bool CpuDataPlugin::GetSystemCpuTime(std::vector& cpuUsageVec, CpuT return true; } +template +bool CpuDataPlugin::SetSystemCpuUsage(T& cpuUsageInfo, CpuLoadData& cpuLoadData, CpuTimeData& cpuTimeData) +{ + cpuUsageInfo.set_prev_system_cpu_time_ms(prevCpuTimeData_.systemUsageTime); + cpuUsageInfo.set_prev_system_boot_time_ms(prevCpuTimeData_.systemBootTime); + cpuUsageInfo.set_system_cpu_time_ms(cpuTimeData.systemUsageTime); + cpuUsageInfo.set_system_boot_time_ms(cpuTimeData.systemBootTime); + bool isTest = false; + if (strncmp(path_.c_str(), "/proc/", strlen("/proc/")) != 0) { + isTest = true; // UT needs report load data for the first time + } + if ((protoConfig_.report_process_info() && prevCpuTimeData_.systemBootTime != 0) || isTest) { + cpuLoadData.userLoad = static_cast(cpuTimeData.userModeUsageTime - prevCpuTimeData_.userModeUsageTime) / + static_cast(cpuTimeData.systemBootTime - prevCpuTimeData_.systemBootTime) * + PERCENT; + cpuLoadData.sysLoad = + static_cast(cpuTimeData.systemModeUsageTime - prevCpuTimeData_.systemModeUsageTime) / + static_cast(cpuTimeData.systemBootTime - prevCpuTimeData_.systemBootTime) * PERCENT; + cpuLoadData.totalLoad = static_cast(cpuTimeData.systemUsageTime - prevCpuTimeData_.systemUsageTime) / + static_cast(cpuTimeData.systemBootTime - prevCpuTimeData_.systemBootTime) * + PERCENT; + } + prevCpuTimeData_ = cpuTimeData; + if (pid_ < 0 && protoConfig_.report_process_info()) { + return false; + } + return true; +} + +template +bool CpuDataPlugin::SetCpuCoreInfo(const std::string& cpuUsageStr, T& cpuUsageInfo, CpuTimeData& cpuTimeData) +{ + size_t cpuLength = strlen("cpu"); + std::string core = std::string(cpuUsageStr.c_str() + cpuLength, cpuUsageStr.size() - cpuLength); + if (!COMMON::IsNumeric(core)) { + PROFILER_LOG_ERROR(LOG_CORE, "WriteSystemCpuUsage core is not numeric"); + return false; + } + int32_t coreNum = atoi(core.c_str()); + // 第一次获取数据时需要将前一个数据置为0 + if (prevCoreSystemCpuTimeMap_.size() == static_cast(coreNum)) { + prevCoreSystemCpuTimeMap_[coreNum] = 0; + prevCoreSystemBootTimeMap_[coreNum] = 0; + } + auto* cpuCore = cpuUsageInfo.add_cores(); + cpuCore->set_cpu_core(coreNum); + cpuCore->set_prev_system_cpu_time_ms(prevCoreSystemCpuTimeMap_[coreNum]); + cpuCore->set_prev_system_boot_time_ms(prevCoreSystemBootTimeMap_[coreNum]); + cpuCore->set_system_cpu_time_ms(cpuTimeData.systemUsageTime); + cpuCore->set_system_boot_time_ms(cpuTimeData.systemBootTime); + + SetCpuFrequency(*cpuCore, coreNum); + prevCoreSystemCpuTimeMap_[coreNum] = cpuTimeData.systemUsageTime; + prevCoreSystemBootTimeMap_[coreNum] = cpuTimeData.systemBootTime; + return true; +} + template void CpuDataPlugin::WriteSystemCpuUsage(T& cpuUsageInfo, CpuLoadData& cpuLoadData, const char* pFile, uint32_t fileLen) { @@ -445,7 +502,6 @@ void CpuDataPlugin::WriteSystemCpuUsage(T& cpuUsageInfo, CpuLoadData& cpuLoadDat if (!totalbuffer.CurWord() || strncmp(totalbuffer.CurWord(), "cpu", cpuLength) != 0) { return; } - for (int i = 0; i < SYSTEM_STAT_COUNT; i++) { if (!totalbuffer.CurWord()) { return; @@ -454,64 +510,18 @@ void CpuDataPlugin::WriteSystemCpuUsage(T& cpuUsageInfo, CpuLoadData& cpuLoadDat cpuUsageVec.push_back(curWord); totalbuffer.NextWord(' '); } - // 获取数据失败返回 CpuTimeData cpuTimeData; if (!GetSystemCpuTime(cpuUsageVec, cpuTimeData)) { return; } - - if (strcmp(cpuUsageVec[0].c_str(), "cpu") == 0) { - cpuUsageInfo.set_prev_system_cpu_time_ms(prevCpuTimeData_.systemUsageTime); - cpuUsageInfo.set_prev_system_boot_time_ms(prevCpuTimeData_.systemBootTime); - cpuUsageInfo.set_system_cpu_time_ms(cpuTimeData.systemUsageTime); - cpuUsageInfo.set_system_boot_time_ms(cpuTimeData.systemBootTime); - bool isTest = false; - if (strncmp(path_.c_str(), "/proc/", strlen("/proc/")) != 0) { - isTest = true; // UT needs report load data for the first time - } - if ((protoConfig_.report_process_info() && prevCpuTimeData_.systemBootTime != 0) || isTest) { - cpuLoadData.userLoad = static_cast(cpuTimeData.userModeUsageTime - - prevCpuTimeData_.userModeUsageTime) / - static_cast(cpuTimeData.systemBootTime - - prevCpuTimeData_.systemBootTime) * PERCENT; - cpuLoadData.sysLoad = static_cast(cpuTimeData.systemModeUsageTime - - prevCpuTimeData_.systemModeUsageTime) / - static_cast(cpuTimeData.systemBootTime - - prevCpuTimeData_.systemBootTime) * PERCENT; - cpuLoadData.totalLoad = static_cast(cpuTimeData.systemUsageTime - - prevCpuTimeData_.systemUsageTime) / - static_cast(cpuTimeData.systemBootTime - - prevCpuTimeData_.systemBootTime) * PERCENT; - } - prevCpuTimeData_ = cpuTimeData; - if (pid_ < 0 && protoConfig_.report_process_info()) { - return; - } + if (strcmp(cpuUsageVec[0].c_str(), "cpu") == 0 && !SetSystemCpuUsage(cpuUsageInfo, cpuLoadData, cpuTimeData)) { + return; } else { - std::string core = std::string(cpuUsageVec[0].c_str() + cpuLength, cpuUsageVec[0].size() - cpuLength); - if (!COMMON::IsNumeric(core)) { - PROFILER_LOG_ERROR(LOG_CORE, "WriteSystemCpuUsage core is not numeric"); + if (!SetCpuCoreInfo(cpuUsageVec[0], cpuUsageInfo, cpuTimeData)) { return; } - int32_t coreNum = atoi(core.c_str()); - // 第一次获取数据时需要将前一个数据置为0 - if (prevCoreSystemCpuTimeMap_.size() == static_cast(coreNum)) { - prevCoreSystemCpuTimeMap_[coreNum] = 0; - prevCoreSystemBootTimeMap_[coreNum] = 0; - } - auto* cpuCore = cpuUsageInfo.add_cores(); - cpuCore->set_cpu_core(coreNum); - cpuCore->set_prev_system_cpu_time_ms(prevCoreSystemCpuTimeMap_[coreNum]); - cpuCore->set_prev_system_boot_time_ms(prevCoreSystemBootTimeMap_[coreNum]); - cpuCore->set_system_cpu_time_ms(cpuTimeData.systemUsageTime); - cpuCore->set_system_boot_time_ms(cpuTimeData.systemBootTime); - - SetCpuFrequency(*cpuCore, coreNum); - prevCoreSystemCpuTimeMap_[coreNum] = cpuTimeData.systemUsageTime; - prevCoreSystemBootTimeMap_[coreNum] = cpuTimeData.systemBootTime; } - cpuUsageVec.clear(); } } diff --git a/device/plugins/native_hook/test/malloc_test.cpp b/device/plugins/native_hook/test/malloc_test.cpp index 41a563c41..6f7909156 100644 --- a/device/plugins/native_hook/test/malloc_test.cpp +++ b/device/plugins/native_hook/test/malloc_test.cpp @@ -491,23 +491,10 @@ static int CommandParse(int argc, char** argv) } return opterr; } -} // namespace -int main(int argc, char* argv[]) -{ - // 参数解析 - int ret = CommandParse(argc, argv); - if (ret == -1) { - return 0; - } - int typeNum = BitMapNum(g_hookFlag); - printf(" g_hookFlag = [%u] \n", g_hookFlag); - if (typeNum == 0) { - // 未设置type时默认启动alloc - g_hookFlag |= ALLOC_FLAG; - typeNum++; - } +static pthread_t** CreateThreadArray(int typeNum) +{ pthread_t** thrArrayList = static_cast(malloc(sizeof(pthread_t*) * typeNum)); if (thrArrayList == nullptr) { printf("malloc thrArrayList fail\n"); @@ -528,8 +515,8 @@ int main(int argc, char* argv[]) } int idx; for (idx = 0; idx < threadNum; ++idx) { - int result = pthread_create((thrArrayList[type]) + idx, nullptr, - ThreadFuncC, static_cast(&mallocSize)); + int result = + pthread_create((thrArrayList[type]) + idx, nullptr, ThreadFuncC, static_cast(&mallocSize)); if (result != 0) { printf("Creating thread failed.\n"); } @@ -541,7 +528,6 @@ int main(int argc, char* argv[]) int threadNum = g_threadNum; // 初始化 MmapInit(); - thrArrayList[type] = static_cast(malloc(sizeof(pthread_t) * threadNum)); if (thrArrayList[type] == nullptr) { printf("new thread failed.\n"); @@ -549,20 +535,37 @@ int main(int argc, char* argv[]) int idx; for (idx = 0; idx < threadNum; ++idx) { - int result = pthread_create((thrArrayList[type]) + idx, - nullptr, ThreadMmap, nullptr); + int result = pthread_create((thrArrayList[type]) + idx, nullptr, ThreadMmap, nullptr); if (result != 0) { printf("Creating thread failed.\n"); } } } + return thrArrayList; +} +} // namespace +int main(int argc, char* argv[]) +{ + // 参数解析 + int ret = CommandParse(argc, argv); + if (ret == -1) { + return 0; + } + int typeNum = BitMapNum(g_hookFlag); + printf(" g_hookFlag = [%u] \n", g_hookFlag); + if (typeNum == 0) { + // 未设置type时默认启动alloc + g_hookFlag |= ALLOC_FLAG; + typeNum++; + } + pthread_t** thrArrayList = CreateThreadArray(typeNum); while (getchar() != '\n') { usleep(RESPONSE_SPEED); }; g_runing = 0; int idx; - for (type = 0; type < typeNum; type++) { + for (int type = 0; type < typeNum; type++) { for (idx = 0; idx < g_threadNum; ++idx) { pthread_join((thrArrayList[type])[idx], nullptr); } -- Gitee From aa3a7f2d2b5318dfb043f1ef5a655c2a78e06690 Mon Sep 17 00:00:00 2001 From: ganchuantao Date: Wed, 3 Sep 2025 16:20:34 +0800 Subject: [PATCH 02/11] =?UTF-8?q?=20=20=20=20cpudataplugin=20=E8=B6=85?= =?UTF-8?q?=E5=A4=A7=E5=87=BD=E6=95=B0=E6=95=B4=E6=94=B9=20=20=20=20=20Sig?= =?UTF-8?q?ned-off-by:ganchuantao1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: ganchuantao --- device/plugins/diskio_plugin/src/io_stats.cpp | 95 ++++++++++--------- .../plugins/diskio_plugin/src/test_main.cpp | 95 +++++++++---------- 2 files changed, 95 insertions(+), 95 deletions(-) diff --git a/device/plugins/diskio_plugin/src/io_stats.cpp b/device/plugins/diskio_plugin/src/io_stats.cpp index abc6b7ee3..3d11ec159 100644 --- a/device/plugins/diskio_plugin/src/io_stats.cpp +++ b/device/plugins/diskio_plugin/src/io_stats.cpp @@ -155,6 +155,54 @@ bool IoStats::ParseIoStats() return true; } +void IoStats::SetIoInfo(std::shared_ptr& ioInfo, const std::string& name) +{ + int index = 0; + ioInfo->major_ = fields_[index]; + index++; + ioInfo->minor_ = fields_[index]; + index++; + ioInfo->deviceName_ = name; + + ioInfo->rSucc_ = fields_[index]; + index++; + ioInfo->rMerged_ = fields_[index]; + index++; + ioInfo->rSectors_ = fields_[index]; + index++; + ioInfo->timeOfRead_ = fields_[index]; + index++; + + ioInfo->wSucc_ = fields_[index]; + index++; + ioInfo->wMerged_ = fields_[index]; + index++; + ioInfo->wSectors_ = fields_[index]; + index++; + ioInfo->timeOfWrite_ = fields_[index]; + index++; + + ioInfo->ios_ = fields_[index]; + index++; + ioInfo->timeOfIo_ = fields_[index]; + index++; + ioInfo->weighted_ = fields_[index]; + index++; + + ioInfo->dSucc_ = fields_[index]; + index++; + ioInfo->dMerged_ = fields_[index]; + index++; + ioInfo->dSectors_ = fields_[index]; + index++; + ioInfo->timeOfd_ = fields_[index]; + index++; + + ioInfo->flushSucc_ = fields_[index]; + index++; + ioInfo->timeOfFlush_ = fields_[index]; +} + bool IoStats::GetIoStats(std::string& line) { std::string name; @@ -162,51 +210,7 @@ bool IoStats::GetIoStats(std::string& line) CHECK_NOTNULL(ioInfo, false, "create DiskStats FAILED!"); if (ParseLineFields(line, name) > 0) { - int index = 0; - ioInfo->major_ = fields_[index]; - index++; - ioInfo->minor_ = fields_[index]; - index++; - ioInfo->deviceName_ = name; - - ioInfo->rSucc_ = fields_[index]; - index++; - ioInfo->rMerged_ = fields_[index]; - index++; - ioInfo->rSectors_ = fields_[index]; - index++; - ioInfo->timeOfRead_ = fields_[index]; - index++; - - ioInfo->wSucc_ = fields_[index]; - index++; - ioInfo->wMerged_ = fields_[index]; - index++; - ioInfo->wSectors_ = fields_[index]; - index++; - ioInfo->timeOfWrite_ = fields_[index]; - index++; - - ioInfo->ios_ = fields_[index]; - index++; - ioInfo->timeOfIo_ = fields_[index]; - index++; - ioInfo->weighted_ = fields_[index]; - index++; - - ioInfo->dSucc_ = fields_[index]; - index++; - ioInfo->dMerged_ = fields_[index]; - index++; - ioInfo->dSectors_ = fields_[index]; - index++; - ioInfo->timeOfd_ = fields_[index]; - index++; - - ioInfo->flushSucc_ = fields_[index]; - index++; - ioInfo->timeOfFlush_ = fields_[index]; - + SetIoInfo(ioInfo, name); ioDatas_.push_back(ioInfo); fields_.clear(); return true; @@ -238,7 +242,6 @@ bool IoStats::GetIoStats(std::string& line) debugIoInfo->deviceName_ = std::string(name); ioDatas_.push_back(debugIoInfo); #endif - return false; } diff --git a/device/plugins/diskio_plugin/src/test_main.cpp b/device/plugins/diskio_plugin/src/test_main.cpp index 1f845f607..8f10bd848 100644 --- a/device/plugins/diskio_plugin/src/test_main.cpp +++ b/device/plugins/diskio_plugin/src/test_main.cpp @@ -53,6 +53,51 @@ void IoTest() std::string command = "rm " + writeFile; system(command.c_str()); } + +static void PrintDiskStats() +{ + DiskioConfig protoConfig; + PluginModuleStruct* diskioPlugin; + void* handle = dlopen("libdiskiodataplugin.z.so", RTLD_LAZY); + if (handle == nullptr) { + std::cout << "test:dlopen err: " << dlerror() << std::endl; + return; + } + std::cout << "test:handle = " << handle << std::endl; + diskioPlugin = (PluginModuleStruct*)dlsym(handle, "g_pluginModule"); + std::cout << "test:name = " << diskioPlugin->name << std::endl; + std::cout << "test:buffer size = " << diskioPlugin->resultBufferSizeHint << std::endl; + // Serialize config + int configLength = protoConfig.ByteSizeLong(); + std::vector configBuffer(configLength); + int ret = protoConfig.SerializeToArray(configBuffer.data(), configBuffer.size()); + std::cout << "test:configLength = " << configLength << std::endl; + std::cout << "test:serialize success start plugin ret = " << ret << std::endl; + // Start + std::vector dataBuffer(diskioPlugin->resultBufferSizeHint); + diskioPlugin->callbacks->onPluginSessionStart(configBuffer.data(), configLength); + while (g_testCount--) { + int len = diskioPlugin->callbacks->onPluginReportResult(dataBuffer.data(), diskioPlugin->resultBufferSizeHint); + std::cout << "test:filler buffer length = " << len << std::endl; + if (len > 0) { + DiskioData diskioData; + diskioData.ParseFromArray(dataBuffer.data(), len); + std::cout << "test:ParseFromArray length = " << len << std::endl; + std::cout << "prev_rd_sectors_kb:" << diskioData.prev_rd_sectors_kb() << std::endl; + std::cout << "prev_wr_sectors_kb:" << diskioData.prev_wr_sectors_kb() << std::endl; + std::cout << "prev_timestamp.tv_sec:" << diskioData.prev_timestamp().tv_sec() << std::endl; + std::cout << "prev_timestamp.tv_nsec:" << diskioData.prev_timestamp().tv_nsec() << std::endl; + std::cout << "rd_sectors_kb:" << diskioData.rd_sectors_kb() << std::endl; + std::cout << "wr_sectors_kb:" << diskioData.wr_sectors_kb() << std::endl; + std::cout << "timestamp.tv_sec:" << diskioData.timestamp().tv_sec() << std::endl; + std::cout << "timestamp.tv_nsec:" << diskioData.timestamp().tv_nsec() << std::endl; + } + std::cout << "test:sleep...................." << std::endl; + sleep(1); + } + diskioPlugin->callbacks->onPluginSessionStop(); + dlclose(handle); +} } // namespace int main(int agrc, char* agrv[]) @@ -61,59 +106,11 @@ int main(int agrc, char* agrv[]) for (int i = 1; i < agrc; i++) { isTestDiskIO = atoi(agrv[i]); } - if (isTestDiskIO) { IoTest(); sleep(SLEEP_TIME); } else { - DiskioConfig protoConfig; - PluginModuleStruct* diskioPlugin; - void* handle = dlopen("libdiskiodataplugin.z.so", RTLD_LAZY); - if (handle == nullptr) { - std::cout << "test:dlopen err: " << dlerror() << std::endl; - return 0; - } - std::cout << "test:handle = " << handle << std::endl; - diskioPlugin = (PluginModuleStruct*)dlsym(handle, "g_pluginModule"); - std::cout << "test:name = " << diskioPlugin->name << std::endl; - std::cout << "test:buffer size = " << diskioPlugin->resultBufferSizeHint << std::endl; - - // Serialize config - int configLength = protoConfig.ByteSizeLong(); - std::vector configBuffer(configLength); - int ret = protoConfig.SerializeToArray(configBuffer.data(), configBuffer.size()); - std::cout << "test:configLength = " << configLength << std::endl; - std::cout << "test:serialize success start plugin ret = " << ret << std::endl; - - // Start - std::vector dataBuffer(diskioPlugin->resultBufferSizeHint); - diskioPlugin->callbacks->onPluginSessionStart(configBuffer.data(), configLength); - while (g_testCount--) { - int len = diskioPlugin->callbacks->onPluginReportResult(dataBuffer.data(), - diskioPlugin->resultBufferSizeHint); - std::cout << "test:filler buffer length = " << len << std::endl; - - if (len > 0) { - DiskioData diskioData; - diskioData.ParseFromArray(dataBuffer.data(), len); - std::cout << "test:ParseFromArray length = " << len << std::endl; - - std::cout << "prev_rd_sectors_kb:" << diskioData.prev_rd_sectors_kb() << std::endl; - std::cout << "prev_wr_sectors_kb:" << diskioData.prev_wr_sectors_kb() << std::endl; - std::cout << "prev_timestamp.tv_sec:" << diskioData.prev_timestamp().tv_sec() << std::endl; - std::cout << "prev_timestamp.tv_nsec:" << diskioData.prev_timestamp().tv_nsec() << std::endl; - std::cout << "rd_sectors_kb:" << diskioData.rd_sectors_kb() << std::endl; - std::cout << "wr_sectors_kb:" << diskioData.wr_sectors_kb() << std::endl; - std::cout << "timestamp.tv_sec:" << diskioData.timestamp().tv_sec() << std::endl; - std::cout << "timestamp.tv_nsec:" << diskioData.timestamp().tv_nsec() << std::endl; - } - - std::cout << "test:sleep...................." << std::endl; - sleep(1); - } - diskioPlugin->callbacks->onPluginSessionStop(); - dlclose(handle); + PrintDiskStats(); } - return 0; } -- Gitee From 86b1bc918c385a19c31c710617813052cbf17992 Mon Sep 17 00:00:00 2001 From: ganchuantao Date: Wed, 3 Sep 2025 16:54:55 +0800 Subject: [PATCH 03/11] =?UTF-8?q?=20=20=20=20ffrt=20plugin=E8=B6=85?= =?UTF-8?q?=E5=A4=A7=E5=87=BD=E6=95=B0=E6=95=B4=E6=94=B9=20=20=20=20=20Sig?= =?UTF-8?q?ned-off-by:ganchuantao1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: ganchuantao --- .../service/include/ffrt_profiler_manager.h | 3 ++ .../service/src/ffrt_profiler_manager.cpp | 34 +++++++++++++++---- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/device/plugins/ffrt_profiler/service/include/ffrt_profiler_manager.h b/device/plugins/ffrt_profiler/service/include/ffrt_profiler_manager.h index da7222ae6..59299a4fa 100644 --- a/device/plugins/ffrt_profiler/service/include/ffrt_profiler_manager.h +++ b/device/plugins/ffrt_profiler/service/include/ffrt_profiler_manager.h @@ -83,6 +83,9 @@ private: bool CheckConfig(); bool HandleFfrtProfilerContext(const std::shared_ptr& ctx); clockid_t GetClockId(FfrtProfilerConfig::ClockId clockType); + bool CheckPid(std::set& pidCache); + bool CheckStartupProcessName(); + bool CheckRestartProcessName(std::set& pidCache); private: std::shared_ptr socketService_{nullptr}; diff --git a/device/plugins/ffrt_profiler/service/src/ffrt_profiler_manager.cpp b/device/plugins/ffrt_profiler/service/src/ffrt_profiler_manager.cpp index 20fb477c3..b150df0f9 100644 --- a/device/plugins/ffrt_profiler/service/src/ffrt_profiler_manager.cpp +++ b/device/plugins/ffrt_profiler/service/src/ffrt_profiler_manager.cpp @@ -56,9 +56,8 @@ void FfrtProfilerManager::Init() RegisterAgentPlugin("ffrt-profiler"); } -bool FfrtProfilerManager::CheckConfig() +bool FfrtProfilerManager::CheckPid(std::set& pidCache) { - std::set pidCache; for (const auto& pid : config_.pid()) { if (pid > 0) { struct stat statBuf; @@ -76,7 +75,11 @@ bool FfrtProfilerManager::CheckConfig() } } } + return true; +} +bool FfrtProfilerManager::CheckStartupProcessName() +{ for (const auto& name : config_.startup_process_name()) { if (name.empty()) { continue; @@ -91,20 +94,23 @@ bool FfrtProfilerManager::CheckConfig() ffrtCtx_.emplace_back(std::make_shared(name)); } } + return true; +} +bool FfrtProfilerManager::CheckRestartProcessName(std::set& pidCache) +{ for (const auto& name : config_.restart_process_name()) { if (name.empty()) { continue; } - int pidValue = -1; bool isExist = COMMON::IsProcessExist(name, pidValue); if (isExist) { auto [iter, ret] = pidCache.emplace(pidValue); if (!ret) { PROFILER_LOG_ERROR(LOG_CORE, - "FfrtProfilerManager process %s pid is %d, duplicate of pid list in config", - name.c_str(), pidValue); + "FfrtProfilerManager process %s pid is %d, duplicate of pid list in config", + name.c_str(), pidValue); return false; } paramValue_ += name + ","; @@ -114,11 +120,27 @@ bool FfrtProfilerManager::CheckConfig() return false; } } + return true; +} +bool FfrtProfilerManager::CheckConfig() +{ + std::set pidCache; + if (!CheckPid(pidCache)) { + PROFILER_LOG_ERROR(LOG_CORE, "CheckPid failed"); + return false; + } + if (!CheckStartupProcessName()) { + PROFILER_LOG_ERROR(LOG_CORE, "CheckStartupProcessName failed"); + return false; + } + if (!CheckRestartProcessName(pidCache)) { + PROFILER_LOG_ERROR(LOG_CORE, "CheckRestartProcessName failed"); + return false; + } if (config_.flush_interval() == 0) { config_.set_flush_interval(1); } - if (config_.clock_id() == FfrtProfilerConfig::UNKNOW) { PROFILER_LOG_ERROR(LOG_CORE, "FfrtProfilerManager clock_id is unknow"); return false; -- Gitee From 05758b28c00a19dbc33ae0f5bf865d90252218e4 Mon Sep 17 00:00:00 2001 From: ganchuantao Date: Thu, 4 Sep 2025 17:16:26 +0800 Subject: [PATCH 04/11] =?UTF-8?q?=20=20=20=20ebpf=20convert=20=E8=B6=85?= =?UTF-8?q?=E5=A4=A7=E5=87=BD=E6=95=B0=E6=95=B4=E6=94=B9=20=20=20=20=20Sig?= =?UTF-8?q?ned-off-by:ganchuantao1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: ganchuantao --- .../tools/include/ebpf_converter.h | 2 + .../tools/src/ebpf_converter.cpp | 93 +++++++++++-------- 2 files changed, 58 insertions(+), 37 deletions(-) diff --git a/device/plugins/hiebpf_plugin/tools/include/ebpf_converter.h b/device/plugins/hiebpf_plugin/tools/include/ebpf_converter.h index 2535ba671..8507876be 100644 --- a/device/plugins/hiebpf_plugin/tools/include/ebpf_converter.h +++ b/device/plugins/hiebpf_plugin/tools/include/ebpf_converter.h @@ -37,6 +37,8 @@ private: void EventMemParsing(); void EventStrParsing(); void EventBIOParsing(); + void WriteEventParsingToFile(FILE *file); + bool ReadMagicHeader(); std::pair> GetSymbolInfo(uint64_t pid, uint64_t ip); public: static std::pair CheckNotExistsFilePath(const std::string& filePath); diff --git a/device/plugins/hiebpf_plugin/tools/src/ebpf_converter.cpp b/device/plugins/hiebpf_plugin/tools/src/ebpf_converter.cpp index 6ad1f455a..397644747 100644 --- a/device/plugins/hiebpf_plugin/tools/src/ebpf_converter.cpp +++ b/device/plugins/hiebpf_plugin/tools/src/ebpf_converter.cpp @@ -91,44 +91,8 @@ EbpfConverter::~EbpfConverter() } } -void EbpfConverter::StartParsing() +void EbpfConverter::WriteEventParsingToFile(FILE *file) { - if (access(inputPath_.c_str(), R_OK) != 0) { - std::cout << "the input file path is invalid" << std::endl; - return; - } - fd_ = open(inputPath_.c_str(), O_RDONLY); - if (fd_ < 0) { - std::cout << "open " << inputPath_ << " failed" << std::endl; - return; - } - char magic[HEADER_MAGIC + 1]; - if (memset_s(magic, sizeof(magic), 0, sizeof(magic)) != EOK) { - close(fd_); - std::cout << "memset_s error at StartParsing" << std::endl; - return; - } - CHK(Read(reinterpret_cast(&magic), sizeof(magic) - 1)); - outData_ << "magic: " << magic << '\n'; - HeaderDataItem header = {}; - CHK(Read(reinterpret_cast(&header), sizeof(header))); - outData_ << "headSize: " << header.headSize << '\n' << "version: " << header.version << '\n' - << "clock: " << header.clock << '\n' << "cmdLineLen: " << header.cmdLineLen; - - char cmdline[header.cmdLineLen + 1]; - if (header.cmdLineLen > 0) { - size_t dataLen = sizeof(cmdline) > 1 ? static_cast(sizeof(cmdline) - 1) : 0; - CHK(Read(reinterpret_cast(cmdline), dataLen)); - outData_ << "\ncmdline: " << cmdline << '\n'; - } - fileSize_ = lseek(fd_, header.headSize, SEEK_SET); - - FILE *file = fopen(outputPath_.c_str(), "w"); - if (file == nullptr) { - std::cout << "create " << outputPath_ << " failed" << std::endl; - return; - } - while (true) { uint32_t type = 0; if (read(fd_, reinterpret_cast(&type), sizeof(type)) <= 0) { @@ -176,6 +140,61 @@ void EbpfConverter::StartParsing() } fd_ = -1; fileSize_ = 0; +} + +bool EbpfConverter::ReadMagicHeader() +{ + if (access(inputPath_.c_str(), R_OK) != 0) { + std::cout << "the input file path is invalid" << std::endl; + return false; + } + fd_ = open(inputPath_.c_str(), O_RDONLY); + if (fd_ < 0) { + std::cout << "open " << inputPath_ << " failed" << std::endl; + return false; + } + char magic[HEADER_MAGIC + 1]; + if (memset_s(magic, sizeof(magic), 0, sizeof(magic)) != EOK) { + close(fd_); + std::cout << "memset_s error at StartParsing" << std::endl; + return false; + } + if (!Read(reinterpret_cast(&magic), sizeof(magic) - 1)) { + close(fd_); + return false; + } + outData_ << "magic: " << magic << '\n'; + HeaderDataItem header = {}; + if (!Read(reinterpret_cast(&header), sizeof(header))) { + close(fd_); + return false; + } + outData_ << "headSize: " << header.headSize << '\n' << "version: " << header.version << '\n' + << "clock: " << header.clock << '\n' << "cmdLineLen: " << header.cmdLineLen; + char cmdline[header.cmdLineLen + 1]; + if (header.cmdLineLen > 0) { + size_t dataLen = sizeof(cmdline) > 1 ? static_cast(sizeof(cmdline) - 1) : 0; + if (!Read(reinterpret_cast(cmdline), dataLen)) { + close(fd_); + return false; + } + outData_ << "\ncmdline: " << cmdline << '\n'; + } + fileSize_ = lseek(fd_, header.headSize, SEEK_SET); + return true; +} + +void EbpfConverter::StartParsing() +{ + if (!ReadMagicHeader()) { + return; + } + FILE *file = fopen(outputPath_.c_str(), "w"); + if (file == nullptr) { + std::cout << "create " << outputPath_ << " failed" << std::endl; + return; + } + WriteEventParsingToFile(file); std::cout << "Data read successfully, output..." << std::endl; size_t len = outData_.str().size(); if (fwrite(outData_.str().c_str(), 1, len, file) != len) { -- Gitee From e5c1dcf4599d03275490632a18ae348ac9c3ebb0 Mon Sep 17 00:00:00 2001 From: ganchuantao Date: Fri, 5 Sep 2025 14:19:47 +0800 Subject: [PATCH 05/11] =?UTF-8?q?=20=20=20=20=E4=BC=98=E5=8C=96=E8=B6=85?= =?UTF-8?q?=E5=A4=A7=E5=87=BD=E6=95=B0=20=20=20=20=20Signed-off-by:ganchua?= =?UTF-8?q?ntao1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: ganchuantao --- device/plugins/diskio_plugin/include/io_stats.h | 1 + 1 file changed, 1 insertion(+) diff --git a/device/plugins/diskio_plugin/include/io_stats.h b/device/plugins/diskio_plugin/include/io_stats.h index 913b349b6..a27f1fae7 100644 --- a/device/plugins/diskio_plugin/include/io_stats.h +++ b/device/plugins/diskio_plugin/include/io_stats.h @@ -227,6 +227,7 @@ private: bool RemoveSpaces(char** p); uint32_t ParseLineFields(const std::string& line); uint32_t ParseLineFields(const std::string& line, std::string& name); + void SetIoInfo(std::shared_ptr& ioInfo, const std::string& name); private: std::mutex mutex_; -- Gitee From 71210eaec9b7248f5f226a20044f00a5aac64d9f Mon Sep 17 00:00:00 2001 From: ganchuantao Date: Sat, 6 Sep 2025 15:05:40 +0800 Subject: [PATCH 06/11] =?UTF-8?q?=20=20=20=20=E4=BF=AE=E6=94=B9=E8=B6=85?= =?UTF-8?q?=E5=A4=A7=E5=87=BD=E6=95=B0=20=20=20=20=20Signed-off-by:ganchua?= =?UTF-8?q?ntao1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: ganchuantao --- .../cpu_plugin/include/cpu_data_plugin.h | 8 +++--- .../service/src/ffrt_profiler_manager.cpp | 27 ++++++++++--------- .../plugins/native_hook/test/malloc_test.cpp | 6 ++++- 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/device/plugins/cpu_plugin/include/cpu_data_plugin.h b/device/plugins/cpu_plugin/include/cpu_data_plugin.h index ef9759190..64e488d5c 100644 --- a/device/plugins/cpu_plugin/include/cpu_data_plugin.h +++ b/device/plugins/cpu_plugin/include/cpu_data_plugin.h @@ -121,10 +121,12 @@ private: path_ = path; } void SetFreqPath(std::string path); - template bool SetSystemCpuUsage(T& cpuUsageInfo, CpuLoadData& cpuLoadData, CpuTimeData& cpuTimeData); - template bool SetCpuCoreInfo(const std::string& cpuUsageStr, T& cpuUsageInfo, CpuTimeData& cpuTimeData); + template + bool SetSystemCpuUsage(T& cpuUsageInfo, CpuLoadData& cpuLoadData, CpuTimeData& cpuTimeData); + template + bool SetCpuCoreInfo(const std::string& cpuUsageStr, T& cpuUsageInfo, CpuTimeData& cpuTimeData); -private: + private: /* data */ CpuConfig protoConfig_; void* buffer_; diff --git a/device/plugins/ffrt_profiler/service/src/ffrt_profiler_manager.cpp b/device/plugins/ffrt_profiler/service/src/ffrt_profiler_manager.cpp index b150df0f9..3ccb45649 100644 --- a/device/plugins/ffrt_profiler/service/src/ffrt_profiler_manager.cpp +++ b/device/plugins/ffrt_profiler/service/src/ffrt_profiler_manager.cpp @@ -59,20 +59,21 @@ void FfrtProfilerManager::Init() bool FfrtProfilerManager::CheckPid(std::set& pidCache) { for (const auto& pid : config_.pid()) { - if (pid > 0) { - struct stat statBuf; - std::string pidPath = "/proc/" + std::to_string(pid) + "/status"; - if (stat(pidPath.c_str(), &statBuf) != 0) { - PROFILER_LOG_ERROR(LOG_CORE, "%s: hook process does not exist", __func__); - return false; - } else { - auto [iter, ret] = pidCache.emplace(pid); - if (ret) { - ffrtCtx_.emplace_back(std::make_shared(pid)); - paramValue_ += std::to_string(pid) + ","; - } - continue; + if (pid <= 0) { + return false; + } + struct stat statBuf; + std::string pidPath = "/proc/" + std::to_string(pid) + "/status"; + if (stat(pidPath.c_str(), &statBuf) != 0) { + PROFILER_LOG_ERROR(LOG_CORE, "%s: hook process does not exist", __func__); + return false; + } else { + auto [iter, ret] = pidCache.emplace(pid); + if (ret) { + ffrtCtx_.emplace_back(std::make_shared(pid)); + paramValue_ += std::to_string(pid) + ","; } + continue; } } return true; diff --git a/device/plugins/native_hook/test/malloc_test.cpp b/device/plugins/native_hook/test/malloc_test.cpp index 6f7909156..0f71ddf92 100644 --- a/device/plugins/native_hook/test/malloc_test.cpp +++ b/device/plugins/native_hook/test/malloc_test.cpp @@ -495,10 +495,14 @@ static int CommandParse(int argc, char** argv) static pthread_t** CreateThreadArray(int typeNum) { + if (typeNum <= 0) { + printf("fail:malloc %d memory", typeNum); + return nullptr; + } pthread_t** thrArrayList = static_cast(malloc(sizeof(pthread_t*) * typeNum)); if (thrArrayList == nullptr) { printf("malloc thrArrayList fail\n"); - return 0; + return nullptr; } int type = 0; if ((g_hookFlag & ALLOC_FLAG) != 0) { -- Gitee From 525039d8dc1d154b60de2b17bb21a66a5283dabd Mon Sep 17 00:00:00 2001 From: ganchuantao Date: Sat, 6 Sep 2025 15:16:24 +0800 Subject: [PATCH 07/11] =?UTF-8?q?=20=20=20=20=E4=BF=AE=E6=94=B9=E8=B6=85?= =?UTF-8?q?=E5=A4=A7=E5=87=BD=E6=95=B0=20=20=20=20=20Signed-off-by:ganchua?= =?UTF-8?q?ntao1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: ganchuantao --- device/plugins/hiebpf_plugin/tools/src/ebpf_converter.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/device/plugins/hiebpf_plugin/tools/src/ebpf_converter.cpp b/device/plugins/hiebpf_plugin/tools/src/ebpf_converter.cpp index 397644747..ef0b93fe5 100644 --- a/device/plugins/hiebpf_plugin/tools/src/ebpf_converter.cpp +++ b/device/plugins/hiebpf_plugin/tools/src/ebpf_converter.cpp @@ -93,11 +93,8 @@ EbpfConverter::~EbpfConverter() void EbpfConverter::WriteEventParsingToFile(FILE *file) { - while (true) { - uint32_t type = 0; - if (read(fd_, reinterpret_cast(&type), sizeof(type)) <= 0) { - break; - } + uint32_t type = 0; + while (read(fd_, reinterpret_cast(&type), sizeof(type)) > 0) { switch (type) { case MAPSTRACE: { EventMapsParsing(); -- Gitee From 9a28a6d8c7003af0247696f56a80858c90f5d76f Mon Sep 17 00:00:00 2001 From: ganchuantao Date: Tue, 9 Sep 2025 17:23:21 +0800 Subject: [PATCH 08/11] =?UTF-8?q?=20=20=20=20=E8=B6=85=E5=A4=A7=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E6=95=B4=E6=94=B9=20=20=20=20=20Signed-off-by:ganchua?= =?UTF-8?q?ntao1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: ganchuantao --- .../plugins/ffrt_profiler/service/src/ffrt_profiler_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/device/plugins/ffrt_profiler/service/src/ffrt_profiler_manager.cpp b/device/plugins/ffrt_profiler/service/src/ffrt_profiler_manager.cpp index 3ccb45649..f08a2bb43 100644 --- a/device/plugins/ffrt_profiler/service/src/ffrt_profiler_manager.cpp +++ b/device/plugins/ffrt_profiler/service/src/ffrt_profiler_manager.cpp @@ -60,7 +60,7 @@ bool FfrtProfilerManager::CheckPid(std::set& pidCache) { for (const auto& pid : config_.pid()) { if (pid <= 0) { - return false; + continue; } struct stat statBuf; std::string pidPath = "/proc/" + std::to_string(pid) + "/status"; -- Gitee From 57ad948755d389180934de486a778e17f43ba66d Mon Sep 17 00:00:00 2001 From: ganchuantao Date: Wed, 10 Sep 2025 11:42:37 +0800 Subject: [PATCH 09/11] =?UTF-8?q?=20=20=20=20=E8=B6=85=E5=A4=A7=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E6=95=B4=E6=94=B9=20=20=20=20=20Signed-off-by:ganchua?= =?UTF-8?q?ntao1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: ganchuantao --- device/plugins/cpu_plugin/src/cpu_data_plugin.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/device/plugins/cpu_plugin/src/cpu_data_plugin.cpp b/device/plugins/cpu_plugin/src/cpu_data_plugin.cpp index 65a13c7e0..48968c991 100644 --- a/device/plugins/cpu_plugin/src/cpu_data_plugin.cpp +++ b/device/plugins/cpu_plugin/src/cpu_data_plugin.cpp @@ -515,8 +515,10 @@ void CpuDataPlugin::WriteSystemCpuUsage(T& cpuUsageInfo, CpuLoadData& cpuLoadDat if (!GetSystemCpuTime(cpuUsageVec, cpuTimeData)) { return; } - if (strcmp(cpuUsageVec[0].c_str(), "cpu") == 0 && !SetSystemCpuUsage(cpuUsageInfo, cpuLoadData, cpuTimeData)) { - return; + if (strcmp(cpuUsageVec[0].c_str(), "cpu") == 0) { + if (!SetSystemCpuUsage(cpuUsageInfo, cpuLoadData, cpuTimeData)) { + return; + } } else { if (!SetCpuCoreInfo(cpuUsageVec[0], cpuUsageInfo, cpuTimeData)) { return; -- Gitee From 424fb2ab568648d67cfa814ab13bfe72241d21d9 Mon Sep 17 00:00:00 2001 From: ganchuantao Date: Wed, 10 Sep 2025 11:49:48 +0800 Subject: [PATCH 10/11] =?UTF-8?q?=20=20=20=20=E4=BF=AE=E6=94=B9=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=20=20=20=20=20Signed-off-by:ganchuantao1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: ganchuantao --- device/plugins/cpu_plugin/include/cpu_data_plugin.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/device/plugins/cpu_plugin/include/cpu_data_plugin.h b/device/plugins/cpu_plugin/include/cpu_data_plugin.h index 64e488d5c..961e026e0 100644 --- a/device/plugins/cpu_plugin/include/cpu_data_plugin.h +++ b/device/plugins/cpu_plugin/include/cpu_data_plugin.h @@ -126,7 +126,7 @@ private: template bool SetCpuCoreInfo(const std::string& cpuUsageStr, T& cpuUsageInfo, CpuTimeData& cpuTimeData); - private: +private: /* data */ CpuConfig protoConfig_; void* buffer_; -- Gitee From f85b05573b9b941b8a384257c4feb1a6f0cc10b2 Mon Sep 17 00:00:00 2001 From: ganchuantao Date: Fri, 12 Sep 2025 09:04:58 +0800 Subject: [PATCH 11/11] =?UTF-8?q?=20=20=20=20=E8=A1=A5=E5=85=85=E7=94=A8?= =?UTF-8?q?=E4=BE=8B=20=20=20=20=20Signed-off-by:ganchuantao1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: ganchuantao --- .../unittest/cpu_data_plugin_unittest.cpp | 26 +++++++++++++++++++ .../unittest/diskio_data_plugin_unittest.cpp | 5 ++++ .../test/unittest/ffrt_profiler_test.cpp | 23 ++++++++++++++++ 3 files changed, 54 insertions(+) diff --git a/device/plugins/cpu_plugin/test/unittest/cpu_data_plugin_unittest.cpp b/device/plugins/cpu_plugin/test/unittest/cpu_data_plugin_unittest.cpp index e2ae0d138..e9dcb81df 100644 --- a/device/plugins/cpu_plugin/test/unittest/cpu_data_plugin_unittest.cpp +++ b/device/plugins/cpu_plugin/test/unittest/cpu_data_plugin_unittest.cpp @@ -976,4 +976,30 @@ HWTEST_F(CpuDataPluginTest, TestPid, TestSize.Level1) plugin1.Stop(); plugin2.Stop(); } + +/** + * @tc.name: cpu plugin + * @tc.desc: cpu system information test for SetSystemCpuUsage. + * @tc.type: FUNC + */ +HWTEST_F(CpuDataPluginTest, TestSetSystemCpuUsage, TestSize.Level1) +{ + CpuData cpuData; + CpuDataPlugin cpuPlugin; + CpuTimeData cpuTimeData = {1966195, 1702753, 2345678, 1458898}; + CpuLoadData cpuLoadData; + cpuPlugin.SetSystemCpuUsage(*cpuData.mutable_cpu_usage_info(), cpuLoadData, cpuTimeData); + CpuUsageInfo cpuUsageInfo1 = cpuData.cpu_usage_info(); + EXPECT_EQ(cpuUsageInfo1.prev_system_cpu_time_ms(), 0); + EXPECT_EQ(cpuUsageInfo1.prev_system_boot_time_ms(), 0); + EXPECT_EQ(cpuUsageInfo1.system_cpu_time_ms(), 2345678); + EXPECT_EQ(cpuUsageInfo1.system_boot_time_ms(), 1458898); + EXPECT_EQ(cpuUsageInfo1.cores_size(), 0); + cpuPlugin.SetCpuCoreInfo("cpu 5", *cpuData.mutable_cpu_usage_info(), cpuTimeData); + cpuUsageInfo1 = cpuData.cpu_usage_info(); + ASSERT_EQ(cpuUsageInfo1.cores_size(), 1); + CpuCoreUsageInfo cpuCoreUsageInfo = cpuUsageInfo1.cores()[0]; + EXPECT_EQ(cpuCoreUsageInfo.cpu_core(), 5); // 5: cpu core +} + } // namespace diff --git a/device/plugins/diskio_plugin/test/unittest/diskio_data_plugin_unittest.cpp b/device/plugins/diskio_plugin/test/unittest/diskio_data_plugin_unittest.cpp index e9f3c3ce5..2562260f7 100644 --- a/device/plugins/diskio_plugin/test/unittest/diskio_data_plugin_unittest.cpp +++ b/device/plugins/diskio_plugin/test/unittest/diskio_data_plugin_unittest.cpp @@ -256,5 +256,10 @@ HWTEST_F(DiskioDataPluginTest, TestIOStats, TestSize.Level1) IoStats ioStatsIoReportEx(DiskioConfig::IO_REPORT_EX); EXPECT_TRUE(ioStatsIoReportEx.GetIoData()); EXPECT_TRUE(ioStatsIoReportEx.PutPluginStatsData(statsData)); + + auto ioInfo = std::make_shared(); + ioStats.fields_.assign(19, 100); + ioStats.SetIoInfo(ioInfo, "nr_free_pages"); + EXPECT_EQ(ioInfo->timeOfFlush_, 100); } } // namespace diff --git a/device/plugins/ffrt_profiler/test/unittest/ffrt_profiler_test.cpp b/device/plugins/ffrt_profiler/test/unittest/ffrt_profiler_test.cpp index ccb5e5d4b..61f830892 100644 --- a/device/plugins/ffrt_profiler/test/unittest/ffrt_profiler_test.cpp +++ b/device/plugins/ffrt_profiler/test/unittest/ffrt_profiler_test.cpp @@ -667,4 +667,27 @@ HWTEST_F(FfrtPofilerTest, TestFunction030, TestSize.Level1) ffrtProfilerMgr->SetConfig(config); EXPECT_TRUE(ffrtProfilerMgr->CheckConfig()); } + +/** + * @tc.name: ffrt plugin + * @tc.desc: FfrtPofiler FfrtProfilerManager check config + * @tc.type: FUNC + */ +HWTEST_F(FfrtPofilerTest, TestFunction040, TestSize.Level1) +{ + std::shared_ptr ffrtProfilerMgr = std::make_shared(); + FfrtProfilerConfig config; + std::set pidCache; + int32_t pid = -1; + config.add_pid(pid); + config.add_pid(ffrtPrfolerExePid_); + config.add_startup_process_name(""); + config.add_startup_process_name("test_name002"); + config.add_restart_process_name(""); + config.set_clock_id(FfrtProfilerConfig::MONOTONIC); + ffrtProfilerMgr->SetConfig(config); + EXPECT_TRUE(ffrtProfilerMgr->CheckPid(pidCache)); + EXPECT_TRUE(ffrtProfilerMgr->CheckStartupProcessName()); + EXPECT_TRUE(ffrtProfilerMgr->CheckRestartProcessName(pidCache)); +} } \ No newline at end of file -- Gitee