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
9d189f41d7
commit
0c40f391bd
33
BUILD.gn
Normal file → Executable file
33
BUILD.gn
Normal file → Executable file
@ -189,6 +189,28 @@ 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" ]
|
||||
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"
|
||||
@ -384,6 +406,7 @@ ohos_executable("hiperf") {
|
||||
":hiperf_etc",
|
||||
":hiperf_platform_common",
|
||||
":hiperf_platform_linux",
|
||||
":hiperf_enable_hisysevent",
|
||||
]
|
||||
|
||||
if (hiperf_target_static) {
|
||||
@ -407,7 +430,10 @@ ohos_executable("hiperf") {
|
||||
|
||||
ohos_executable("hiperf_host") {
|
||||
sources = [ "./src/main.cpp" ]
|
||||
deps = [ ":hiperf_platform_common" ]
|
||||
deps = [
|
||||
":hiperf_platform_common",
|
||||
":hiperf_disable_hisysevent"
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"bounds_checking_function:libsec_shared",
|
||||
@ -467,7 +493,10 @@ ohos_source_set("hiperf_platform_host") {
|
||||
}
|
||||
|
||||
ohos_shared_library("hiperf_host_lib") {
|
||||
public_deps = [ ":hiperf_platform_host" ]
|
||||
public_deps = [
|
||||
":hiperf_platform_host",
|
||||
":hiperf_disable_hisysevent"
|
||||
]
|
||||
output_name = "hiperf_report"
|
||||
|
||||
ldflags = [ "-static-libstdc++" ]
|
||||
|
17
bundle.json
Normal file → Executable file
17
bundle.json
Normal file → Executable file
@ -19,16 +19,17 @@
|
||||
"ram": "2000KB",
|
||||
"deps": {
|
||||
"components": [
|
||||
"hilog",
|
||||
"napi",
|
||||
"samgr",
|
||||
"ipc",
|
||||
"c_utils",
|
||||
"bundle_framework",
|
||||
"faultloggerd",
|
||||
"init",
|
||||
"ability_base",
|
||||
"bounds_checking_function",
|
||||
"bundle_framework",
|
||||
"c_utils",
|
||||
"faultloggerd",
|
||||
"hilog",
|
||||
"hisysevent",
|
||||
"init",
|
||||
"ipc",
|
||||
"napi",
|
||||
"samgr",
|
||||
"zlib"
|
||||
],
|
||||
"third_party": [
|
||||
|
41
include/command_reporter.h
Executable file
41
include/command_reporter.h
Executable file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) 2024-2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef COMMAND_REPORTER_H_
|
||||
#define COMMAND_REPORTER_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace OHOS::Developtools::HiPerf {
|
||||
|
||||
class CommandReporter {
|
||||
public:
|
||||
explicit CommandReporter(const std::string& fullArgument);
|
||||
~CommandReporter();
|
||||
|
||||
void ReportCommand();
|
||||
|
||||
std::string mainCommand_ = "";
|
||||
std::string subCommand_ = "";
|
||||
std::string targetProcess_ = "";
|
||||
int32_t errorCode_ = 0;
|
||||
std::string errorMessage_ = "";
|
||||
|
||||
private:
|
||||
bool isReported = false;
|
||||
};
|
||||
|
||||
} // namespace OHOS::Developtools::HiPerf
|
||||
|
||||
#endif // COMMAND_REPORTER_H_
|
5
include/subcommand.h
Normal file → Executable file
5
include/subcommand.h
Normal file → Executable file
@ -15,6 +15,8 @@
|
||||
#ifndef HIPERF_SUBCOMMAND_H_
|
||||
#define HIPERF_SUBCOMMAND_H_
|
||||
#include <string>
|
||||
|
||||
#include "command_reporter.h"
|
||||
#include "utilities.h"
|
||||
#include "virtual_runtime.h"
|
||||
|
||||
@ -65,6 +67,9 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
// add args for hisysevent
|
||||
virtual void AddReportArgs(CommandReporter& reporter) {};
|
||||
|
||||
// return false means cmd failed
|
||||
virtual bool OnSubCommand(std::vector<std::string> &args) = 0;
|
||||
// some test code will use this for simple
|
||||
|
0
include/subcommand_dump.h
Normal file → Executable file
0
include/subcommand_dump.h
Normal file → Executable file
7
include/subcommand_record.h
Normal file → Executable file
7
include/subcommand_record.h
Normal file → Executable file
@ -197,6 +197,9 @@ public:
|
||||
bool ParseOption(std::vector<std::string> &args) override;
|
||||
void DumpOptions(void) const override;
|
||||
|
||||
// add args for hisysevent
|
||||
void AddReportArgs(CommandReporter& reporter) override;
|
||||
|
||||
static bool RegisterSubCommandRecord(void);
|
||||
std::map<const std::string, unsigned long long> speOptMap_ = {
|
||||
{"branch_filter", 0}, {"load_filter", 0},
|
||||
@ -363,6 +366,10 @@ private:
|
||||
void SetSavedCmdlinesSize();
|
||||
void RecoverSavedCmdlinesSize();
|
||||
bool OnlineReportData();
|
||||
|
||||
FRIEND_TEST(SubCommandRecordTest, ReportSampleAll);
|
||||
FRIEND_TEST(SubCommandRecordTest, ReportSamplePid);
|
||||
FRIEND_TEST(SubCommandRecordTest, ReportSampleApp);
|
||||
};
|
||||
} // namespace HiPerf
|
||||
} // namespace Developtools
|
||||
|
0
include/subcommand_report.h
Normal file → Executable file
0
include/subcommand_report.h
Normal file → Executable file
7
include/subcommand_stat.h
Normal file → Executable file
7
include/subcommand_stat.h
Normal file → Executable file
@ -93,6 +93,9 @@ public:
|
||||
bool ParseSpecialOption(std::vector<std::string> &args);
|
||||
void DumpOptions(void) const override;
|
||||
|
||||
// add args for hisysevent
|
||||
void AddReportArgs(CommandReporter& reporter) override;
|
||||
|
||||
private:
|
||||
PerfEvents perfEvents_;
|
||||
bool targetSystemWide_ {false};
|
||||
@ -154,6 +157,10 @@ private:
|
||||
bool CheckSelectCpuPidOption();
|
||||
void SetReportFlags(bool cpuFlag, bool threadFlag);
|
||||
void SetPerfEvent();
|
||||
|
||||
FRIEND_TEST(SubCommandStatTest, ReportSampleAll);
|
||||
FRIEND_TEST(SubCommandStatTest, ReportSamplePid);
|
||||
FRIEND_TEST(SubCommandStatTest, ReportSampleApp);
|
||||
};
|
||||
|
||||
bool RegisterSubCommandStat(void);
|
||||
|
4
src/command.cpp
Normal file → Executable file
4
src/command.cpp
Normal file → Executable file
@ -28,6 +28,7 @@ bool Command::DispatchCommands(std::vector<std::string> arguments)
|
||||
fullArgument.append(" ");
|
||||
fullArgument.append(arg);
|
||||
}
|
||||
CommandReporter reporter(fullArgument);
|
||||
HLOGD("args:%s", VectorToString(arguments).c_str());
|
||||
while (!arguments.empty()) {
|
||||
// we need found main command args first
|
||||
@ -48,6 +49,7 @@ bool Command::DispatchCommands(std::vector<std::string> arguments)
|
||||
// if it is an sub command
|
||||
auto subCommand = SubCommand::FindSubCommand(arguments.front());
|
||||
if (subCommand != nullptr) {
|
||||
reporter.mainCommand_ = arguments.front();
|
||||
// this is an sub command which we support
|
||||
|
||||
// remove the subcmd name
|
||||
@ -56,6 +58,8 @@ bool Command::DispatchCommands(std::vector<std::string> arguments)
|
||||
// if we found the sub command , after it processed , we will exit
|
||||
HLOGD("OnSubCommandOptions -> %s", subCommand->Name().c_str());
|
||||
if (subCommand->OnSubCommandOptions(arguments)) {
|
||||
subCommand->AddReportArgs(reporter);
|
||||
reporter.ReportCommand();
|
||||
// if some help cmd ?
|
||||
if (subCommand->OnPreSubCommand()) {
|
||||
return true;
|
||||
|
55
src/command_reporter.cpp
Executable file
55
src/command_reporter.cpp
Executable file
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (c) 2024-2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "command_reporter.h"
|
||||
|
||||
#ifdef ENABLE_HISYSEVENT
|
||||
#include "hisysevent.h"
|
||||
#include "debug_logger.h"
|
||||
#endif
|
||||
|
||||
namespace OHOS::Developtools::HiPerf {
|
||||
|
||||
CommandReporter::CommandReporter(const std::string& fullArgument) : subCommand_(fullArgument) {}
|
||||
|
||||
CommandReporter::~CommandReporter()
|
||||
{
|
||||
ReportCommand();
|
||||
}
|
||||
|
||||
void CommandReporter::ReportCommand()
|
||||
{
|
||||
#ifdef ENABLE_HISYSEVENT
|
||||
if (isReported) {
|
||||
HLOGW("command has been reported");
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t ret = HiSysEventWrite(
|
||||
OHOS::HiviewDFX::HiSysEvent::Domain::GRAPHIC, "HIPERF_USAGE",
|
||||
OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
|
||||
"MAIN_CMD", mainCommand_,
|
||||
"SUB_CMD", subCommand_,
|
||||
"TARGET_PROCESS", targetProcess_,
|
||||
"ERROR_CODE", errorCode_,
|
||||
"ERROR_MESSAGE", errorMessage_);
|
||||
if (ret != 0) {
|
||||
HLOGE("hisysevent report failed, err:%d", ret);
|
||||
}
|
||||
#endif
|
||||
isReported = true;
|
||||
}
|
||||
|
||||
} // namespace OHOS::Developtools::HiPerf
|
0
src/subcommand_dump.cpp
Normal file → Executable file
0
src/subcommand_dump.cpp
Normal file → Executable file
12
src/subcommand_record.cpp
Normal file → Executable file
12
src/subcommand_record.cpp
Normal file → Executable file
@ -1930,6 +1930,18 @@ std::string SubCommandRecord::HandleAppInfo()
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
void SubCommandRecord::AddReportArgs(CommandReporter& reporter)
|
||||
{
|
||||
if (targetSystemWide_) {
|
||||
reporter.targetProcess_ = "ALL";
|
||||
} else if (!appPackage_.empty()) {
|
||||
reporter.targetProcess_ = appPackage_;
|
||||
} else {
|
||||
reporter.targetProcess_ = VectorToString<pid_t>(selectPids_);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace HiPerf
|
||||
} // namespace Developtools
|
||||
} // namespace OHOS
|
||||
|
12
src/subcommand_stat.cpp
Normal file → Executable file
12
src/subcommand_stat.cpp
Normal file → Executable file
@ -805,6 +805,18 @@ bool SubCommandStat::CheckOptions(const std::vector<pid_t> &pids)
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void SubCommandStat::AddReportArgs(CommandReporter& reporter)
|
||||
{
|
||||
if (targetSystemWide_) {
|
||||
reporter.targetProcess_ = "ALL";
|
||||
} else if (!appPackage_.empty()) {
|
||||
reporter.targetProcess_ = appPackage_;
|
||||
} else {
|
||||
reporter.targetProcess_ = VectorToString<pid_t>(selectPids_);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace HiPerf
|
||||
} // namespace Developtools
|
||||
} // namespace OHOS
|
||||
|
2
test/BUILD.gn
Normal file → Executable file
2
test/BUILD.gn
Normal file → Executable file
@ -68,6 +68,7 @@ common_deps = [
|
||||
"${hiperf_path}/:hiperf_platform_host",
|
||||
"${hiperf_path}/:hiperf_platform_linux",
|
||||
"${hiperf_path}/interfaces/innerkits/native:hiperf_client_static",
|
||||
"${hiperf_path}/:hiperf_disable_hisysevent",
|
||||
"//third_party/googletest:gmock_main",
|
||||
"//third_party/googletest:gtest_main",
|
||||
]
|
||||
@ -121,6 +122,7 @@ fuzz_deps = [
|
||||
"${hiperf_path}/:hiperf_platform_host",
|
||||
"${hiperf_path}/:hiperf_platform_linux",
|
||||
"${hiperf_path}/interfaces/innerkits/native:hiperf_client_static",
|
||||
"${hiperf_path}/:hiperf_disable_hisysevent",
|
||||
]
|
||||
|
||||
ohos_fuzztest("CommandLineFuzzTest") {
|
||||
|
46
test/unittest/common/native/subcommand_record_test.cpp
Normal file → Executable file
46
test/unittest/common/native/subcommand_record_test.cpp
Normal file → Executable file
@ -1580,6 +1580,52 @@ HWTEST_F(SubCommandRecordTest, TestCmdlineSizeErr, TestSize.Level1)
|
||||
{
|
||||
TestRecordCommand("-d 2 -a -f 2000 --cmdline-size", false, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AddReportArgs
|
||||
* @tc.desc: Test AddReportArgs with -a
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(SubCommandRecordTest, ReportSampleAll, TestSize.Level1)
|
||||
{
|
||||
SubCommandRecord command;
|
||||
command.targetSystemWide_ = true;
|
||||
|
||||
CommandReporter reporter("record");
|
||||
command.AddReportArgs(reporter);
|
||||
EXPECT_EQ(reporter.targetProcess_, "ALL");
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AddReportArgs
|
||||
* @tc.desc: Test AddReportArgs with -p
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(SubCommandRecordTest, ReportSamplePid, TestSize.Level1)
|
||||
{
|
||||
SubCommandRecord command;
|
||||
command.selectPids_ = {1, 2, 3};
|
||||
|
||||
CommandReporter reporter("record");
|
||||
command.AddReportArgs(reporter);
|
||||
EXPECT_EQ(reporter.targetProcess_, "ALL");
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AddReportArgs
|
||||
* @tc.desc: Test AddReportArgs with --app
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(SubCommandRecordTest, ReportSampleApp, TestSize.Level1)
|
||||
{
|
||||
SubCommandRecord command;
|
||||
command.targetSystemWide_ = true;
|
||||
|
||||
CommandReporter reporter("record");
|
||||
command.AddReportArgs(reporter);
|
||||
EXPECT_EQ(reporter.targetProcess_, "ALL");
|
||||
}
|
||||
|
||||
} // namespace HiPerf
|
||||
} // namespace Developtools
|
||||
} // namespace OHOS
|
||||
|
45
test/unittest/common/native/subcommand_stat_test.cpp
Normal file → Executable file
45
test/unittest/common/native/subcommand_stat_test.cpp
Normal file → Executable file
@ -2258,6 +2258,51 @@ HWTEST_F(SubCommandStatTest, CheckPidAndApp, TestSize.Level1)
|
||||
printf("output:\n%s", stringOut.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AddReportArgs
|
||||
* @tc.desc: Test AddReportArgs with -a
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(SubCommandStatTest, ReportSampleAll, TestSize.Level1)
|
||||
{
|
||||
SubCommandStat command;
|
||||
command.targetSystemWide_ = true;
|
||||
|
||||
CommandReporter reporter("stat");
|
||||
command.AddReportArgs(reporter);
|
||||
EXPECT_EQ(reporter.targetProcess_, "ALL");
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AddReportArgs
|
||||
* @tc.desc: Test AddReportArgs with -p
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(SubCommandStatTest, ReportSamplePid, TestSize.Level1)
|
||||
{
|
||||
SubCommandStat command;
|
||||
command.selectPids_ = {1, 2, 3};
|
||||
|
||||
CommandReporter reporter("stat");
|
||||
command.AddReportArgs(reporter);
|
||||
EXPECT_EQ(reporter.targetProcess_, "ALL");
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AddReportArgs
|
||||
* @tc.desc: Test AddReportArgs with --app
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(SubCommandStatTest, ReportSampleApp, TestSize.Level1)
|
||||
{
|
||||
SubCommandStat command;
|
||||
command.targetSystemWide_ = true;
|
||||
|
||||
CommandReporter reporter("stat");
|
||||
command.AddReportArgs(reporter);
|
||||
EXPECT_EQ(reporter.targetProcess_, "ALL");
|
||||
}
|
||||
} // namespace HiPerf
|
||||
} // namespace Developtools
|
||||
} // namespace OHOS
|
||||
|
Loading…
Reference in New Issue
Block a user