diff --git a/interfaces/innerkits/backtrace/BUILD.gn b/interfaces/innerkits/backtrace/BUILD.gn index f181d62e72e3fef751a9676b38cff8c3dd5f5054..350f267af6a81d119afc18185aa5643f027605c2 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 d3809aa604e77fcd0b0b92cd0a5fbf2e9749eefa..979f35e7a6ab15e6b346be12b6e8e4e8105c4ebf 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 922ea92bfd5cae0094609c98ce01fe54c45fba6f..eaed9d330f9bb437d6478e368d931eb9cbb14030 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: