修改代码

Signed-off-by: yuanye <yuanye64@huawei.com>
This commit is contained in:
yuanye 2024-11-04 19:48:55 +08:00
parent 0c40f391bd
commit a52ee8d190
16 changed files with 28 additions and 11 deletions

6
BUILD.gn Executable file → Normal file
View File

@ -197,7 +197,11 @@ ohos_source_set("hiperf_enable_hisysevent") {
public_configs = common_configs public_configs = common_configs
sources = [ "./src/command_reporter.cpp" ] sources = [ "./src/command_reporter.cpp" ]
external_deps = [ "hisysevent:libhisysevent" ] external_deps = [
"hisysevent:libhisysevent",
"c_utils:utils",
"hilog:libhilog",
]
defines = [ "ENABLE_HISYSEVENT" ] defines = [ "ENABLE_HISYSEVENT" ]
} }

0
bundle.json Executable file → Normal file
View File

6
include/command_reporter.h Executable file → Normal file
View File

@ -28,12 +28,18 @@ public:
std::string mainCommand_ = ""; std::string mainCommand_ = "";
std::string subCommand_ = ""; std::string subCommand_ = "";
std::string caller_ = "";
std::string targetProcess_ = ""; std::string targetProcess_ = "";
int32_t errorCode_ = 0; int32_t errorCode_ = 0;
std::string errorMessage_ = ""; std::string errorMessage_ = "";
private: private:
bool isReported = false; bool isReported = false;
CommandReporter(const CommandReporter&) = delete;
CommandReporter& operator=(const CommandReporter&) = delete;
CommandReporter(CommandReporter&&) = delete;
CommandReporter& operator=(CommandReporter&&) = delete;
}; };
} // namespace OHOS::Developtools::HiPerf } // namespace OHOS::Developtools::HiPerf

0
include/subcommand.h Executable file → Normal file
View File

0
include/subcommand_dump.h Executable file → Normal file
View File

0
include/subcommand_record.h Executable file → Normal file
View File

0
include/subcommand_report.h Executable file → Normal file
View File

0
include/subcommand_stat.h Executable file → Normal file
View File

0
src/command.cpp Executable file → Normal file
View File

View File

@ -17,12 +17,18 @@
#ifdef ENABLE_HISYSEVENT #ifdef ENABLE_HISYSEVENT
#include "hisysevent.h" #include "hisysevent.h"
#include "debug_logger.h" #include "utilities.h"
#include "hiperf_hilog.h"
#endif #endif
namespace OHOS::Developtools::HiPerf { 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() CommandReporter::~CommandReporter()
{ {
@ -33,20 +39,21 @@ void CommandReporter::ReportCommand()
{ {
#ifdef ENABLE_HISYSEVENT #ifdef ENABLE_HISYSEVENT
if (isReported) { if (isReported) {
HLOGW("command has been reported"); HIPERF_HILOGD(MODULE_DEFAULT, "command has been reported");
return; return;
} }
int32_t ret = HiSysEventWrite( int32_t ret = HiSysEventWrite(
OHOS::HiviewDFX::HiSysEvent::Domain::GRAPHIC, "HIPERF_USAGE", OHOS::HiviewDFX::HiSysEvent::Domain::PROFILER, "HIPERF_USAGE",
OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
"MAIN_CMD", mainCommand_, "MAIN_CMD", mainCommand_,
"SUB_CMD", subCommand_, "SUB_CMD", subCommand_,
"CALLER", caller_,
"TARGET_PROCESS", targetProcess_, "TARGET_PROCESS", targetProcess_,
"ERROR_CODE", errorCode_, "ERROR_CODE", errorCode_,
"ERROR_MESSAGE", errorMessage_); "ERROR_MESSAGE", errorMessage_);
if (ret != 0) { if (ret != 0) {
HLOGE("hisysevent report failed, err:%d", ret); HIPERF_HILOGE(MODULE_DEFAULT, "hisysevent report failed, err:%{public}d", ret);
} }
#endif #endif
isReported = true; isReported = true;

0
src/subcommand_dump.cpp Executable file → Normal file
View File

0
src/subcommand_record.cpp Executable file → Normal file
View File

0
src/subcommand_stat.cpp Executable file → Normal file
View File

0
test/BUILD.gn Executable file → Normal file
View File

6
test/unittest/common/native/subcommand_record_test.cpp Executable file → Normal file
View File

@ -1608,7 +1608,7 @@ HWTEST_F(SubCommandRecordTest, ReportSamplePid, TestSize.Level1)
CommandReporter reporter("record"); CommandReporter reporter("record");
command.AddReportArgs(reporter); 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) HWTEST_F(SubCommandRecordTest, ReportSampleApp, TestSize.Level1)
{ {
SubCommandRecord command; SubCommandRecord command;
command.targetSystemWide_ = true; command.appPackage_ = "com.test.app";
CommandReporter reporter("record"); CommandReporter reporter("record");
command.AddReportArgs(reporter); command.AddReportArgs(reporter);
EXPECT_EQ(reporter.targetProcess_, "ALL"); EXPECT_EQ(reporter.targetProcess_, "com.test.app");
} }
} // namespace HiPerf } // namespace HiPerf

4
test/unittest/common/native/subcommand_stat_test.cpp Executable file → Normal file
View File

@ -2286,7 +2286,7 @@ HWTEST_F(SubCommandStatTest, ReportSamplePid, TestSize.Level1)
CommandReporter reporter("stat"); CommandReporter reporter("stat");
command.AddReportArgs(reporter); 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"); CommandReporter reporter("stat");
command.AddReportArgs(reporter); command.AddReportArgs(reporter);
EXPECT_EQ(reporter.targetProcess_, "ALL"); EXPECT_EQ(reporter.targetProcess_, "com.test.app");
} }
} // namespace HiPerf } // namespace HiPerf
} // namespace Developtools } // namespace Developtools