From 15fb1b09e38791219b386d510448edf2d4065664 Mon Sep 17 00:00:00 2001 From: yuhaoqiang <690364942@qq.com> Date: Thu, 9 Jan 2025 17:40:49 +0800 Subject: [PATCH 1/2] remove read wchan in hm kernel Signed-off-by: yuhaoqiang (cherry picked from commit a062308bfa3ef991bbf40b1a5be8e21753af3f37) --- interfaces/innerkits/dump_catcher/dfx_dump_catcher.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/interfaces/innerkits/dump_catcher/dfx_dump_catcher.cpp b/interfaces/innerkits/dump_catcher/dfx_dump_catcher.cpp index db3cf89d4..1703143ed 100644 --- a/interfaces/innerkits/dump_catcher/dfx_dump_catcher.cpp +++ b/interfaces/innerkits/dump_catcher/dfx_dump_catcher.cpp @@ -426,7 +426,9 @@ void DfxDumpCatcher::CollectKernelStack(pid_t pid, int waitMilliSeconds) void DfxDumpCatcher::AsyncGetAllTidKernelStack(pid_t pid, int waitMilliSeconds) { ReadProcessStatus(halfProcStatus_, pid); - ReadProcessWchan(halfProcWchan_, pid, false, true); + if (IsLinuxKernel()) { + ReadProcessWchan(halfProcWchan_, pid, false, true); + } if (g_asyncThreadRunning) { DFXLOG_INFO("pid(%d) get kernel stack thread is running, not get pid(%d)", g_kernelStackPid, pid); return; -- Gitee From dd88eaf44d9f971604052106a28bd5ae4dfdc848 Mon Sep 17 00:00:00 2001 From: yuhaoqiang Date: Mon, 20 Jan 2025 13:35:52 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8Ddumpcatcher=20system=20?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B=E6=89=A7=E8=A1=8C=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yuhaoqiang (cherry picked from commit 58da8267237d06e10239cb988df9eaaac4b0f569) Signed-off-by: yuhaoqiang Change-Id: I750880829560145044bc70844e067b36e0d0a003 --- test/systemtest/dumpcatcher_system_test.cpp | 23 +++++++++++++++------ test/utils/dfx_test_util.cpp | 16 ++++++++++++++ test/utils/dfx_test_util.h | 1 + 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/test/systemtest/dumpcatcher_system_test.cpp b/test/systemtest/dumpcatcher_system_test.cpp index b02945ed2..21946be5f 100644 --- a/test/systemtest/dumpcatcher_system_test.cpp +++ b/test/systemtest/dumpcatcher_system_test.cpp @@ -1379,10 +1379,15 @@ HWTEST_F(DumpCatcherSystemTest, DumpCatcherSystemTest101, TestSize.Level2) string procCMD = "dumpcatcher -p " + to_string(pid); string procDumpLog = ExecuteCommands(procCMD); GTEST_LOG_(INFO) << "procDumpLog: " << procDumpLog; - string log[] = { "Failed", "status:", "Name:", "nonvoluntary_ctxt_switches:", "wchan:", "Tid:" }; - int count = GetKeywordsNum(procDumpLog, log, sizeof(log) / sizeof(log[0])); + std::vector matchWords = { "Failed", "status:", "Name:", "nonvoluntary_ctxt_switches:" }; + if (IsLinuxKernel()) { + matchWords.emplace_back("wchan:"); + matchWords.emplace_back("Tid:"); + } + int matchCount = static_cast(matchWords.size()); + int count = GetKeywordsNum(procDumpLog, matchWords.data(), matchCount); kill(pid, SIGKILL); - EXPECT_EQ(count, sizeof(log) / sizeof(log[0])) << "DumpCatcherSystemTest101 Failed"; + EXPECT_EQ(count, matchCount) << "DumpCatcherSystemTest101 Failed"; GTEST_LOG_(INFO) << "DumpCatcherSystemTest101: end."; } @@ -1407,10 +1412,16 @@ HWTEST_F(DumpCatcherSystemTest, DumpCatcherSystemTest102, TestSize.Level2) GTEST_LOG_(ERROR) << "DumpCatcherSystemTest102: Failed to dump target process."; } GTEST_LOG_(INFO) << msg; - string log[] = { "timeout", "status:", "Name:", "nonvoluntary_ctxt_switches:", "wchan:", "Tid:" }; - int count = GetKeywordsNum(msg, log, sizeof(log) / sizeof(log[0])); + + std::vector matchWords = { "timeout", "status:", "Name:", "nonvoluntary_ctxt_switches:" }; + if (IsLinuxKernel()) { + matchWords.emplace_back("wchan:"); + matchWords.emplace_back("Tid:"); + } + int matchCount = static_cast(matchWords.size()); + int count = GetKeywordsNum(msg, matchWords.data(), matchCount); kill(pid, SIGKILL); - EXPECT_EQ(count, sizeof(log) / sizeof(log[0])) << "DumpCatcherSystemTest102 Failed"; + EXPECT_EQ(count, matchCount) << "DumpCatcherSystemTest102 Failed"; GTEST_LOG_(INFO) << "DumpCatcherSystemTest102: end."; } diff --git a/test/utils/dfx_test_util.cpp b/test/utils/dfx_test_util.cpp index 70acb4867..eb49aace8 100644 --- a/test/utils/dfx_test_util.cpp +++ b/test/utils/dfx_test_util.cpp @@ -295,5 +295,21 @@ void CheckResourceUsage(uint32_t fdCount, uint32_t mapsCount, uint64_t memCount) printf("AfterTest Memory New: %lu\n", static_cast(curMemSize)); printf("Memory Old: %lu\n", static_cast(memCount)); } + +bool IsLinuxKernel() +{ + static bool isLinux = [] { + std::string content; + LoadStringFromFile("/proc/version", content); + if (content.empty()) { + return true; + } + if (content.find("Linux") != std::string::npos) { + return true; + } + return false; + }(); + return isLinux; +} } // namespace HiviewDFX } // namespace OHOS \ No newline at end of file diff --git a/test/utils/dfx_test_util.h b/test/utils/dfx_test_util.h index 566b2fdc5..65971fb45 100644 --- a/test/utils/dfx_test_util.h +++ b/test/utils/dfx_test_util.h @@ -89,6 +89,7 @@ uint32_t GetSelfFdCount(); uint32_t GetSelfMapsCount(); uint64_t GetSelfMemoryCount(); void CheckResourceUsage(uint32_t fdCount, uint32_t mapsCount, uint64_t memCount); +bool IsLinuxKernel(); } // namespace HiviewDFX } // namespace OHOS #endif // DFX_TEST_UTIL \ No newline at end of file -- Gitee