mirror of
https://gitee.com/openharmony/developtools_hiperf
synced 2024-11-23 07:29:42 +00:00
修改代码
Signed-off-by: yuanye <yuanye64@huawei.com>
This commit is contained in:
parent
0c40f391bd
commit
a52ee8d190
6
BUILD.gn
Executable file → Normal file
6
BUILD.gn
Executable file → Normal file
@ -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" ]
|
||||
}
|
||||
|
||||
|
0
bundle.json
Executable file → Normal file
0
bundle.json
Executable file → Normal file
6
include/command_reporter.h
Executable file → Normal file
6
include/command_reporter.h
Executable file → Normal file
@ -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
|
||||
|
0
include/subcommand.h
Executable file → Normal file
0
include/subcommand.h
Executable file → Normal file
0
include/subcommand_dump.h
Executable file → Normal file
0
include/subcommand_dump.h
Executable file → Normal file
0
include/subcommand_record.h
Executable file → Normal file
0
include/subcommand_record.h
Executable file → Normal file
0
include/subcommand_report.h
Executable file → Normal file
0
include/subcommand_report.h
Executable file → Normal file
0
include/subcommand_stat.h
Executable file → Normal file
0
include/subcommand_stat.h
Executable file → Normal file
0
src/command.cpp
Executable file → Normal file
0
src/command.cpp
Executable file → Normal file
@ -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;
|
||||
|
0
src/subcommand_dump.cpp
Executable file → Normal file
0
src/subcommand_dump.cpp
Executable file → Normal file
0
src/subcommand_record.cpp
Executable file → Normal file
0
src/subcommand_record.cpp
Executable file → Normal file
0
src/subcommand_stat.cpp
Executable file → Normal file
0
src/subcommand_stat.cpp
Executable file → Normal file
0
test/BUILD.gn
Executable file → Normal file
0
test/BUILD.gn
Executable file → Normal file
6
test/unittest/common/native/subcommand_record_test.cpp
Executable file → Normal file
6
test/unittest/common/native/subcommand_record_test.cpp
Executable file → Normal file
@ -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
|
||||
|
4
test/unittest/common/native/subcommand_stat_test.cpp
Executable file → Normal file
4
test/unittest/common/native/subcommand_stat_test.cpp
Executable file → Normal file
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user