From fca2bf5d70786386a6e49531b0cd0d07e273d80c Mon Sep 17 00:00:00 2001 From: dong-bosi123 Date: Sat, 13 Sep 2025 15:04:49 +0800 Subject: [PATCH] add the dot in offline parse kernel stack Signed-off-by: dong-bosi123 --- interfaces/innerkits/backtrace/BUILD.gn | 9 ++++-- .../innerkits/backtrace/dfx_kernel_stack.cpp | 32 ++++++++++++++++++- .../innerkits/unwinder/include/dfx_hap.h | 3 +- 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/interfaces/innerkits/backtrace/BUILD.gn b/interfaces/innerkits/backtrace/BUILD.gn index f181d62e7..350f267af 100644 --- a/interfaces/innerkits/backtrace/BUILD.gn +++ b/interfaces/innerkits/backtrace/BUILD.gn @@ -39,7 +39,11 @@ if (defined(ohos_lite)) { sources = backtrace_local_sources defines = [ "is_ohos_lite" ] - + if (faultloggerd_hisysevent_enable) { + deps += [ "hisysevent:libhisysevent" ] + } else { + defines += [ "HISYSEVENT_DISABLE" ] + } deps = [ "$faultloggerd_common_path/dfxlog:dfx_hilog", "$faultloggerd_common_path/dfxutil:dfx_util", @@ -97,6 +101,7 @@ if (defined(ohos_lite)) { "bounds_checking_function:libsec_shared", "c_utils:utils", "hilog:libhilog", + "hisysevent:libhisysevent", ] install_images = [ @@ -116,7 +121,7 @@ if (defined(ohos_lite)) { ohos_static_library("backtrace_local") { public_configs = [ ":dfx_backtrace_config" ] defines = [ "DFX_LOG_HILOG_BASE" ] - + defines += [ "HISYSEVENT_DISABLE" ] sources = backtrace_local_sources include_dirs = [ "$faultloggerd_common_path/dfxlog", diff --git a/interfaces/innerkits/backtrace/dfx_kernel_stack.cpp b/interfaces/innerkits/backtrace/dfx_kernel_stack.cpp index d3809aa60..979f35e7a 100644 --- a/interfaces/innerkits/backtrace/dfx_kernel_stack.cpp +++ b/interfaces/innerkits/backtrace/dfx_kernel_stack.cpp @@ -25,7 +25,13 @@ #include "dfx_log.h" #include "dfx_trace_dlsym.h" #include "elapsed_time.h" +#include "file_ex.h" #include "smart_fd.h" +#include "string_util.h" + +#ifndef HISYSEVENT_DISABLE +#include "hisysevent.h" +#endif #define LOGGER_GET_STACK _IO(0xAB, 9) #define LOGGER_GET_STACK_ARKTS _IO(0xAB, 10) @@ -41,6 +47,25 @@ typedef struct HstackVal { pid_t pid {0}; char hstackLogBuff[BUFF_STACK_SIZE] {0}; } HstackVal; +MAYBE_UNUSED void ReportDumpStats(const std::string& bundleName, uint32_t threadSize, uint32_t costTime) +{ +#ifndef HISYSEVENT_DISABLE + std::string cmdline; + if (!LoadStringFromFile("/proc/self/cmdline", cmdline)) { + DFXLOGE("Failed to read self cmdline, errno:%{public}d", errno); + } + Trim(cmdline); + HiSysEventWrite( + HiSysEvent::Domain::HIVIEWDFX, + "DUMP_CATCHER_STATS", + HiSysEvent::EventType::STATISTIC, + "CALLER_PROCESS_NAME", cmdline.c_str(), + "TARGET_PROCESS_NAME", bundleName.c_str(), + "RESULT", 100, // 100 means offline parse kernel stack + "WRITE_DUMP_INFO_TIME", costTime, + "TARGET_PROCESS_THREAD_COUNT", threadSize); +#endif +} } int32_t DfxGetKernelStack(int32_t pid, std::string& kernelStack, bool needArkts) { @@ -134,7 +159,12 @@ bool FormatProcessKernelStack(const std::string& kernelStack, std::vector()); + auto costTime = counter.Elapsed(); + DFXLOGI("format kernel stack cost time = %{public}" PRId64 " ms", costTime); + if (needParseSymbol) { + ReportDumpStats(bundleName, static_cast(threadKernelStackVec.size()), + static_cast(costTime)); + } return true; #else return false; diff --git a/interfaces/innerkits/unwinder/include/dfx_hap.h b/interfaces/innerkits/unwinder/include/dfx_hap.h index 922ea92bf..eaed9d330 100644 --- a/interfaces/innerkits/unwinder/include/dfx_hap.h +++ b/interfaces/innerkits/unwinder/include/dfx_hap.h @@ -30,7 +30,8 @@ class DfxHap { public: DfxHap() = default; ~DfxHap(); - + DfxHap(const DfxHap&) = delete; + DfxHap& operator= (const DfxHap&) = delete; bool ParseHapInfo(pid_t pid, uint64_t pc, std::shared_ptr map, JsFunction *jsFunction, bool isOffline = false); private: -- Gitee