diff --git a/bundle.json b/bundle.json index c4c3f8615..d14357008 100644 --- a/bundle.json +++ b/bundle.json @@ -56,7 +56,8 @@ "zlib", "grpc", "storage_service", - "abseil-cpp" + "abseil-cpp", + "hisysevent" ], "third_party": [ "cJSON", @@ -64,6 +65,9 @@ "libpng" ] }, + "hisysevent_config": [ + "//developtools/profiler/hiprofiler.yaml" + ], "build": { "sub_component": [ "//developtools/profiler/device:hiprofiler_targets", diff --git a/device/base/include/common.h b/device/base/include/common.h index e65761662..89abb8084 100644 --- a/device/base/include/common.h +++ b/device/base/include/common.h @@ -54,5 +54,16 @@ bool IsBetaVersion(); std::pair CheckNotExistsFilePath(const std::string& filePath); bool CheckWhiteList(const std::string& cmdPath); bool CheckCmdLineArgValid(const std::string& cmdLine); +int PluginWriteToHisysevent (std::string pluginName, std::string caller, std::string args, int errorCode, + std::string errorMessage); + +enum ErrorType { + RET_NOT_SUPPORT, + RET_NULL_ADDR, + RET_IVALID_PID, + RET_MSG_EMPTY, + RET_FAIL = -1, + RET_SUCC = 0, +}; } // COMMON #endif // COMMON_H \ No newline at end of file diff --git a/device/base/src/common.cpp b/device/base/src/common.cpp index 0a337280d..4ab0016f5 100644 --- a/device/base/src/common.cpp +++ b/device/base/src/common.cpp @@ -33,6 +33,7 @@ #include "application_info.h" #include "bundle_mgr_proxy.h" #include "file_ex.h" +#include "hisysevent.h" #include "iservice_registry.h" #include "logging.h" #include "system_ability_definition.h" @@ -773,4 +774,16 @@ bool CheckCmdLineArgValid(const std::string& cmdLine) } return true; } + +int PluginWriteToHisysevent (std::string pluginName, std::string caller, std::string args, int errorCode, + std::string errorMessage) +{ + return HiSysEventWrite(OHOS::HiviewDFX::HiSysEvent::Domain::HIPROFILER, "HIPROFILER_USAGE", + OHOS::HiviewDFX::HiSysEvent::EventType::STATISTIC, + "PLUGIN_NAME", pluginName, + "CALLER", caller, + "ARGS", args, + "ERROR_CODE", errorCode, + "ERROR_MESSAFE", errorMessage); +} } // namespace COMMON diff --git a/device/plugins/cpu_plugin/BUILD.gn b/device/plugins/cpu_plugin/BUILD.gn index 67c4dd6dd..fb5337c66 100644 --- a/device/plugins/cpu_plugin/BUILD.gn +++ b/device/plugins/cpu_plugin/BUILD.gn @@ -37,6 +37,7 @@ ohos_source_set("cpudataplugin_source") { defines = [ "HAVE_HILOG" ] external_deps = [ "hilog:libhilog_base", + "hisysevent:libhisysevent", "protobuf:protobuf_lite", ] } @@ -46,7 +47,10 @@ ohos_source_set("cpudataplugin_source") { ohos_shared_library("cpudataplugin") { output_name = "cpudataplugin" version_script = "libcpu_plugin.map" - deps = [ ":cpudataplugin_source" ] + deps = [ + ":cpudataplugin_source", + "${OHOS_PROFILER_DIR}/device/base:hiprofiler_base", + ] if (current_toolchain != host_toolchain) { defines = [ "HAVE_HILOG" ] external_deps = [ diff --git a/device/plugins/cpu_plugin/include/cpu_data_plugin.h b/device/plugins/cpu_plugin/include/cpu_data_plugin.h index af0fdde77..021abebf1 100644 --- a/device/plugins/cpu_plugin/include/cpu_data_plugin.h +++ b/device/plugins/cpu_plugin/include/cpu_data_plugin.h @@ -99,6 +99,7 @@ private: DIR* OpenDestDir(std::string& dirPath); int32_t GetValidTid(DIR* dirp); ThreadState GetThreadState(const char threadState); + std::string GetCmdArgs(CpuConfig protoConfig); template void WriteThread(T& threadInfo, const char* pFile, uint32_t fileLen, int32_t tid); diff --git a/device/plugins/cpu_plugin/src/cpu_data_plugin.cpp b/device/plugins/cpu_plugin/src/cpu_data_plugin.cpp index 685e7f403..c2668358b 100644 --- a/device/plugins/cpu_plugin/src/cpu_data_plugin.cpp +++ b/device/plugins/cpu_plugin/src/cpu_data_plugin.cpp @@ -18,6 +18,8 @@ #include #include #include + +#include "common.h" #include "cpu_plugin_result.pbencoder.h" #include "buffer_splitter.h" @@ -68,6 +70,15 @@ CpuDataPlugin::~CpuDataPlugin() minFrequencyVec_.clear(); } +std::string CpuDataPlugin::GetCmdArgs(CpuConfig protoConfig) +{ + std::string args; + args += "pid: " + std::to_string(protoConfig.pid()); + args += " report_process_info: "; + args += (protoConfig.report_process_info() ? "true" : "false"); + return args; +} + int CpuDataPlugin::Start(const uint8_t* configData, uint32_t configSize) { buffer_ = malloc(READ_BUFFER_SIZE); @@ -77,15 +88,19 @@ int CpuDataPlugin::Start(const uint8_t* configData, uint32_t configSize) } CHECK_TRUE(protoConfig_.ParseFromArray(configData, configSize) > 0, RET_FAIL, "%s:parseFromArray failed!", __func__); + auto args = GetCmdArgs(protoConfig_); if (protoConfig_.pid() > 0) { pid_ = protoConfig_.pid(); } else if (protoConfig_.report_process_info()) { PROFILER_LOG_INFO(LOG_CORE, "%s:need report process info", __func__); } else { - PROFILER_LOG_ERROR(LOG_CORE, "%s:invalid pid", __func__); + int ret = COMMON::PluginWriteToHisysevent("CPU_PLUGIN", "sh", args, RET_FAIL, "failed"); + PROFILER_LOG_ERROR(LOG_CORE, "%s:invalid pid, record hisysevent result", __func__, ret); return RET_FAIL; } - PROFILER_LOG_INFO(LOG_CORE, "%s:start success!", __func__); + + int ret = COMMON::PluginWriteToHisysevent("cpu_plugin", "sh", args, RET_SUCC, "success"); + PROFILER_LOG_INFO(LOG_CORE, "%s:start success! hisysevent report cpu_plugin result: %d", __func__, ret); return RET_SUCC; } diff --git a/device/plugins/cpu_plugin/test/BUILD.gn b/device/plugins/cpu_plugin/test/BUILD.gn index 6268777ef..9e69f37de 100644 --- a/device/plugins/cpu_plugin/test/BUILD.gn +++ b/device/plugins/cpu_plugin/test/BUILD.gn @@ -29,6 +29,7 @@ ohos_unittest("cpudataplugin_ut") { module_out_path = module_output_path sources = [ "unittest/cpu_data_plugin_unittest.cpp" ] deps = [ + "${OHOS_PROFILER_DIR}/device/base:hiprofiler_base", "${OHOS_PROFILER_DIR}/device/plugins/cpu_plugin:cpudataplugin_source", "${OHOS_PROFILER_DIR}/device/plugins/cpu_plugin:cpudataplugintest", "${OHOS_PROFILER_DIR}/protos/types/plugins/cpu_data:cpu_data_cpp", diff --git a/device/plugins/cpu_plugin/test/fuzztest/cpustartplugin_fuzzer/BUILD.gn b/device/plugins/cpu_plugin/test/fuzztest/cpustartplugin_fuzzer/BUILD.gn index 30b66a753..34cdda708 100644 --- a/device/plugins/cpu_plugin/test/fuzztest/cpustartplugin_fuzzer/BUILD.gn +++ b/device/plugins/cpu_plugin/test/fuzztest/cpustartplugin_fuzzer/BUILD.gn @@ -27,6 +27,7 @@ ohos_fuzztest("CpuStartPluginFuzzTest") { ] sources = [ "cpustartplugin_fuzzer.cpp" ] deps = [ + "${OHOS_PROFILER_DIR}/device/base:hiprofiler_base", "${OHOS_PROFILER_DIR}/device/plugins/cpu_plugin:cpudataplugin_source", "${OHOS_PROFILER_DIR}/protos/types/plugins/cpu_data:cpu_data_cpp", ] diff --git a/device/plugins/diskio_plugin/BUILD.gn b/device/plugins/diskio_plugin/BUILD.gn index 1ca03ebe3..f98489554 100644 --- a/device/plugins/diskio_plugin/BUILD.gn +++ b/device/plugins/diskio_plugin/BUILD.gn @@ -38,6 +38,7 @@ ohos_source_set("diskiodataplugin_source") { defines = [ "HAVE_HILOG" ] external_deps = [ "hilog:libhilog_base", + "hisysevent:libhisysevent", "protobuf:protobuf_lite", ] } @@ -47,7 +48,10 @@ ohos_source_set("diskiodataplugin_source") { ohos_shared_library("diskiodataplugin") { output_name = "diskiodataplugin" version_script = "libdiskio_plugin.map" - deps = [ ":diskiodataplugin_source" ] + deps = [ + ":diskiodataplugin_source", + "${OHOS_PROFILER_DIR}/device/base:hiprofiler_base", + ] if (current_toolchain != host_toolchain) { defines = [ "HAVE_HILOG" ] external_deps = [ diff --git a/device/plugins/diskio_plugin/include/diskio_data_plugin.h b/device/plugins/diskio_plugin/include/diskio_data_plugin.h index 9940c4739..01a544c73 100644 --- a/device/plugins/diskio_plugin/include/diskio_data_plugin.h +++ b/device/plugins/diskio_plugin/include/diskio_data_plugin.h @@ -56,6 +56,8 @@ private: template void WriteDiskioData(T& diskioData); + std::string GetCmdArgs(DiskioConfig protoConfig); + // for UT void SetPath(std::string path) { diff --git a/device/plugins/diskio_plugin/src/diskio_data_plugin.cpp b/device/plugins/diskio_plugin/src/diskio_data_plugin.cpp index 717728105..33d032dd2 100644 --- a/device/plugins/diskio_plugin/src/diskio_data_plugin.cpp +++ b/device/plugins/diskio_plugin/src/diskio_data_plugin.cpp @@ -18,6 +18,7 @@ #include #include "buffer_splitter.h" +#include "common.h" #include "diskio_plugin_result.pbencoder.h" namespace { @@ -46,6 +47,13 @@ DiskioDataPlugin::~DiskioDataPlugin() } } +std::string DiskioDataPlugin::GetCmdArgs(DiskioConfig protoConfig) +{ + std::string args; + args = "report_io_stats: " + std::to_string(protoConfig.report_io_stats()); + return args; +} + int DiskioDataPlugin::Start(const uint8_t* configData, uint32_t configSize) { buffer_ = malloc(READ_BUFFER_SIZE); @@ -57,7 +65,9 @@ int DiskioDataPlugin::Start(const uint8_t* configData, uint32_t configSize) if (protoConfig_.report_io_stats()) { ioEntry_ = std::make_shared(protoConfig_.report_io_stats()); } - PROFILER_LOG_INFO(LOG_CORE, "%s:start success!", __func__); + + int ret = COMMON::PluginWriteToHisysevent("diskio_plugin", "sh", GetCmdArgs(protoConfig_), RET_SUCC, "success"); + PROFILER_LOG_INFO(LOG_CORE, "%s:start success! hisysevent report diskio_plugin result: %d", __func__, ret); return RET_SUCC; } diff --git a/device/plugins/ftrace_plugin/BUILD.gn b/device/plugins/ftrace_plugin/BUILD.gn index 62ac106d4..4755e21ef 100644 --- a/device/plugins/ftrace_plugin/BUILD.gn +++ b/device/plugins/ftrace_plugin/BUILD.gn @@ -52,6 +52,7 @@ ohos_source_set("ftrace_plugin_source") { external_deps = [ "bounds_checking_function:libsec_shared", "hilog:libhilog_base", + "hisysevent:libhisysevent", "hiview:libucollection_client", "init:libbegetutil", "protobuf:protobuf_lite", diff --git a/device/plugins/ftrace_plugin/include/flow_controller.h b/device/plugins/ftrace_plugin/include/flow_controller.h index c5113dcbc..2eeb6f4a9 100644 --- a/device/plugins/ftrace_plugin/include/flow_controller.h +++ b/device/plugins/ftrace_plugin/include/flow_controller.h @@ -76,6 +76,7 @@ private: void EnableTraceEvents(void); void DisableTraceEvents(void); void DisableAllCategories(void); + std::string GetCmdArgs(TracePluginConfig traceConfig); template bool ReportClockTimes(T& tracePluginResult); diff --git a/device/plugins/ftrace_plugin/src/flow_controller.cpp b/device/plugins/ftrace_plugin/src/flow_controller.cpp index 2581127eb..3bc22ef34 100644 --- a/device/plugins/ftrace_plugin/src/flow_controller.cpp +++ b/device/plugins/ftrace_plugin/src/flow_controller.cpp @@ -24,6 +24,7 @@ #include #include +#include "common.h" #include "file_utils.h" #include "ftrace_field_parser.h" #include "ftrace_fs_ops.h" @@ -746,6 +747,36 @@ bool FlowController::AddPlatformEventsToParser(void) return true; } +std::string FlowController::GetCmdArgs(TracePluginConfig traceConfig) +{ + std::string args; + for (const auto& event : traceConfig.ftrace_events()) { + args += "ftrace_events: " + event + ", "; + } + for (const auto& category : traceConfig.hitrace_categories()) { + args += "hitrace_categories: " + category + ", "; + } + for (const auto& app : traceConfig.hitrace_apps()) { + args += "hitrace_apps: " + app + ", "; + } + args += "buffer_size_kb: " + std::to_string(traceConfig.buffer_size_kb()) + ", "; + args += "flush_interval_ms: " + std::to_string(traceConfig.flush_interval_ms()) + ", "; + args += "flush_threshold_kb: " + std::to_string(traceConfig.flush_threshold_kb()) + ", "; + args += "trace_period_ms: " + std::to_string(traceConfig.trace_period_ms()) + ", "; + args += "trace_duration_ms: " + std::to_string(traceConfig.trace_duration_ms()) + ", "; + args += "hitrace_time: " + std::to_string(traceConfig.hitrace_time()) + ", "; + args += "parse_ksyms: "; + args += (traceConfig.parse_ksyms() ? "true" : "false"); + args += ", clock: " + traceConfig.clock() + ", "; + args += "raw_data_prefix: " + traceConfig.raw_data_prefix() + ", "; + args += "debug_on: "; + args += (traceConfig.debug_on() ? "true" : "false"); + args += ", discard_cache_data: "; + args += (traceConfig.discard_cache_data() ? "true" : "false"); + args += ", parse_mode: " + std::to_string(traceConfig.parse_mode()); + return args; +} + int FlowController::LoadConfig(const uint8_t configData[], uint32_t size) { CHECK_TRUE(size > 0, -1, "config data size is zero!"); @@ -790,6 +821,10 @@ int FlowController::LoadConfig(const uint8_t configData[], uint32_t size) SetupTraceReadPeriod(traceConfig.trace_period_ms()); flushCacheData_ = traceConfig.discard_cache_data(); hitraceTime_ = traceConfig.hitrace_time(); + + int ret = COMMON::PluginWriteToHisysevent("ftrace_plugin", "sh", GetCmdArgs(traceConfig), + COMMON::ErrorType::RET_SUCC, "success"); + PROFILER_LOG_INFO(LOG_CORE, "hisysevent report ftrace_plugin result: %d", ret); return 0; } diff --git a/device/plugins/gpu_plugin/BUILD.gn b/device/plugins/gpu_plugin/BUILD.gn index 9ff820d61..64863d269 100644 --- a/device/plugins/gpu_plugin/BUILD.gn +++ b/device/plugins/gpu_plugin/BUILD.gn @@ -38,6 +38,7 @@ ohos_source_set("gpudataplugin_source") { external_deps = [ "bounds_checking_function:libsec_shared", "hilog:libhilog_base", + "hisysevent:libhisysevent", "protobuf:protobuf_lite", ] } @@ -47,7 +48,10 @@ ohos_source_set("gpudataplugin_source") { ohos_shared_library("gpudataplugin") { output_name = "gpudataplugin" version_script = "libgpu_plugin.map" - deps = [ ":gpudataplugin_source" ] + deps = [ + ":gpudataplugin_source", + "${OHOS_PROFILER_DIR}/device/base:hiprofiler_base", + ] if (current_toolchain != host_toolchain) { defines = [ "HAVE_HILOG" ] external_deps = [ "hilog:libhilog_base" ] diff --git a/device/plugins/gpu_plugin/include/gpu_data_plugin.h b/device/plugins/gpu_plugin/include/gpu_data_plugin.h index 63dde6bd0..c57f5d94d 100644 --- a/device/plugins/gpu_plugin/include/gpu_data_plugin.h +++ b/device/plugins/gpu_plugin/include/gpu_data_plugin.h @@ -45,6 +45,7 @@ public: private: int ReadFile(); + std::string GetCmdArgs(GpuConfig traceConfig); template void WriteGpuDataInfo(T& gpuData); private: diff --git a/device/plugins/gpu_plugin/src/gpu_data_plugin.cpp b/device/plugins/gpu_plugin/src/gpu_data_plugin.cpp index 914aefecc..0e8deca02 100644 --- a/device/plugins/gpu_plugin/src/gpu_data_plugin.cpp +++ b/device/plugins/gpu_plugin/src/gpu_data_plugin.cpp @@ -15,6 +15,7 @@ #include "gpu_data_plugin.h" #include +#include "common.h" #include "gpu_plugin_result.pbencoder.h" namespace { @@ -32,14 +33,27 @@ int GpuDataPlugin::Start(const uint8_t* configData, uint32_t configSize) } file_.open(GPU_PATH); + auto args = GetCmdArgs(protoConfig_); if (!file_.is_open()) { - PROFILER_LOG_ERROR(LOG_CORE, "%s:failed to open(%s)", __func__, GPU_PATH.c_str()); + int ret = COMMON::PluginWriteToHisysevent("gpu_plugin", "sh", args, RET_FAIL, "failed"); + PROFILER_LOG_ERROR(LOG_CORE, "%s:failed to open(%s), hisysevent report gpu_plugin ret: %d", + __func__, GPU_PATH.c_str(), ret); return RET_FAIL; } - PROFILER_LOG_INFO(LOG_CORE, "%s:start success!", __func__); + + int ret = COMMON::PluginWriteToHisysevent("gpu_plugin", "sh", args, RET_SUCC, "success"); + PROFILER_LOG_INFO(LOG_CORE, "%s:start success! hisysevent report gpu_plugin result: %d", __func__, ret); return RET_SUCC; } +std::string GpuDataPlugin::GetCmdArgs(GpuConfig traceConfig) +{ + std::string args; + args += "pid: " + std::to_string(traceConfig.pid()) + ", report_gpu_info: "; + args += (traceConfig.report_gpu_info() ? "true" : "false"); + return args; +} + int GpuDataPlugin::ReportOptimize(RandomWriteCtx* randomWrite) { ProtoEncoder::GpuData dataProto(randomWrite); diff --git a/device/plugins/hidump_plugin/BUILD.gn b/device/plugins/hidump_plugin/BUILD.gn index 779e86389..c3adaf324 100644 --- a/device/plugins/hidump_plugin/BUILD.gn +++ b/device/plugins/hidump_plugin/BUILD.gn @@ -36,6 +36,7 @@ ohos_source_set("hidumpplugin_source") { external_deps = [ "bounds_checking_function:libsec_shared", "hilog:libhilog_base", + "hisysevent:libhisysevent", "protobuf:protobuf_lite", ] } diff --git a/device/plugins/hidump_plugin/include/hidump_plugin.h b/device/plugins/hidump_plugin/include/hidump_plugin.h index 37349b811..c1e9bfd59 100644 --- a/device/plugins/hidump_plugin/include/hidump_plugin.h +++ b/device/plugins/hidump_plugin/include/hidump_plugin.h @@ -44,6 +44,7 @@ private: // for ut void SetConfig(HidumpConfig& config); int SetTestCmd(const char *test_cmd); + std::string GetCmdArgs(HidumpConfig protoConfig); const char *GetTestCmd(); char *testCmd_ = nullptr; private: diff --git a/device/plugins/hidump_plugin/src/hidump_plugin.cpp b/device/plugins/hidump_plugin/src/hidump_plugin.cpp index fd9ae84b0..7e03265f8 100644 --- a/device/plugins/hidump_plugin/src/hidump_plugin.cpp +++ b/device/plugins/hidump_plugin/src/hidump_plugin.cpp @@ -24,9 +24,10 @@ #include #include -#include "hidump_plugin_result.pbencoder.h" -#include "securec.h" #include "common.h" +#include "hidump_plugin_result.pbencoder.h" +#include "hisysevent.h" +#include "securec.h" namespace { using namespace OHOS::Developtools::Profiler; @@ -58,6 +59,14 @@ HidumpPlugin::~HidumpPlugin() PROFILER_LOG_INFO(LOG_CORE, "%s: success!", __func__); } +std::string HidumpPlugin::GetCmdArgs(HidumpConfig protoConfig) +{ + std::string args; + args += "sections: " + std::to_string(protoConfig.sections()) + ", report_fps: "; + args += (protoConfig.report_fps() ? "true" : "false"); + return args; +} + int HidumpPlugin::Start(const uint8_t* configData, uint32_t configSize) { PROFILER_LOG_INFO(LOG_CORE, "HidumpPlugin:Start ----> !"); @@ -73,10 +82,12 @@ int HidumpPlugin::Start(const uint8_t* configData, uint32_t configSize) COMMON::CustomPopen(fullCmd, "r", pipeFds_, childPid_, true), [this](FILE* fp) -> int { return COMMON::CustomPclose(fp, pipeFds_, childPid_, true); }); + auto args = GetCmdArgs(protoConfig_); if (fp_.get() == nullptr) { const int bufSize = 256; char buf[bufSize] = {0}; strerror_r(errno, buf, bufSize); + COMMON::PluginWriteToHisysevent("hidump_plugin", "sh", args, COMMON::ErrorType::RET_FAIL, "failed"); PROFILER_LOG_ERROR(LOG_CORE, "HidumpPlugin: CustomPopen(%s) Failed, errno(%d:%s)", FPS_FORMAT, errno, buf); return -1; } @@ -86,7 +97,8 @@ int HidumpPlugin::Start(const uint8_t* configData, uint32_t configSize) std::unique_lock locker(mutex_); running_ = true; writeThread_ = std::thread([this] { this->Loop(); }); - PROFILER_LOG_INFO(LOG_CORE, "HidumpPlugin: ---> Start success!"); + int ret = COMMON::PluginWriteToHisysevent("hidump_plugin", "sh", args, COMMON::ErrorType::RET_SUCC, "success"); + PROFILER_LOG_INFO(LOG_CORE, "HidumpPlugin--> Start success! hisysevent report hidump_plugin result:%d", ret); return 0; } diff --git a/device/plugins/hilog_plugin/BUILD.gn b/device/plugins/hilog_plugin/BUILD.gn index 443040631..41a1cb744 100644 --- a/device/plugins/hilog_plugin/BUILD.gn +++ b/device/plugins/hilog_plugin/BUILD.gn @@ -38,6 +38,7 @@ ohos_source_set("hilogplugin_source") { external_deps = [ "bounds_checking_function:libsec_shared", "hilog:libhilog_base", + "hisysevent:libhisysevent", "protobuf:protobuf_lite", ] } diff --git a/device/plugins/hilog_plugin/include/hilog_plugin.h b/device/plugins/hilog_plugin/include/hilog_plugin.h index 4bfe6f713..aae8690de 100644 --- a/device/plugins/hilog_plugin/include/hilog_plugin.h +++ b/device/plugins/hilog_plugin/include/hilog_plugin.h @@ -55,6 +55,7 @@ private: bool FindFirstNum(char** p); bool RemoveSpaces(char** p); bool FindFirstSpace(char** p); + std::string GetCmdArgs(HilogConfig protoConfig); bool StringToL(const char* word, long& value); // for ut diff --git a/device/plugins/hilog_plugin/src/hilog_plugin.cpp b/device/plugins/hilog_plugin/src/hilog_plugin.cpp index 0e042aff7..756206352 100644 --- a/device/plugins/hilog_plugin/src/hilog_plugin.cpp +++ b/device/plugins/hilog_plugin/src/hilog_plugin.cpp @@ -68,6 +68,17 @@ HilogPlugin::~HilogPlugin() PROFILER_LOG_INFO(LOG_CORE, "%s: success!", __func__); } +std::string HilogPlugin::GetCmdArgs(HilogConfig protoConfig) +{ + std::string args; + args += "log_level: " + std::to_string(protoConfig.log_level()); + args += "pid: " + std::to_string(protoConfig.pid()) + ", need_record: "; + args += (protoConfig.need_record() ? "true" : "false"); + args += ", need_clear: "; + args += (protoConfig.need_clear() ? "true" : "false"); + return args; +} + int HilogPlugin::Start(const uint8_t* configData, uint32_t configSize) { CHECK_TRUE(protoConfig_.ParseFromArray(configData, configSize) > 0, -1, "HilogPlugin: ParseFromArray failed"); @@ -106,8 +117,11 @@ int HilogPlugin::Start(const uint8_t* configData, uint32_t configSize) fcntl(fileno(fp_.get()), F_SETPIPE_SZ, oldPipeSize * PIPE_SIZE_RATIO); int pipeSize = fcntl(fileno(fp_.get()), F_GETPIPE_SZ); PROFILER_LOG_INFO(LOG_CORE, "{fp = %d, pipeSize=%d, oldPipeSize=%d}", fileno(fp_.get()), pipeSize, oldPipeSize); - workThread_ = std::thread([this] { this->Run(); }); + + int ret = COMMON::PluginWriteToHisysevent("hidump_plugin", "sh", GetCmdArgs(protoConfig_), + COMMON::ErrorType::RET_SUCC, "success"); + PROFILER_LOG_INFO(LOG_CORE, "hisysevent report hilog_plugin result:%d", ret); return 0; } diff --git a/device/plugins/hiperf_plugin/BUILD.gn b/device/plugins/hiperf_plugin/BUILD.gn index 8bcc6a62b..f1584e331 100644 --- a/device/plugins/hiperf_plugin/BUILD.gn +++ b/device/plugins/hiperf_plugin/BUILD.gn @@ -47,6 +47,7 @@ ohos_source_set("hiperfplugin_source") { external_deps = [ "bounds_checking_function:libsec_shared", "hilog:libhilog_base", + "hisysevent:libhisysevent", "openssl:libcrypto_shared", "protobuf:protobuf_lite", ] diff --git a/device/plugins/hiperf_plugin/src/hiperf_module.cpp b/device/plugins/hiperf_plugin/src/hiperf_module.cpp index 279e1c93e..7641001d6 100644 --- a/device/plugins/hiperf_plugin/src/hiperf_module.cpp +++ b/device/plugins/hiperf_plugin/src/hiperf_module.cpp @@ -22,10 +22,11 @@ #include #include +#include "common.h" #include "hiperf_plugin_config.pb.h" +#include "hisysevent.h" #include "logging.h" #include "securec.h" -#include "common.h" #include "trace_file_writer.h" namespace { @@ -111,6 +112,18 @@ bool RunCommand(const std::string& cmd) CHECK_TRUE(res, false, "HiperfPlugin::RunCommand: execute command FAILED!"); return true; } + +std::string GetCmdArgs(HiperfPluginConfig protoConfig) +{ + std::string args; + args += "is_root: "; + args += (protoConfig.is_root() ? "true" : "false"); + args += ", outfile_name: " + protoConfig.outfile_name(); + args += ", record_args: " + protoConfig.record_args(); + args += ", split_outfile_name: " + protoConfig.split_outfile_name(); + args += ", log_level: " + std::to_string(protoConfig.log_level()); + return args; +} } // namespace int HiperfPluginSessionStart(const uint8_t* configData, const uint32_t configSize) @@ -141,6 +154,9 @@ int HiperfPluginSessionStart(const uint8_t* configData, const uint32_t configSiz CHECK_TRUE(res, -1, "HiperfPluginSessionStart, RunCommand(%s) FAILED!", cmd.c_str()); } + int ret = COMMON::PluginWriteToHisysevent("hiperf_plugin", "sh", GetCmdArgs(g_config), + COMMON::ErrorType::RET_SUCC, "success"); + PROFILER_LOG_INFO(LOG_CORE, "hisysevent report hiperf_plugin result:%d", ret); return 0; } diff --git a/device/plugins/hisysevent_plugin/BUILD.gn b/device/plugins/hisysevent_plugin/BUILD.gn index c3d88ea99..192e7ccbd 100644 --- a/device/plugins/hisysevent_plugin/BUILD.gn +++ b/device/plugins/hisysevent_plugin/BUILD.gn @@ -38,6 +38,7 @@ ohos_source_set("hisyseventplugin_source") { external_deps = [ "bounds_checking_function:libsec_shared", "hilog:libhilog_base", + "hisysevent:libhisysevent", "protobuf:protobuf_lite", ] } diff --git a/device/plugins/hisysevent_plugin/include/hisysevent_plugin.h b/device/plugins/hisysevent_plugin/include/hisysevent_plugin.h index 0d405624b..ac06d47bc 100644 --- a/device/plugins/hisysevent_plugin/include/hisysevent_plugin.h +++ b/device/plugins/hisysevent_plugin/include/hisysevent_plugin.h @@ -40,6 +40,7 @@ public: private: std::string GetFullCmd(); bool InitHisyseventCmd(); + std::string GetCmdArgs(HisyseventConfig protoConfig); template bool ParseSyseventLineInfo(const char* data, size_t len, T hisyseventInfoProto); diff --git a/device/plugins/hisysevent_plugin/src/hisysevent_plugin.cpp b/device/plugins/hisysevent_plugin/src/hisysevent_plugin.cpp index de4690efd..7c1c5653a 100644 --- a/device/plugins/hisysevent_plugin/src/hisysevent_plugin.cpp +++ b/device/plugins/hisysevent_plugin/src/hisysevent_plugin.cpp @@ -76,10 +76,21 @@ int HisyseventPlugin::Start(const uint8_t* configData, uint32_t configSize) running_ = true; workThread_ = std::thread([this] { this->Run(); }); - PROFILER_LOG_INFO(LOG_CORE, "END %s: success!", __func__); + int ret = COMMON::PluginWriteToHisysevent("hisysevent_plugin", "sh", GetCmdArgs(protoConfig_), + COMMON::ErrorType::RET_SUCC, "success"); + PROFILER_LOG_INFO(LOG_CORE, "END %s: success! hisysevent report hisysevent_plugin result:%d", __func__, ret); return 0; } +std::string HisyseventPlugin::GetCmdArgs(HisyseventConfig protoConfig) +{ + std::string args; + args += "msg: " + protoConfig.msg() + ", "; + args += "subscribe_domain: " + protoConfig.subscribe_domain() + ", "; + args += "subscribe_event: " + protoConfig.subscribe_event(); + return args; +} + int HisyseventPlugin::Stop() { PROFILER_LOG_INFO(LOG_CORE, "BEGN %s: ready!", __func__); diff --git a/device/plugins/memory_plugin/BUILD.gn b/device/plugins/memory_plugin/BUILD.gn index fbf12469f..6da053776 100644 --- a/device/plugins/memory_plugin/BUILD.gn +++ b/device/plugins/memory_plugin/BUILD.gn @@ -43,6 +43,7 @@ ohos_source_set("memdataplugin_source") { "drivers_interface_memorytracker:libmemorytracker_proxy_1.0", "hidumper:lib_dump_usage", "hilog:libhilog_base", + "hisysevent:libhisysevent", "hiview:libucollection_graphic", "protobuf:protobuf_lite", ] diff --git a/device/plugins/memory_plugin/include/memory_data_plugin.h b/device/plugins/memory_plugin/include/memory_data_plugin.h index af6d6346a..c609cf2d1 100644 --- a/device/plugins/memory_plugin/include/memory_data_plugin.h +++ b/device/plugins/memory_plugin/include/memory_data_plugin.h @@ -349,7 +349,7 @@ public: }; template void WriteProcesseList(T& memoryData); - + std::string GetCmdArgs(MemoryConfig traceConfig); template void WriteProcinfoByPidfds(T& processMemoryInfo, int32_t pid); DIR* OpenDestDir(const char* dirPath); diff --git a/device/plugins/memory_plugin/src/memory_data_plugin.cpp b/device/plugins/memory_plugin/src/memory_data_plugin.cpp index bab9b0f1f..a416ae693 100644 --- a/device/plugins/memory_plugin/src/memory_data_plugin.cpp +++ b/device/plugins/memory_plugin/src/memory_data_plugin.cpp @@ -17,10 +17,10 @@ #include #include +#include "common.h" #include "memory_plugin_result.pbencoder.h" #include "securec.h" #include "smaps_stats.h" -#include "common.h" namespace { using namespace OHOS::HDI::Memorytracker::V1_0; @@ -199,10 +199,55 @@ int MemoryDataPlugin::Start(const uint8_t* configData, uint32_t configSize) } } - PROFILER_LOG_INFO(LOG_CORE, "%s:start success!", __func__); + int ret = COMMON::PluginWriteToHisysevent("memory_plugin", "sh", GetCmdArgs(protoConfig_), + COMMON::ErrorType::RET_SUCC, "success"); + PROFILER_LOG_INFO(LOG_CORE, "%s: success! hisysevent report memory_plugin result:%d", __func__, ret); return RET_SUCC; } + +std::string MemoryDataPlugin::GetCmdArgs(MemoryConfig traceConfig) +{ + std::string args; + args += "report_process_tree: "; + args += (traceConfig.report_process_tree() ? "true" : "false"); + args += ", report_sysmem_mem_info: "; + args += (traceConfig.report_sysmem_mem_info() ? "true" : "false"); + args += ", report_sysmem_vmem_info: "; + args += (traceConfig.report_sysmem_vmem_info() ? "true" : "false"); + args += ", report_process_mem_info: "; + args += (traceConfig.report_process_mem_info() ? "true" : "false"); + args += ", report_app_mem_info: "; + args += (traceConfig.report_app_mem_info() ? "true" : "false"); + args += ", report_app_mem_by_memory_service: "; + args += (traceConfig.report_app_mem_by_memory_service() ? "true" : "false"); + args += ", report_smaps_mem_info: "; + args += (traceConfig.report_smaps_mem_info() ? "true" : "false"); + args += ", report_purgeable_ashmem_info: "; + args += (traceConfig.report_purgeable_ashmem_info() ? "true" : "false"); + args += ", report_dma_mem_info: "; + args += (traceConfig.report_dma_mem_info() ? "true" : "false"); + args += ", report_gpu_mem_info: "; + args += (traceConfig.report_gpu_mem_info() ? "true" : "false"); + args += ", report_gpu_dump_info: "; + args += (traceConfig.report_gpu_dump_info() ? "true" : "false"); + args += ", report_fake_data: "; + args += (traceConfig.report_fake_data() ? "true" : "false"); + + args += ", "; + for (const auto& count : traceConfig.sys_meminfo_counters()) { + args += "sys_meminfo_counters: " + std::to_string(count) + ", "; + } + for (const auto& count : traceConfig.sys_vmeminfo_counters()) { + args += "sys_vmeminfo_counters: " + std::to_string(count) + ", "; + } + for (const auto& p : traceConfig.pid()) { + args += "pid: " + std::to_string(p) + ", "; + } + return args; +} + + template void MemoryDataPlugin::WriteMeminfo(T& memoryData) { int readsize = ReadFile(meminfoFd_); diff --git a/device/plugins/native_daemon/BUILD.gn b/device/plugins/native_daemon/BUILD.gn index b621388e6..a6f33f309 100644 --- a/device/plugins/native_daemon/BUILD.gn +++ b/device/plugins/native_daemon/BUILD.gn @@ -126,6 +126,7 @@ ohos_executable("native_daemon") { "access_token:libaccesstoken_sdk", "access_token:libtokensetproc_shared", "bounds_checking_function:libsec_shared", + "hisysevent:libhisysevent", "init:libbegetutil", "ipc:ipc_core", "openssl:libcrypto_shared", @@ -202,6 +203,7 @@ ohos_shared_library("libnative_daemon_client") { "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "c_utils:utils", + "hisysevent:libhisysevent", "init:libbegetutil", "ipc:ipc_core", "os_account:os_account_innerkits", diff --git a/device/plugins/native_daemon/include/hook_manager.h b/device/plugins/native_daemon/include/hook_manager.h index e3ab5a549..b1a321b75 100644 --- a/device/plugins/native_daemon/include/hook_manager.h +++ b/device/plugins/native_daemon/include/hook_manager.h @@ -104,6 +104,7 @@ public: int32_t CreatePluginSession(); void RegisterWriter(const std::shared_ptr writer); void WriteHookConfig(); + std::string GetCmdArgs(NativeHookConfig traceConfig); std::pair GetFds(int32_t pid, const std::string& name); inline void SetSaServiceConfig(bool saFlag, bool isProtobufSerialize) { diff --git a/device/plugins/native_daemon/native_memory_profiler_sa/test/BUILD.gn b/device/plugins/native_daemon/native_memory_profiler_sa/test/BUILD.gn index 30e4f0eee..20c462c81 100644 --- a/device/plugins/native_daemon/native_memory_profiler_sa/test/BUILD.gn +++ b/device/plugins/native_daemon/native_memory_profiler_sa/test/BUILD.gn @@ -127,6 +127,7 @@ ohos_unittest("native_memory_profiler_sa_ut") { "bounds_checking_function:libsec_shared", "c_utils:utils", "googletest:gtest", + "hisysevent:libhisysevent", "init:libbegetutil", "ipc:ipc_core", "openssl:libcrypto_shared", diff --git a/device/plugins/native_daemon/src/hook_manager.cpp b/device/plugins/native_daemon/src/hook_manager.cpp index 8034a892a..3cbc08fd6 100644 --- a/device/plugins/native_daemon/src/hook_manager.cpp +++ b/device/plugins/native_daemon/src/hook_manager.cpp @@ -763,6 +763,57 @@ void HookManager::StartPluginSession() PROFILER_LOG_INFO(LOG_CORE, "StartPluginSession: pid(%d) is less or equal zero.", item->pid); } } + int ret = COMMON::PluginWriteToHisysevent("native_hook_plugin", "sh", GetCmdArgs(hookConfig_), + COMMON::ErrorType::RET_SUCC, "success"); + PROFILER_LOG_INFO(LOG_CORE, "hisysevent report native_hook_plugin result:%d", ret); +} + +std::string HookManager::GetCmdArgs(NativeHookConfig traceConfig) +{ + std::string args; + args += "pid: " + std::to_string(traceConfig.pid()) + ", save_file: "; + args += (traceConfig.save_file() ? "true" : "false"); + args += ", file_name: " + traceConfig.file_name(); + args += ", filter_size: " + std::to_string(traceConfig.filter_size()); + args += ", smb_pages: " + std::to_string(traceConfig.smb_pages()); + args += ", max_stack_depth: " + std::to_string(traceConfig.max_stack_depth()); + args += ", process_name: " + traceConfig.process_name() + ", malloc_disable: "; + args += (traceConfig.malloc_disable() ? "true" : "false"); + args += ", mmap_disable: " + args += (traceConfig.mmap_disable() ? "true" : "false"); + args += ", free_stack_report: " + args += (traceConfig.free_stack_report() ? "true" : "false"); + args += ", munmap_stack_report: " + args += (traceConfig.munmap_stack_report() ? "true" : "false"); + args += ", malloc_free_matching_interval: " + std::to_string(traceConfig.malloc_free_matching_interval()); + args += ", malloc_free_matching_cnt: " + std::to_string(traceConfig.malloc_free_matching_cnt()); + args += ", string_compressed: " + args += (traceConfig.string_compressed() ? "true" : "false"); + args += ", fp_unwind: " + args += (traceConfig.fp_unwind() ? "true" : "false"); + args += ", blocked: " + args += (traceConfig.blocked() ? "true" : "false"); + args += ", record_accurately: " + args += (traceConfig.record_accurately() ? "true" : "false"); + args += ", startup_mode: " + args += (traceConfig.startup_mode() ? "true" : "false"); + args += ", memtrace_enable: " + args += (traceConfig.memtrace_enable() ? "true" : "false"); + args += ", offline_symbolization: " + args += (traceConfig.offline_symbolization() ? "true" : "false"); + args += ", callframe_compress: " + args += (traceConfig.callframe_compress() ? "true" : "false"); + args += ", statistics_interval: " + std::to_string(traceConfig.statistics_interval()); + args += ", clock: " + traceConfig.clock() + ", sample_interval: "; + args += std::to_string(traceConfig.sample_interval()) + ", response_library_mode: "; + args += (traceConfig.response_library_mode() ? "true" : "false"); + args += ", js_stack_report: " + std::to_string(traceConfig.js_stack_report()); + args += ", max_js_stack_depth: " + std::to_string(traceConfig.max_js_stack_depth()); + args += ", filter_napi_name: " + traceConfig.filter_napi_name() + ", "; + for (const auto& pid : traceConfig.expand_pids()) { + args += "expand_pids: " + std::to_string(p) + ", "; + } + return args; } void HookManager::WriteHookConfig() diff --git a/device/plugins/native_daemon/test/BUILD.gn b/device/plugins/native_daemon/test/BUILD.gn index aca1d7d6b..230cfb3a9 100644 --- a/device/plugins/native_daemon/test/BUILD.gn +++ b/device/plugins/native_daemon/test/BUILD.gn @@ -126,6 +126,7 @@ ohos_unittest("native_daemon_ut") { "bounds_checking_function:libsec_shared", "faultloggerd:libunwinder", "googletest:gtest", + "hisysevent:libhisysevent", "init:libbegetutil", "openssl:libcrypto_shared", "protobuf:protobuf_lite", diff --git a/device/plugins/network_plugin/BUILD.gn b/device/plugins/network_plugin/BUILD.gn index 52d9f4a66..8bfd64a67 100644 --- a/device/plugins/network_plugin/BUILD.gn +++ b/device/plugins/network_plugin/BUILD.gn @@ -39,6 +39,7 @@ ohos_source_set("networkplugin_source") { external_deps = [ "bounds_checking_function:libsec_shared", "hilog:libhilog_base", + "hisysevent:libhisysevent", "protobuf:protobuf_lite", ] } @@ -47,7 +48,10 @@ ohos_source_set("networkplugin_source") { ohos_shared_library("networkplugin") { output_name = "networkplugin" version_script = "libnetwork_plugin.map" - deps = [ ":networkplugin_source" ] + deps = [ + ":networkplugin_source", + "${OHOS_PROFILER_DIR}/device/base:hiprofiler_base", + ] if (current_toolchain != host_toolchain) { defines = [ "HAVE_HILOG" ] external_deps = [ "hilog:libhilog_base" ] diff --git a/device/plugins/network_plugin/include/network_plugin.h b/device/plugins/network_plugin/include/network_plugin.h index fb654f445..746629bae 100644 --- a/device/plugins/network_plugin/include/network_plugin.h +++ b/device/plugins/network_plugin/include/network_plugin.h @@ -93,6 +93,7 @@ protected: bool ReadSystemTxRxBytes(NetSystemData &systemData); void AddNetDetails(NetworkCell& cell, NetDetails& data); void AddNetSystemDetails(NetSystemData& systemData, NetSystemDetails& data); + std::string GetCmdArgs(NetworkConfig traceConfig); // for UT void setPathForTest(std::string path) { diff --git a/device/plugins/network_plugin/src/network_plugin.cpp b/device/plugins/network_plugin/src/network_plugin.cpp index 07eeeb176..a9f1a7ff3 100644 --- a/device/plugins/network_plugin/src/network_plugin.cpp +++ b/device/plugins/network_plugin/src/network_plugin.cpp @@ -18,6 +18,7 @@ #include #include "buffer_splitter.h" +#include "common.h" #include "network_plugin_result.pbencoder.h" #include "securec.h" @@ -47,11 +48,22 @@ int NetworkPlugin::Start(const uint8_t* configData, uint32_t configSize) pidUid_.emplace(pid, GetUid(pid)); } - PROFILER_LOG_INFO(LOG_CORE, "%s:NetworkPlugin, start success!", __func__); - + int ret = COMMON::PluginWriteToHisysevent("network_plugin", "sh", GetCmdArgs(protoConfig_), + COMMON::ErrorType::RET_SUCC, "success"); + PROFILER_LOG_INFO(LOG_CORE, "%s: NetworkPlugin success! hisysevent report result:%d", __func__, ret); return 0; } +std::string NetworkPlugin::GetCmdArgs(NetworkConfig traceConfig) +{ + std::string args; + for (const auto& p : traceConfig.pid()) { + args += "pid: " + std::to_string(p) + ", "; + } + args += "test_file: " + traceConfig.test_file(); + return args; +} + template bool NetworkPlugin::WriteNetWorkData(T& networkDatasProto) { std::string file = GetRateNodePath(); diff --git a/device/plugins/network_plugin/test/BUILD.gn b/device/plugins/network_plugin/test/BUILD.gn index 2ce820703..e0545b114 100644 --- a/device/plugins/network_plugin/test/BUILD.gn +++ b/device/plugins/network_plugin/test/BUILD.gn @@ -26,6 +26,7 @@ ohos_unittest("networkplugin_ut") { module_out_path = module_output_path sources = [ "unittest/network_plugin_test.cpp" ] deps = [ + "${OHOS_PROFILER_DIR}/device/base:hiprofiler_base", "${OHOS_PROFILER_DIR}/device/plugins/network_plugin:networkplugin_source", "${OHOS_PROFILER_DIR}/protos/types/plugins/network_data:network_data_cpp", ] diff --git a/device/plugins/network_plugin/test/fuzztest/networkstartplugin_fuzzer/BUILD.gn b/device/plugins/network_plugin/test/fuzztest/networkstartplugin_fuzzer/BUILD.gn index 84e898157..90b63a2c7 100644 --- a/device/plugins/network_plugin/test/fuzztest/networkstartplugin_fuzzer/BUILD.gn +++ b/device/plugins/network_plugin/test/fuzztest/networkstartplugin_fuzzer/BUILD.gn @@ -28,6 +28,7 @@ ohos_fuzztest("NetworkStartPluginFuzzTest") { ] sources = [ "networkstartplugin_fuzzer.cpp" ] deps = [ + "${OHOS_PROFILER_DIR}/device/base:hiprofiler_base", "${OHOS_PROFILER_DIR}/device/plugins/network_plugin:networkplugin_source", "${OHOS_PROFILER_DIR}/protos/types/plugins/network_data:network_data_cpp", ] diff --git a/device/plugins/network_profiler/service/BUILD.gn b/device/plugins/network_profiler/service/BUILD.gn index 61014e5c4..8e76a46de 100644 --- a/device/plugins/network_profiler/service/BUILD.gn +++ b/device/plugins/network_profiler/service/BUILD.gn @@ -49,6 +49,7 @@ ohos_source_set("network_profiler_service") { ] external_deps = [ + "hisysevent:libhisysevent", "init:libbegetutil", "protobuf:protobuf_lite", ] diff --git a/device/plugins/network_profiler/service/include/network_profiler_manager.h b/device/plugins/network_profiler/service/include/network_profiler_manager.h index 57d26b652..528dfec67 100644 --- a/device/plugins/network_profiler/service/include/network_profiler_manager.h +++ b/device/plugins/network_profiler/service/include/network_profiler_manager.h @@ -71,9 +71,13 @@ public: bool ResetWriter(uint32_t pluginId) override; void SetCommandPoller(const std::shared_ptr& p) override; bool RegisterAgentPlugin(const std::string& pluginPath); + std::string GetCmdArgs(NetworkProfilerConfig traceConfig); private: bool CheckConfig(); + bool CheckConfigPid(std::set& pidCache); + bool CheckStartupProcessName(); + bool CheckRestartProcessName(std::set& pidCache); bool HandleNetworkProfilerContext(const std::shared_ptr& ctx); clockid_t GetClockId(NetworkProfilerConfig::ClockId clockType); diff --git a/device/plugins/network_profiler/service/src/network_profiler_manager.cpp b/device/plugins/network_profiler/service/src/network_profiler_manager.cpp index adcaf2a66..5d62fb4c4 100644 --- a/device/plugins/network_profiler/service/src/network_profiler_manager.cpp +++ b/device/plugins/network_profiler/service/src/network_profiler_manager.cpp @@ -57,9 +57,8 @@ void NetworkProfilerManager::Init() RegisterAgentPlugin("network-profiler"); } -bool NetworkProfilerManager::CheckConfig() +bool NetworkProfilerManager::CheckConfigPid(std::set& pidCache) { - std::set pidCache; for (const auto& pid : config_.pid()) { if (pid > 0) { if (COMMON::IsUserMode() && (!COMMON::CheckApplicationPermission(pid, ""))) { @@ -70,17 +69,19 @@ bool NetworkProfilerManager::CheckConfig() 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) { - networkCtx_.emplace_back(std::make_shared(pid)); - paramValue_ += std::to_string(pid) + ","; - } - continue; + } + auto [iter, ret] = pidCache.emplace(pid); + if (ret) { + networkCtx_.emplace_back(std::make_shared(pid)); + paramValue_ += std::to_string(pid) + ","; } } } + return true; +} +bool NetworkProfilerManager::CheckStartupProcessName() +{ for (const auto& name : config_.startup_process_name()) { if (name.empty()) { continue; @@ -98,7 +99,11 @@ bool NetworkProfilerManager::CheckConfig() networkCtx_.emplace_back(std::make_shared(name)); } } + return true; +} +bool NetworkProfilerManager::CheckRestartProcessName(std::set& pidCache) +{ for (const auto& name : config_.restart_process_name()) { if (name.empty()) { continue; @@ -123,6 +128,21 @@ bool NetworkProfilerManager::CheckConfig() return false; } } + return true; +} + +bool NetworkProfilerManager::CheckConfig() +{ + std::set pidCache; + if (!CheckConfigPid(pidCache)) { + return false; + } + if (!CheckStartupProcessName()) { + return false; + } + if (!CheckRestartProcessName(pidCache)) { + return false; + } if (config_.flush_interval() == 0) { config_.set_flush_interval(1); @@ -170,15 +190,42 @@ bool NetworkProfilerManager::StartNetworkProfiler() int ret = SystemSetParameter(PARAM_KAY.c_str(), paramValue_.c_str()); PROFILER_LOG_INFO(LOG_CORE, "StartNetworkProfiler parameter: %s", paramValue_.c_str()); + + auto args = GetCmdArgs(config_); if (ret < 0) { PROFILER_LOG_ERROR(LOG_CORE, "StartNetworkProfiler set parameter failed"); + COMMON::PluginWriteToHisysevent("network_profiler_plugin", "sh", args, COMMON::ErrorType::RET_FAIL, + "set param failed"); return false; } else { PROFILER_LOG_INFO(LOG_CORE, "StartNetworkProfiler set parameter success"); } + + int res = COMMON::PluginWriteToHisysevent("memory_plugin", "sh", args, COMMON::ErrorType::RET_SUCC, "success"); + PROFILER_LOG_INFO(LOG_CORE, "hisysevent report network_profiler_plugin ret: %d.", res); return true; } +std::string NetworkProfilerManager::GetCmdArgs(NetworkProfilerConfig traceConfig) +{ + std::string args; + for (const auto& p : traceConfig.pid()) { + args += "pid: " + std::to_string(p) + ", "; + } + for (const auto& name : traceConfig.startup_process_name()) { + args += "startup_process_name: " + name + ", "; + } + for (const auto& name : traceConfig.restart_process_name()) { + args += "restart_process_name: " + name + ", "; + } + args += "clock_id: " + std::to_string(traceConfig.clock_id()); + args += ", smb_pages: " + std::to_string(traceConfig.smb_pages()); + args += ", flush_interval: " + std::to_string(traceConfig.flush_interval()); + args += ", block: "; + args += (traceConfig.block() ? "true" : "false"); + return args; +} + void NetworkProfilerManager::StopNetworkProfiler() { int ret = SystemSetParameter(PARAM_KAY.c_str(), ""); diff --git a/device/plugins/process_plugin/BUILD.gn b/device/plugins/process_plugin/BUILD.gn index 15dbfd4d6..2a9373cba 100644 --- a/device/plugins/process_plugin/BUILD.gn +++ b/device/plugins/process_plugin/BUILD.gn @@ -37,6 +37,7 @@ ohos_source_set("processplugin_source") { external_deps = [ "bounds_checking_function:libsec_shared", "hilog:libhilog_base", + "hisysevent:libhisysevent", "protobuf:protobuf_lite", ] } @@ -48,7 +49,10 @@ ohos_source_set("processplugin_source") { ohos_shared_library("processplugin") { output_name = "processplugin" version_script = "libprocess_plugin.map" - deps = [ ":processplugin_source" ] + deps = [ + ":processplugin_source", + "${OHOS_PROFILER_DIR}/device/base:hiprofiler_base", + ] if (current_toolchain != host_toolchain) { defines = [ "HAVE_HILOG" ] external_deps = [ "hilog:libhilog_base" ] diff --git a/device/plugins/process_plugin/include/process_data_plugin.h b/device/plugins/process_plugin/include/process_data_plugin.h index 7af76c359..0a4f7591f 100644 --- a/device/plugins/process_plugin/include/process_data_plugin.h +++ b/device/plugins/process_plugin/include/process_data_plugin.h @@ -95,6 +95,8 @@ private: template bool WritePssData(int pid, T& processinfo); + std::string GetCmdArgs(ProcessConfig traceConfig); + ProcessConfig protoConfig_; std::unique_ptr buffer_; std::vector pids_; diff --git a/device/plugins/process_plugin/src/process_data_plugin.cpp b/device/plugins/process_plugin/src/process_data_plugin.cpp index 470a6dcbc..e40580627 100644 --- a/device/plugins/process_plugin/src/process_data_plugin.cpp +++ b/device/plugins/process_plugin/src/process_data_plugin.cpp @@ -20,6 +20,8 @@ #include #include "buffer_splitter.h" +#include "common.h" +#include "hisysevent.h" #include "process_plugin_result.pbencoder.h" #include "securec.h" @@ -56,10 +58,26 @@ int ProcessDataPlugin::Start(const uint8_t* configData, uint32_t configSize) CHECK_TRUE(protoConfig_.ParseFromArray(configData, configSize) > 0, RET_FAIL, "%s:parseFromArray failed!", __func__); - PROFILER_LOG_INFO(LOG_CORE, "%s:start success!", __func__); + int ret = COMMON::PluginWriteToHisysevent("process_plugin", "sh", GetCmdArgs(protoConfig_), + COMMON::ErrorType::RET_SUCC, "success"); + PROFILER_LOG_INFO(LOG_CORE, "%s: success! hisysevent report process_plugin result:%d", __func__, ret); return RET_SUCC; } +std::string ProcessDataPlugin::GetCmdArgs(ProcessConfig traceConfig) +{ + std::string args; + args += "report_process_tree: "; + args += (traceConfig.report_process_tree() ? "true" : "false"); + args += ", report_cpu: "; + args += (traceConfig.report_cpu() ? "true" : "false"); + args += ", report_diskio: "; + args += (traceConfig.report_diskio() ? "true" : "false"); + args += ", report_pss: "; + args += (traceConfig.report_pss() ? "true" : "false"); + return args; +} + int ProcessDataPlugin::ReportOptimize(RandomWriteCtx* randomWrite) { ProtoEncoder::ProcessData dataProto(randomWrite); diff --git a/device/plugins/xpower_plugin/BUILD.gn b/device/plugins/xpower_plugin/BUILD.gn index 5f713d2e3..9873f086f 100644 --- a/device/plugins/xpower_plugin/BUILD.gn +++ b/device/plugins/xpower_plugin/BUILD.gn @@ -36,6 +36,7 @@ ohos_shared_library("xpowerplugin") { external_deps = [ "bounds_checking_function:libsec_shared", "hilog:libhilog_base", + "hisysevent:libhisysevent", "protobuf:protobuf_lite", ] } diff --git a/device/plugins/xpower_plugin/include/xpower_plugin.h b/device/plugins/xpower_plugin/include/xpower_plugin.h index f43ae1da3..f09cb2649 100644 --- a/device/plugins/xpower_plugin/include/xpower_plugin.h +++ b/device/plugins/xpower_plugin/include/xpower_plugin.h @@ -34,6 +34,7 @@ public: void OptimizeCallback(const std::uint32_t messageType, const uint8_t* protoData, size_t protoSize); void SetWriter(WriterStruct* writer); bool StartPowerManager(std::uint32_t messageType, std::string& bundleName); + std::string GetCmdArgs(XpowerConfig traceConfig); private: void* powerClientHandle_ = nullptr; XpowerConfig protoConfig_; diff --git a/device/plugins/xpower_plugin/src/xpower_plugin.cpp b/device/plugins/xpower_plugin/src/xpower_plugin.cpp index c9d8c224c..5f3508c78 100644 --- a/device/plugins/xpower_plugin/src/xpower_plugin.cpp +++ b/device/plugins/xpower_plugin/src/xpower_plugin.cpp @@ -48,6 +48,17 @@ XpowerPlugin::~XpowerPlugin() } } +std::string XpowerPlugin::GetCmdArgs(XpowerConfig traceConfig) +{ + std::string args; + + args += "bundle_name: " + traceConfig.bundle_name() + ", "; + for (const auto& type : traceConfig.message_type()) { + args += "type: " + std::to_string(type) + ", "; + } + return args; +} + int XpowerPlugin::Start(const uint8_t *configData, uint32_t configSize) { PROFILER_LOG_INFO(LOG_CORE, "%s:config data -->configSize=%d", __func__, configSize); @@ -63,8 +74,11 @@ int XpowerPlugin::Start(const uint8_t *configData, uint32_t configSize) messageType |= mesType; } } + auto args = GetCmdArgs(protoConfig_); if (messageType == 0) { PROFILER_LOG_ERROR(LOG_CORE, "XpowerPlugin error : messageType is empty!"); + COMMON::PluginWriteToHisysevent("xpower_plugin", "sh", args, COMMON::ErrorType::RET_MSG_EMPTY, + "messageType is empty"); return -1; } PROFILER_LOG_INFO(LOG_CORE, "bundleName is %s,messagetype is %d", bundleName.c_str(), messageType); @@ -73,12 +87,16 @@ int XpowerPlugin::Start(const uint8_t *configData, uint32_t configSize) (messageType & OptimizeMessageType::MESSAGE_ABNORMAL_EVENTS) != 0) { if (bundleName.empty()) { PROFILER_LOG_ERROR(LOG_CORE, "XpowerPlugin error : bundle name is empty!"); + COMMON::PluginWriteToHisysevent("xpower_plugin", "sh", args, COMMON::ErrorType::RET_MSG_EMPTY, + "bundle name is empty"); return -1; } // check bundleName int32_t uid = COMMON::GetPackageUid(bundleName); if (uid < AID_HAP_START || uid > AID_HAP_END) { PROFILER_LOG_ERROR(LOG_CORE, "the bundle name %s is not supported", bundleName.c_str()); + COMMON::PluginWriteToHisysevent("xpower_plugin", "sh", args, COMMON::ErrorType::RET_NOT_SUPPORT, + "bundle name is not supported"); return -1; } } @@ -87,6 +105,8 @@ int XpowerPlugin::Start(const uint8_t *configData, uint32_t configSize) bool isExsit = COMMON::IsProcessExist(bundleName, processId); if (!isExsit) { PROFILER_LOG_ERROR(LOG_CORE, "%s:the process %s does not exist.", __func__, bundleName.c_str()); + COMMON::PluginWriteToHisysevent("xpower_plugin", "sh", args, COMMON::ErrorType::RET_IVALID_PID, + "the process does not exist"); return -1; } } @@ -94,9 +114,13 @@ int XpowerPlugin::Start(const uint8_t *configData, uint32_t configSize) // 加载对应so 库文件 if (!StartPowerManager(messageType, bundleName)) { PROFILER_LOG_ERROR(LOG_CORE, "start power manager failed!"); + COMMON::PluginWriteToHisysevent("xpower_plugin", "sh", args, COMMON::ErrorType::RET_FAIL, + "start power manager failed"); return -1; } - PROFILER_LOG_INFO(LOG_CORE, "finish register the callback function:%s", __func__); + int ret = COMMON::PluginWriteToHisysevent("xpower_plugin", "sh", args, COMMON::ErrorType::RET_SUCC, "success"); + PROFILER_LOG_INFO(LOG_CORE, "finish register the callback function:%s, hisysevent report xpower_plugin ret: %d.", + __func__, ret); return 0; } diff --git a/hiprofiler.yaml b/hiprofiler.yaml new file mode 100644 index 000000000..f46ad883a --- /dev/null +++ b/hiprofiler.yaml @@ -0,0 +1,22 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +domain: PROFILER + +HIPROFILER_USAGE: + __BASE: {type: STATISTIC, level: CRITICAL, tag: usageStats, desc: cpu_plugin usage statistics} + PLUGIN_NAME: { type: STRING desc: hiprofiler plugin name } + CALLER: {type: STRING, desc: hiprofiler caller} sh + ARGS: {type: STRING, desc: hiprofiler plugin args} + ERROR_CODE: { type: INT32. desc: hiprofiler request error code } + ERROR_MESSAGE: { type: STRING, desc: hiprofiler request error message} diff --git a/interfaces/kits/test/BUILD.gn b/interfaces/kits/test/BUILD.gn index 4ff1ae1d5..2e9555caf 100644 --- a/interfaces/kits/test/BUILD.gn +++ b/interfaces/kits/test/BUILD.gn @@ -60,6 +60,7 @@ ohos_unittest("plugin_module_api_ut") { "googletest:gtest", "hidumper:lib_dump_usage", "hilog:libhilog_base", + "hisysevent:libhisysevent", "hiview:libucollection_graphic", "protobuf:protobuf_lite", ]