From a52ee8d19047a92b2352a1b8601c942aa4f8eb06 Mon Sep 17 00:00:00 2001 From: yuanye Date: Mon, 4 Nov 2024 19:48:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yuanye --- BUILD.gn | 6 +++++- bundle.json | 0 include/command_reporter.h | 6 ++++++ include/subcommand.h | 0 include/subcommand_dump.h | 0 include/subcommand_record.h | 0 include/subcommand_report.h | 0 include/subcommand_stat.h | 0 src/command.cpp | 0 src/command_reporter.cpp | 17 ++++++++++++----- src/subcommand_dump.cpp | 0 src/subcommand_record.cpp | 0 src/subcommand_stat.cpp | 0 test/BUILD.gn | 0 .../common/native/subcommand_record_test.cpp | 6 +++--- .../common/native/subcommand_stat_test.cpp | 4 ++-- 16 files changed, 28 insertions(+), 11 deletions(-) mode change 100755 => 100644 BUILD.gn mode change 100755 => 100644 bundle.json mode change 100755 => 100644 include/command_reporter.h mode change 100755 => 100644 include/subcommand.h mode change 100755 => 100644 include/subcommand_dump.h mode change 100755 => 100644 include/subcommand_record.h mode change 100755 => 100644 include/subcommand_report.h mode change 100755 => 100644 include/subcommand_stat.h mode change 100755 => 100644 src/command.cpp mode change 100755 => 100644 src/subcommand_dump.cpp mode change 100755 => 100644 src/subcommand_record.cpp mode change 100755 => 100644 src/subcommand_stat.cpp mode change 100755 => 100644 test/BUILD.gn mode change 100755 => 100644 test/unittest/common/native/subcommand_record_test.cpp mode change 100755 => 100644 test/unittest/common/native/subcommand_stat_test.cpp 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