diff --git a/BUILD.gn b/BUILD.gn old mode 100755 new mode 100644 index 9eeff83..f19d9c7 --- a/BUILD.gn +++ b/BUILD.gn @@ -197,7 +197,11 @@ ohos_source_set("hiperf_enable_hisysevent") { public_configs = common_configs sources = [ "./src/command_reporter.cpp" ] - external_deps = [ "hisysevent:libhisysevent" ] + external_deps = [ + "hisysevent:libhisysevent", + "c_utils:utils", + "hilog:libhilog", + ] defines = [ "ENABLE_HISYSEVENT" ] } diff --git a/bundle.json b/bundle.json old mode 100755 new mode 100644 diff --git a/include/command_reporter.h b/include/command_reporter.h old mode 100755 new mode 100644 index 44c1bc7..2ccfc3f --- a/include/command_reporter.h +++ b/include/command_reporter.h @@ -28,12 +28,18 @@ public: std::string mainCommand_ = ""; std::string subCommand_ = ""; + std::string caller_ = ""; std::string targetProcess_ = ""; int32_t errorCode_ = 0; std::string errorMessage_ = ""; private: bool isReported = false; + + CommandReporter(const CommandReporter&) = delete; + CommandReporter& operator=(const CommandReporter&) = delete; + CommandReporter(CommandReporter&&) = delete; + CommandReporter& operator=(CommandReporter&&) = delete; }; } // namespace OHOS::Developtools::HiPerf diff --git a/include/subcommand.h b/include/subcommand.h old mode 100755 new mode 100644 diff --git a/include/subcommand_dump.h b/include/subcommand_dump.h old mode 100755 new mode 100644 diff --git a/include/subcommand_record.h b/include/subcommand_record.h old mode 100755 new mode 100644 diff --git a/include/subcommand_report.h b/include/subcommand_report.h old mode 100755 new mode 100644 diff --git a/include/subcommand_stat.h b/include/subcommand_stat.h old mode 100755 new mode 100644 diff --git a/src/command.cpp b/src/command.cpp old mode 100755 new mode 100644 diff --git a/src/command_reporter.cpp b/src/command_reporter.cpp index d87e737..bd7d9f1 100755 --- a/src/command_reporter.cpp +++ b/src/command_reporter.cpp @@ -17,12 +17,18 @@ #ifdef ENABLE_HISYSEVENT #include "hisysevent.h" -#include "debug_logger.h" +#include "utilities.h" +#include "hiperf_hilog.h" #endif namespace OHOS::Developtools::HiPerf { -CommandReporter::CommandReporter(const std::string& fullArgument) : subCommand_(fullArgument) {} +CommandReporter::CommandReporter(const std::string& fullArgument) : subCommand_(fullArgument) +{ +#ifdef ENABLE_HISYSEVENT + caller_ = GetProcessName(getppid()); +#endif +} CommandReporter::~CommandReporter() { @@ -33,20 +39,21 @@ void CommandReporter::ReportCommand() { #ifdef ENABLE_HISYSEVENT if (isReported) { - HLOGW("command has been reported"); + HIPERF_HILOGD(MODULE_DEFAULT, "command has been reported"); return; } int32_t ret = HiSysEventWrite( - OHOS::HiviewDFX::HiSysEvent::Domain::GRAPHIC, "HIPERF_USAGE", + OHOS::HiviewDFX::HiSysEvent::Domain::PROFILER, "HIPERF_USAGE", OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, "MAIN_CMD", mainCommand_, "SUB_CMD", subCommand_, + "CALLER", caller_, "TARGET_PROCESS", targetProcess_, "ERROR_CODE", errorCode_, "ERROR_MESSAGE", errorMessage_); if (ret != 0) { - HLOGE("hisysevent report failed, err:%d", ret); + HIPERF_HILOGE(MODULE_DEFAULT, "hisysevent report failed, err:%{public}d", ret); } #endif isReported = true; diff --git a/src/subcommand_dump.cpp b/src/subcommand_dump.cpp old mode 100755 new mode 100644 diff --git a/src/subcommand_record.cpp b/src/subcommand_record.cpp old mode 100755 new mode 100644 diff --git a/src/subcommand_stat.cpp b/src/subcommand_stat.cpp old mode 100755 new mode 100644 diff --git a/test/BUILD.gn b/test/BUILD.gn old mode 100755 new mode 100644 diff --git a/test/unittest/common/native/subcommand_record_test.cpp b/test/unittest/common/native/subcommand_record_test.cpp old mode 100755 new mode 100644 index b511d7a..8b44341 --- a/test/unittest/common/native/subcommand_record_test.cpp +++ b/test/unittest/common/native/subcommand_record_test.cpp @@ -1608,7 +1608,7 @@ HWTEST_F(SubCommandRecordTest, ReportSamplePid, TestSize.Level1) CommandReporter reporter("record"); command.AddReportArgs(reporter); - EXPECT_EQ(reporter.targetProcess_, "ALL"); + EXPECT_EQ(reporter.targetProcess_, "1,2,3"); } /** @@ -1619,11 +1619,11 @@ HWTEST_F(SubCommandRecordTest, ReportSamplePid, TestSize.Level1) HWTEST_F(SubCommandRecordTest, ReportSampleApp, TestSize.Level1) { SubCommandRecord command; - command.targetSystemWide_ = true; + command.appPackage_ = "com.test.app"; CommandReporter reporter("record"); command.AddReportArgs(reporter); - EXPECT_EQ(reporter.targetProcess_, "ALL"); + EXPECT_EQ(reporter.targetProcess_, "com.test.app"); } } // namespace HiPerf diff --git a/test/unittest/common/native/subcommand_stat_test.cpp b/test/unittest/common/native/subcommand_stat_test.cpp old mode 100755 new mode 100644 index 2813919..1b8dc95 --- a/test/unittest/common/native/subcommand_stat_test.cpp +++ b/test/unittest/common/native/subcommand_stat_test.cpp @@ -2286,7 +2286,7 @@ HWTEST_F(SubCommandStatTest, ReportSamplePid, TestSize.Level1) CommandReporter reporter("stat"); command.AddReportArgs(reporter); - EXPECT_EQ(reporter.targetProcess_, "ALL"); + EXPECT_EQ(reporter.targetProcess_, "1,2,3"); } /** @@ -2301,7 +2301,7 @@ HWTEST_F(SubCommandStatTest, ReportSampleApp, TestSize.Level1) CommandReporter reporter("stat"); command.AddReportArgs(reporter); - EXPECT_EQ(reporter.targetProcess_, "ALL"); + EXPECT_EQ(reporter.targetProcess_, "com.test.app"); } } // namespace HiPerf } // namespace Developtools