已开启
fix(hidumper): unify ARK_STATS_DUMP PID parameter to int type #805
LWH创建于 9月2日
fix(hidumper): unify ARK_STATS_DUMP PID parameter to int type #805
已开启
共 2 个文件变更+48-3
| @@ -1412,7 +1412,7 @@ void DumpImplement::ReportJsheap(const DumperOpts &opts) | |||
| 1412 | } | 1412 | } |
| 1413 | int memJsheapRet = HiSysEventWrite(OHOS::HiviewDFX::HiSysEvent::Domain::FRAMEWORK, "ARK_STATS_DUMP", | 1413 | int memJsheapRet = HiSysEventWrite(OHOS::HiviewDFX::HiSysEvent::Domain::FRAMEWORK, "ARK_STATS_DUMP", |
| 1414 | OHOS::HiviewDFX::HiSysEvent::EventType::FAULT, | 1414 | OHOS::HiviewDFX::HiSysEvent::EventType::FAULT, |
| 1415 | - "PID", std::to_string(opts.dumpJsHeapMemPid_), | 1415 | + "PID", opts.dumpJsHeapMemPid_, |
| 1416 | "TYPE", strType); | 1416 | "TYPE", strType); |
| 1417 | if (memJsheapRet != 0) { | 1417 | if (memJsheapRet != 0) { |
| 1418 | DUMPER_HILOGE(MODULE_COMMON, "hisysevent report mem jsheap failed! ret %{public}d.", memJsheapRet); | 1418 | DUMPER_HILOGE(MODULE_COMMON, "hisysevent report mem jsheap failed! ret %{public}d.", memJsheapRet); |
| @@ -1427,7 +1427,7 @@ void DumpImplement::ReportCjheap(const DumperOpts &opts) | |||
| 1427 | std::string strType = "hidumper"; | 1427 | std::string strType = "hidumper"; |
| 1428 | int memCjheapRet = HiSysEventWrite(OHOS::HiviewDFX::HiSysEvent::Domain::FRAMEWORK, "ARK_STATS_DUMP", | 1428 | int memCjheapRet = HiSysEventWrite(OHOS::HiviewDFX::HiSysEvent::Domain::FRAMEWORK, "ARK_STATS_DUMP", |
| 1429 | OHOS::HiviewDFX::HiSysEvent::EventType::FAULT, | 1429 | OHOS::HiviewDFX::HiSysEvent::EventType::FAULT, |
| 1430 | - "PID", std::to_string(opts.dumpCjHeapMemPid_), | 1430 | + "PID", opts.dumpCjHeapMemPid_, |
| 1431 | "TYPE", strType); | 1431 | "TYPE", strType); |
| 1432 | if (memCjheapRet != 0) { | 1432 | if (memCjheapRet != 0) { |
| 1433 | DUMPER_HILOGE(MODULE_COMMON, "hisysevent report mem cjheap failed! ret %{public}d.", memCjheapRet); | 1433 | DUMPER_HILOGE(MODULE_COMMON, "hisysevent report mem cjheap failed! ret %{public}d.", memCjheapRet); |
| @@ -1460,7 +1460,7 @@ void DumpImplement::ReportMemheap(const DumperOpts &opts) | |||
| 1460 | int pid = opts.dumpHeapArgPid_ > 0 ? opts.dumpHeapArgPid_ : opts.dumpHeapMemPid_; | 1460 | int pid = opts.dumpHeapArgPid_ > 0 ? opts.dumpHeapArgPid_ : opts.dumpHeapMemPid_; |
| 1461 | int memHeapRet = HiSysEventWrite(OHOS::HiviewDFX::HiSysEvent::Domain::FRAMEWORK, "ARK_STATS_DUMP", | 1461 | int memHeapRet = HiSysEventWrite(OHOS::HiviewDFX::HiSysEvent::Domain::FRAMEWORK, "ARK_STATS_DUMP", |
| 1462 | OHOS::HiviewDFX::HiSysEvent::EventType::FAULT, | 1462 | OHOS::HiviewDFX::HiSysEvent::EventType::FAULT, |
| 1463 | - "PID", std::to_string(pid), | 1463 | + "PID", pid, |
| 1464 | "TYPE", strType); | 1464 | "TYPE", strType); |
| 1465 | if (memHeapRet != 0) { | 1465 | if (memHeapRet != 0) { |
| 1466 | DUMPER_HILOGE(MODULE_COMMON, "hisysevent report mem heap failed! ret %{public}d.", memHeapRet); | 1466 | DUMPER_HILOGE(MODULE_COMMON, "hisysevent report mem heap failed! ret %{public}d.", memHeapRet); |
| @@ -879,6 +879,51 @@ HWTEST_F(HidumperDumpersTest, JsHeapDumperTest008, TestSize.Level1) | |||
| 879 | ASSERT_EQ(ret, DumpStatus::DUMP_OK); | 879 | ASSERT_EQ(ret, DumpStatus::DUMP_OK); |
| 880 | } | 880 | } |
| 881 | 881 | ||
| 882 | +/** | ||
| 883 | + * @tc.name: JsHeapDumperTest009 | ||
| 884 | + * @tc.desc: Test JsHeapDumper with real systemui pid and verify snapshot file. | ||
| 885 | + * @tc.type: FUNC | ||
| 886 | + */ | ||
| 887 | +HWTEST_F(HidumperDumpersTest, JsHeapDumperTest009, TestSize.Level1) | ||
| 888 | +{ | ||
| 889 | + char buf[64] = {0}; | ||
| 890 | + FILE* fp = popen("pidof com.ohos.systemui", "r"); | ||
| 891 | + if (fp) { | ||
| 892 | + if (fgets(buf, sizeof(buf), fp) != nullptr) {} | ||
| 893 | + pclose(fp); | ||
| 894 | + } | ||
| 895 | + int32_t targetPid = static_cast<int32_t>(strtol(buf, nullptr, 10)); | ||
| 896 | + if (targetPid <= 0) { | ||
| 897 | + GTEST_SKIP() << "com.ohos.systemui not running, cannot verify jsheap dump"; | ||
| 898 | + } | ||
| 899 | + std::string pidStr = std::to_string(targetPid); | ||
| 900 | + std::string cmd = "hidumper --mem-jsheap " + pidStr; | ||
| 901 | + FILE* pipe = popen(cmd.c_str(), "r"); | ||
| 902 | + ASSERT_NE(pipe, nullptr); | ||
| 903 | + char outBuf[256]; | ||
| 904 | + while (fgets(outBuf, sizeof(outBuf), pipe) != nullptr) {} | ||
| 905 | + pclose(pipe); | ||
| 906 | +#ifdef HIDUMPER_HIVIEWDFX_PLUGIN_ENABLE | ||
| 907 | + std::string dir = "/data/log/reliability/resource_leak/memory_leak/"; | ||
| 908 | + std::string prefix = "hidumper-jsheap-" + pidStr; | ||
| 909 | +#else | ||
| 910 | + std::string dir = "/data/log/faultlog/temp/"; | ||
| 911 | + std::string prefix = "jsheap-" + pidStr; | ||
| 912 | +#endif | ||
| 913 | + std::string checkCmd = "ls " + dir + " 2>/dev/null | grep '^" + prefix + "' | wc -l"; | ||
| 914 | + FILE* cntFp = popen(checkCmd.c_str(), "r"); | ||
| 915 | + if (!cntFp) { | ||
| 916 | + return; | ||
| 917 | + } | ||
| 918 | + char cntBuf[32] = {0}; | ||
| 919 | + bool ok = fgets(cntBuf, sizeof(cntBuf), cntFp) != nullptr; | ||
| 920 | + pclose(cntFp); | ||
| 921 | + if (ok) { | ||
| 922 | + int count = static_cast<int>(strtol(cntBuf, nullptr, 10)); | ||
| 923 | + EXPECT_GT(count, 0); | ||
| 924 | + } | ||
| 925 | +} | ||
| 926 | + | ||
| 882 | /** | 927 | /** |
| 883 | * @tc.name: HelpDumperTest001 | 928 | * @tc.name: HelpDumperTest001 |
| 884 | * @tc.desc: Test hidumper -h | 929 | * @tc.desc: Test hidumper -h |