From a4603bedabcfffede5a8c6ba147c52f3c40855b3 Mon Sep 17 00:00:00 2001 From: yuanye Date: Tue, 5 Nov 2024 17:30:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E9=9A=94=E7=A6=BB=E5=AE=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yuanye --- BUILD.gn | 39 ++----------------- include/command_reporter.h | 10 ++++- src/command_reporter.cpp | 10 ++--- test/BUILD.gn | 2 - .../common/native/subcommand_record_test.cpp | 3 ++ .../common/native/subcommand_stat_test.cpp | 3 ++ 6 files changed, 24 insertions(+), 43 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index f19d9c7..4950860 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -116,6 +116,7 @@ config("hiperf_inner_config") { sources_platform_common = [ "./src/command.cpp", + "./src/command_reporter.cpp", "./src/dwarf_encoding.cpp", "./src/ipc_utilities.cpp", "./src/option.cpp", @@ -189,32 +190,6 @@ if (is_ohos && hiperf_use_syspara) { common_configs += [ ":hiperf_syspara_config" ] } -ohos_source_set("hiperf_enable_hisysevent") { - part_name = "hiperf" - subsystem_name = "developtools" - use_exceptions = true - public_deps = common_deps - public_configs = common_configs - - sources = [ "./src/command_reporter.cpp" ] - external_deps = [ - "hisysevent:libhisysevent", - "c_utils:utils", - "hilog:libhilog", - ] - defines = [ "ENABLE_HISYSEVENT" ] -} - -ohos_source_set("hiperf_disable_hisysevent") { - part_name = "hiperf" - subsystem_name = "developtools" - use_exceptions = true - public_deps = common_deps - public_configs = common_configs - - sources = [ "./src/command_reporter.cpp" ] -} - ohos_source_set("hiperf_platform_common") { part_name = "hiperf" subsystem_name = "developtools" @@ -228,6 +203,7 @@ ohos_source_set("hiperf_platform_common") { "c_utils:utils", "faultloggerd:libunwinder_static", "hilog:libhilog", + "hisysevent:libhisysevent", "init:libbegetutil", "ipc:ipc_core", "samgr:samgr_proxy", @@ -410,7 +386,6 @@ ohos_executable("hiperf") { ":hiperf_etc", ":hiperf_platform_common", ":hiperf_platform_linux", - ":hiperf_enable_hisysevent", ] if (hiperf_target_static) { @@ -434,10 +409,7 @@ ohos_executable("hiperf") { ohos_executable("hiperf_host") { sources = [ "./src/main.cpp" ] - deps = [ - ":hiperf_platform_common", - ":hiperf_disable_hisysevent" - ] + deps = [ ":hiperf_platform_common" ] external_deps = [ "bounds_checking_function:libsec_shared", @@ -497,10 +469,7 @@ ohos_source_set("hiperf_platform_host") { } ohos_shared_library("hiperf_host_lib") { - public_deps = [ - ":hiperf_platform_host", - ":hiperf_disable_hisysevent" - ] + public_deps = [ ":hiperf_platform_host" ] output_name = "hiperf_report" ldflags = [ "-static-libstdc++" ] diff --git a/include/command_reporter.h b/include/command_reporter.h index 2ccfc3f..b1b859d 100644 --- a/include/command_reporter.h +++ b/include/command_reporter.h @@ -16,6 +16,7 @@ #define COMMAND_REPORTER_H_ #include +#include namespace OHOS::Developtools::HiPerf { @@ -34,12 +35,19 @@ public: std::string errorMessage_ = ""; private: - bool isReported = false; + bool isReported_ = false; CommandReporter(const CommandReporter&) = delete; CommandReporter& operator=(const CommandReporter&) = delete; CommandReporter(CommandReporter&&) = delete; CommandReporter& operator=(CommandReporter&&) = delete; + + FRIEND_TEST(SubCommandRecordTest, ReportSampleAll); + FRIEND_TEST(SubCommandRecordTest, ReportSamplePid); + FRIEND_TEST(SubCommandRecordTest, ReportSampleApp); + FRIEND_TEST(SubCommandStatTest, ReportSampleAll); + FRIEND_TEST(SubCommandStatTest, ReportSamplePid); + FRIEND_TEST(SubCommandStatTest, ReportSampleApp); }; } // namespace OHOS::Developtools::HiPerf diff --git a/src/command_reporter.cpp b/src/command_reporter.cpp index f8822d4..6b99870 100755 --- a/src/command_reporter.cpp +++ b/src/command_reporter.cpp @@ -15,7 +15,7 @@ #include "command_reporter.h" -#ifdef ENABLE_HISYSEVENT +#if defined(is_ohos) && is_ohos #include "hiperf_hilog.h" #include "hisysevent.h" #include "utilities.h" @@ -25,7 +25,7 @@ namespace OHOS::Developtools::HiPerf { CommandReporter::CommandReporter(const std::string& fullArgument) : subCommand_(fullArgument) { -#ifdef ENABLE_HISYSEVENT +#if defined(is_ohos) && is_ohos caller_ = GetProcessName(getppid()); #endif } @@ -37,8 +37,8 @@ CommandReporter::~CommandReporter() void CommandReporter::ReportCommand() { -#ifdef ENABLE_HISYSEVENT - if (isReported) { +#if defined(is_ohos) && is_ohos + if (isReported_) { HIPERF_HILOGD(MODULE_DEFAULT, "command has been reported"); return; } @@ -56,7 +56,7 @@ void CommandReporter::ReportCommand() HIPERF_HILOGE(MODULE_DEFAULT, "hisysevent report failed, err:%{public}d", ret); } #endif - isReported = true; + isReported_ = true; } } // namespace OHOS::Developtools::HiPerf diff --git a/test/BUILD.gn b/test/BUILD.gn index 558c3f7..97713e8 100755 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -67,7 +67,6 @@ common_deps = [ "${hiperf_path}/:hiperf_platform_common", "${hiperf_path}/:hiperf_platform_host", "${hiperf_path}/:hiperf_platform_linux", - "${hiperf_path}/:hiperf_disable_hisysevent", "${hiperf_path}/interfaces/innerkits/native:hiperf_client_static", "//third_party/googletest:gmock_main", "//third_party/googletest:gtest_main", @@ -121,7 +120,6 @@ fuzz_deps = [ "${hiperf_path}/:hiperf_platform_common", "${hiperf_path}/:hiperf_platform_host", "${hiperf_path}/:hiperf_platform_linux", - "${hiperf_path}/:hiperf_disable_hisysevent", "${hiperf_path}/interfaces/innerkits/native:hiperf_client_static", ] diff --git a/test/unittest/common/native/subcommand_record_test.cpp b/test/unittest/common/native/subcommand_record_test.cpp index 8b44341..19e7ba0 100644 --- a/test/unittest/common/native/subcommand_record_test.cpp +++ b/test/unittest/common/native/subcommand_record_test.cpp @@ -1592,6 +1592,7 @@ HWTEST_F(SubCommandRecordTest, ReportSampleAll, TestSize.Level1) command.targetSystemWide_ = true; CommandReporter reporter("record"); + reporter.isReported_ = true; command.AddReportArgs(reporter); EXPECT_EQ(reporter.targetProcess_, "ALL"); } @@ -1607,6 +1608,7 @@ HWTEST_F(SubCommandRecordTest, ReportSamplePid, TestSize.Level1) command.selectPids_ = {1, 2, 3}; CommandReporter reporter("record"); + reporter.isReported_ = true; command.AddReportArgs(reporter); EXPECT_EQ(reporter.targetProcess_, "1,2,3"); } @@ -1622,6 +1624,7 @@ HWTEST_F(SubCommandRecordTest, ReportSampleApp, TestSize.Level1) command.appPackage_ = "com.test.app"; CommandReporter reporter("record"); + reporter.isReported_ = true; command.AddReportArgs(reporter); EXPECT_EQ(reporter.targetProcess_, "com.test.app"); } diff --git a/test/unittest/common/native/subcommand_stat_test.cpp b/test/unittest/common/native/subcommand_stat_test.cpp index 1afba68..3e36144 100755 --- a/test/unittest/common/native/subcommand_stat_test.cpp +++ b/test/unittest/common/native/subcommand_stat_test.cpp @@ -2270,6 +2270,7 @@ HWTEST_F(SubCommandStatTest, ReportSampleAll, TestSize.Level1) command.targetSystemWide_ = true; CommandReporter reporter("stat"); + reporter.isReported_ = true; command.AddReportArgs(reporter); EXPECT_EQ(reporter.targetProcess_, "ALL"); } @@ -2285,6 +2286,7 @@ HWTEST_F(SubCommandStatTest, ReportSamplePid, TestSize.Level1) command.selectPids_ = {1, 2, 3}; CommandReporter reporter("stat"); + reporter.isReported_ = true; command.AddReportArgs(reporter); EXPECT_EQ(reporter.targetProcess_, "1,2,3"); } @@ -2300,6 +2302,7 @@ HWTEST_F(SubCommandStatTest, ReportSampleApp, TestSize.Level1) command.appPackage_ = "com.test.app"; CommandReporter reporter("stat"); + reporter.isReported_ = true; command.AddReportArgs(reporter); EXPECT_EQ(reporter.targetProcess_, "com.test.app"); }