mirror of
https://gitee.com/openharmony/developtools_hiperf
synced 2024-11-23 07:29:42 +00:00
代码同步
Signed-off-by:wenlong12 <wenlong12@huawei.com> Signed-off-by: wenlong12 <wenlong12@huawei.com>
This commit is contained in:
parent
27564f7e32
commit
b968b00a0c
@ -20,6 +20,12 @@
|
||||
|
||||
using namespace OHOS::Developtools::HiPerf;
|
||||
|
||||
#if defined(__aarch64__)
|
||||
const std::string TEST_PROCESSES = "com.ohos.sceneboard";
|
||||
#else
|
||||
const std::string TEST_PROCESSES = "com.ohos.launcher";
|
||||
#endif
|
||||
|
||||
namespace HiperfClientDemo {
|
||||
void TestCodeThread(int id)
|
||||
{
|
||||
@ -64,7 +70,7 @@ int main()
|
||||
printf("demo start\n");
|
||||
HiperfClient::RecordOption opt;
|
||||
const int timeout = 30;
|
||||
opt.SetAppPackage("com.ohos.launcher");
|
||||
opt.SetAppPackage(TEST_PROCESSES);
|
||||
opt.SetTimeStopSec(timeout);
|
||||
if (myHiperf.Start(opt)) {
|
||||
printf("demo start successfully\n");
|
||||
|
@ -14,6 +14,7 @@
|
||||
*/
|
||||
|
||||
#include "cpu_usage_test.h"
|
||||
#include "utilities_test.h"
|
||||
using namespace std;
|
||||
using namespace testing::ext;
|
||||
using namespace std::chrono;
|
||||
@ -40,6 +41,8 @@ public:
|
||||
float GetCpuUsageRatio(int pid);
|
||||
|
||||
float GetAverageCpuUsage(pid_t pid, uint64_t timeOut);
|
||||
|
||||
void TestCpuUsage(const std::string &option, unsigned int expect, bool fixPid);
|
||||
};
|
||||
|
||||
void CpuUsageTest::SetUpTestCase() {}
|
||||
@ -208,6 +211,24 @@ float CpuUsageTest::GetAverageCpuUsage(pid_t pid, uint64_t timeOut)
|
||||
return cpuUsage;
|
||||
}
|
||||
|
||||
void CpuUsageTest::TestCpuUsage(const std::string &option, unsigned int expect, bool fixPid)
|
||||
{
|
||||
std::string cmd = "hiperf record ";
|
||||
if (fixPid) {
|
||||
cmd += "--app ";
|
||||
cmd += " " + TEST_PROCESSES;
|
||||
}
|
||||
cmd += " " + option;
|
||||
|
||||
std::thread perf(system, cmd.c_str());
|
||||
perf.detach();
|
||||
pid_t pid = GetPidByProcessName("hiperf");
|
||||
uint64_t timeOut = 10000;
|
||||
float cpuUsage = GetAverageCpuUsage(pid, timeOut);
|
||||
|
||||
EXPECT_LE(cpuUsage, expect);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: recordCpuUsageF100_FP_SYSTEM
|
||||
* @tc.desc: test hiperf record system wide cpu usage within required limit
|
||||
@ -215,13 +236,7 @@ float CpuUsageTest::GetAverageCpuUsage(pid_t pid, uint64_t timeOut)
|
||||
*/
|
||||
HWTEST_F(CpuUsageTest, recordCpuUsageF100_FP_SYSTEM, TestSize.Level1)
|
||||
{
|
||||
std::string cmd = "hiperf record -a -f 100 -s fp -d 10";
|
||||
std::thread perf(system, cmd.c_str());
|
||||
perf.detach();
|
||||
pid_t pid = GetPidByProcessName("hiperf");
|
||||
uint64_t timeOut = 10000;
|
||||
float cpuUsage = GetAverageCpuUsage(pid, timeOut);
|
||||
EXPECT_LE(cpuUsage, F100_FP_CPU_LIMIT_SYSTEM);
|
||||
TestCpuUsage("-a -f 100 -s fp -d 10", F100_FP_CPU_LIMIT_SYSTEM, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -231,13 +246,7 @@ HWTEST_F(CpuUsageTest, recordCpuUsageF100_FP_SYSTEM, TestSize.Level1)
|
||||
*/
|
||||
HWTEST_F(CpuUsageTest, recordCpuUsageF500_FP_SYSTEM, TestSize.Level1)
|
||||
{
|
||||
std::string cmd = "hiperf record -a -f 500 -s fp -d 10";
|
||||
std::thread perf(system, cmd.c_str());
|
||||
perf.detach();
|
||||
pid_t pid = GetPidByProcessName("hiperf");
|
||||
uint64_t timeOut = 10000;
|
||||
float cpuUsage = GetAverageCpuUsage(pid, timeOut);
|
||||
EXPECT_LE(cpuUsage, F500_FP_CPU_LIMIT_SYSTEM);
|
||||
TestCpuUsage("-a -f 500 -s fp -d 10", F500_FP_CPU_LIMIT_SYSTEM, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -247,13 +256,7 @@ HWTEST_F(CpuUsageTest, recordCpuUsageF500_FP_SYSTEM, TestSize.Level1)
|
||||
*/
|
||||
HWTEST_F(CpuUsageTest, recordCpuUsageF1000_FP_SYSTEM, TestSize.Level1)
|
||||
{
|
||||
std::string cmd = "hiperf record -a -f 1000 -s fp -d 10";
|
||||
std::thread perf(system, cmd.c_str());
|
||||
perf.detach();
|
||||
pid_t pid = GetPidByProcessName("hiperf");
|
||||
uint64_t timeOut = 10000;
|
||||
float cpuUsage = GetAverageCpuUsage(pid, timeOut);
|
||||
EXPECT_LE(cpuUsage, F1000_FP_CPU_LIMIT_SYSTEM);
|
||||
TestCpuUsage("-a -f 1000 -s fp -d 10", F1000_FP_CPU_LIMIT_SYSTEM, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -263,13 +266,7 @@ HWTEST_F(CpuUsageTest, recordCpuUsageF1000_FP_SYSTEM, TestSize.Level1)
|
||||
*/
|
||||
HWTEST_F(CpuUsageTest, recordCpuUsageF2000_FP_SYSTEM, TestSize.Level1)
|
||||
{
|
||||
std::string cmd = "hiperf record -a -f 2000 -s fp -d 10";
|
||||
std::thread perf(system, cmd.c_str());
|
||||
perf.detach();
|
||||
pid_t pid = GetPidByProcessName("hiperf");
|
||||
uint64_t timeOut = 10000;
|
||||
float cpuUsage = GetAverageCpuUsage(pid, timeOut);
|
||||
EXPECT_LE(cpuUsage, F2000_FP_CPU_LIMIT_SYSTEM);
|
||||
TestCpuUsage("-a -f 2000 -s fp -d 10", F2000_FP_CPU_LIMIT_SYSTEM, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -279,13 +276,7 @@ HWTEST_F(CpuUsageTest, recordCpuUsageF2000_FP_SYSTEM, TestSize.Level1)
|
||||
*/
|
||||
HWTEST_F(CpuUsageTest, recordCpuUsageF4000_FP_SYSTEM, TestSize.Level1)
|
||||
{
|
||||
std::string cmd = "hiperf record -a -f 4000 -s fp -d 10";
|
||||
std::thread perf(system, cmd.c_str());
|
||||
perf.detach();
|
||||
pid_t pid = GetPidByProcessName("hiperf");
|
||||
uint64_t timeOut = 10000;
|
||||
float cpuUsage = GetAverageCpuUsage(pid, timeOut);
|
||||
EXPECT_LE(cpuUsage, F4000_FP_CPU_LIMIT_SYSTEM);
|
||||
TestCpuUsage("-a -f 4000 -s fp -d 10", F4000_FP_CPU_LIMIT_SYSTEM, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -295,13 +286,7 @@ HWTEST_F(CpuUsageTest, recordCpuUsageF4000_FP_SYSTEM, TestSize.Level1)
|
||||
*/
|
||||
HWTEST_F(CpuUsageTest, recordCpuUsageF8000_FP_SYSTEM, TestSize.Level1)
|
||||
{
|
||||
std::string cmd = "hiperf record -a -f 8000 -s fp -d 10";
|
||||
std::thread perf(system, cmd.c_str());
|
||||
perf.detach();
|
||||
pid_t pid = GetPidByProcessName("hiperf");
|
||||
uint64_t timeOut = 10000;
|
||||
float cpuUsage = GetAverageCpuUsage(pid, timeOut);
|
||||
EXPECT_LE(cpuUsage, F8000_FP_CPU_LIMIT_SYSTEM);
|
||||
TestCpuUsage("-a -f 8000 -s fp -d 10", F8000_FP_CPU_LIMIT_SYSTEM, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -311,13 +296,7 @@ HWTEST_F(CpuUsageTest, recordCpuUsageF8000_FP_SYSTEM, TestSize.Level1)
|
||||
*/
|
||||
HWTEST_F(CpuUsageTest, recordCpuUsageF100_DWARF_SYSTEM, TestSize.Level1)
|
||||
{
|
||||
std::string cmd = "hiperf record -a -f 100 -s dwarf -d 10";
|
||||
std::thread perf(system, cmd.c_str());
|
||||
perf.detach();
|
||||
pid_t pid = GetPidByProcessName("hiperf");
|
||||
uint64_t timeOut = 10000;
|
||||
float cpuUsage = GetAverageCpuUsage(pid, timeOut);
|
||||
EXPECT_LE(cpuUsage, F100_DWARF_CPU_LIMIT_SYSTEM);
|
||||
TestCpuUsage("-a -f 100 -s dwarf -d 10", F100_DWARF_CPU_LIMIT_SYSTEM, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -327,13 +306,7 @@ HWTEST_F(CpuUsageTest, recordCpuUsageF100_DWARF_SYSTEM, TestSize.Level1)
|
||||
*/
|
||||
HWTEST_F(CpuUsageTest, recordCpuUsageF500_DWARF_SYSTEM, TestSize.Level1)
|
||||
{
|
||||
std::string cmd = "hiperf record -a -f 500 -s dwarf -d 10";
|
||||
std::thread perf(system, cmd.c_str());
|
||||
perf.detach();
|
||||
pid_t pid = GetPidByProcessName("hiperf");
|
||||
uint64_t timeOut = 10000;
|
||||
float cpuUsage = GetAverageCpuUsage(pid, timeOut);
|
||||
EXPECT_LE(cpuUsage, F500_DWARF_CPU_LIMIT_SYSTEM);
|
||||
TestCpuUsage("-a -f 500 -s dwarf -d 10", F500_DWARF_CPU_LIMIT_SYSTEM, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -343,13 +316,7 @@ HWTEST_F(CpuUsageTest, recordCpuUsageF500_DWARF_SYSTEM, TestSize.Level1)
|
||||
*/
|
||||
HWTEST_F(CpuUsageTest, recordCpuUsageF1000_DWARF_SYSTEM, TestSize.Level1)
|
||||
{
|
||||
std::string cmd = "hiperf record -a -f 1000 -s dwarf -d 10";
|
||||
std::thread perf(system, cmd.c_str());
|
||||
perf.detach();
|
||||
pid_t pid = GetPidByProcessName("hiperf");
|
||||
uint64_t timeOut = 10000;
|
||||
float cpuUsage = GetAverageCpuUsage(pid, timeOut);
|
||||
EXPECT_LE(cpuUsage, F1000_DWARF_CPU_LIMIT_SYSTEM);
|
||||
TestCpuUsage("-a -f 1000 -s dwarf -d 10", F1000_DWARF_CPU_LIMIT_SYSTEM, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -359,13 +326,7 @@ HWTEST_F(CpuUsageTest, recordCpuUsageF1000_DWARF_SYSTEM, TestSize.Level1)
|
||||
*/
|
||||
HWTEST_F(CpuUsageTest, recordCpuUsageF2000_DWARF_SYSTEM, TestSize.Level1)
|
||||
{
|
||||
std::string cmd = "hiperf record -a -f 2000 -s dwarf -d 10";
|
||||
std::thread perf(system, cmd.c_str());
|
||||
perf.detach();
|
||||
pid_t pid = GetPidByProcessName("hiperf");
|
||||
uint64_t timeOut = 10000;
|
||||
float cpuUsage = GetAverageCpuUsage(pid, timeOut);
|
||||
EXPECT_LE(cpuUsage, F2000_DWARF_CPU_LIMIT_SYSTEM);
|
||||
TestCpuUsage("-a -f 2000 -s dwarf -d 10", F2000_DWARF_CPU_LIMIT_SYSTEM, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -375,13 +336,7 @@ HWTEST_F(CpuUsageTest, recordCpuUsageF2000_DWARF_SYSTEM, TestSize.Level1)
|
||||
*/
|
||||
HWTEST_F(CpuUsageTest, recordCpuUsageF4000_DWARF_SYSTEM, TestSize.Level1)
|
||||
{
|
||||
std::string cmd = "hiperf record -a -f 4000 -s dwarf -d 10";
|
||||
std::thread perf(system, cmd.c_str());
|
||||
perf.detach();
|
||||
pid_t pid = GetPidByProcessName("hiperf");
|
||||
uint64_t timeOut = 10000;
|
||||
float cpuUsage = GetAverageCpuUsage(pid, timeOut);
|
||||
EXPECT_LE(cpuUsage, F4000_DWARF_CPU_LIMIT_SYSTEM);
|
||||
TestCpuUsage("-a -f 4000 -s dwarf -d 10", F4000_DWARF_CPU_LIMIT_SYSTEM, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -391,13 +346,7 @@ HWTEST_F(CpuUsageTest, recordCpuUsageF4000_DWARF_SYSTEM, TestSize.Level1)
|
||||
*/
|
||||
HWTEST_F(CpuUsageTest, recordCpuUsageF8000_DWARF_SYSTEM, TestSize.Level1)
|
||||
{
|
||||
std::string cmd = "hiperf record -a -f 8000 -s dwarf -d 10";
|
||||
std::thread perf(system, cmd.c_str());
|
||||
perf.detach();
|
||||
pid_t pid = GetPidByProcessName("hiperf");
|
||||
uint64_t timeOut = 10000;
|
||||
float cpuUsage = GetAverageCpuUsage(pid, timeOut);
|
||||
EXPECT_LE(cpuUsage, F8000_DWARF_CPU_LIMIT_SYSTEM);
|
||||
TestCpuUsage("-a -f 8000 -s dwarf -d 10", F8000_DWARF_CPU_LIMIT_SYSTEM, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -407,13 +356,7 @@ HWTEST_F(CpuUsageTest, recordCpuUsageF8000_DWARF_SYSTEM, TestSize.Level1)
|
||||
*/
|
||||
HWTEST_F(CpuUsageTest, recordCpuUsageF100_FP_PROCESS, TestSize.Level1)
|
||||
{
|
||||
std::string cmd = "hiperf record --app com.ohos.systemui -f 100 -s fp -d 10";
|
||||
std::thread perf(system, cmd.c_str());
|
||||
perf.detach();
|
||||
pid_t pid = GetPidByProcessName("hiperf");
|
||||
uint64_t timeOut = 10000;
|
||||
float cpuUsage = GetAverageCpuUsage(pid, timeOut);
|
||||
EXPECT_LE(cpuUsage, F100_FP_CPU_LIMIT_PROCESS);
|
||||
TestCpuUsage("-f 100 -s fp -d 10", F100_FP_CPU_LIMIT_PROCESS, true);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -423,13 +366,7 @@ HWTEST_F(CpuUsageTest, recordCpuUsageF100_FP_PROCESS, TestSize.Level1)
|
||||
*/
|
||||
HWTEST_F(CpuUsageTest, recordCpuUsageF500_FP_PROCESS, TestSize.Level1)
|
||||
{
|
||||
std::string cmd = "hiperf record --app com.ohos.systemui -f 500 -s fp -d 10";
|
||||
std::thread perf(system, cmd.c_str());
|
||||
perf.detach();
|
||||
pid_t pid = GetPidByProcessName("hiperf");
|
||||
uint64_t timeOut = 10000;
|
||||
float cpuUsage = GetAverageCpuUsage(pid, timeOut);
|
||||
EXPECT_LE(cpuUsage, F500_FP_CPU_LIMIT_PROCESS);
|
||||
TestCpuUsage("-f 500 -s fp -d 10", F500_FP_CPU_LIMIT_PROCESS, true);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -439,13 +376,7 @@ HWTEST_F(CpuUsageTest, recordCpuUsageF500_FP_PROCESS, TestSize.Level1)
|
||||
*/
|
||||
HWTEST_F(CpuUsageTest, recordCpuUsageF1000_FP_PROCESS, TestSize.Level1)
|
||||
{
|
||||
std::string cmd = "hiperf record --app com.ohos.systemui -f 1000 -s fp -d 10";
|
||||
std::thread perf(system, cmd.c_str());
|
||||
perf.detach();
|
||||
pid_t pid = GetPidByProcessName("hiperf");
|
||||
uint64_t timeOut = 10000;
|
||||
float cpuUsage = GetAverageCpuUsage(pid, timeOut);
|
||||
EXPECT_LE(cpuUsage, F1000_FP_CPU_LIMIT_PROCESS);
|
||||
TestCpuUsage("-f 1000 -s fp -d 10", F1000_FP_CPU_LIMIT_PROCESS, true);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -455,13 +386,7 @@ HWTEST_F(CpuUsageTest, recordCpuUsageF1000_FP_PROCESS, TestSize.Level1)
|
||||
*/
|
||||
HWTEST_F(CpuUsageTest, recordCpuUsageF2000_FP_PROCESS, TestSize.Level1)
|
||||
{
|
||||
std::string cmd = "hiperf record --app com.ohos.systemui -f 2000 -s fp -d 10";
|
||||
std::thread perf(system, cmd.c_str());
|
||||
perf.detach();
|
||||
pid_t pid = GetPidByProcessName("hiperf");
|
||||
uint64_t timeOut = 10000;
|
||||
float cpuUsage = GetAverageCpuUsage(pid, timeOut);
|
||||
EXPECT_LE(cpuUsage, F2000_FP_CPU_LIMIT_PROCESS);
|
||||
TestCpuUsage("-f 2000 -s fp -d 10", F2000_FP_CPU_LIMIT_PROCESS, true);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -471,13 +396,7 @@ HWTEST_F(CpuUsageTest, recordCpuUsageF2000_FP_PROCESS, TestSize.Level1)
|
||||
*/
|
||||
HWTEST_F(CpuUsageTest, recordCpuUsageF4000_FP_PROCESS, TestSize.Level1)
|
||||
{
|
||||
std::string cmd = "hiperf record --app com.ohos.systemui -f 4000 -s fp -d 10";
|
||||
std::thread perf(system, cmd.c_str());
|
||||
perf.detach();
|
||||
pid_t pid = GetPidByProcessName("hiperf");
|
||||
uint64_t timeOut = 10000;
|
||||
float cpuUsage = GetAverageCpuUsage(pid, timeOut);
|
||||
EXPECT_LE(cpuUsage, F4000_FP_CPU_LIMIT_PROCESS);
|
||||
TestCpuUsage("-f 4000 -s fp -d 10", F4000_FP_CPU_LIMIT_PROCESS, true);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -487,13 +406,7 @@ HWTEST_F(CpuUsageTest, recordCpuUsageF4000_FP_PROCESS, TestSize.Level1)
|
||||
*/
|
||||
HWTEST_F(CpuUsageTest, recordCpuUsageF8000_FP_PROCESS, TestSize.Level1)
|
||||
{
|
||||
std::string cmd = "hiperf record --app com.ohos.systemui -f 8000 -s fp -d 10";
|
||||
std::thread perf(system, cmd.c_str());
|
||||
perf.detach();
|
||||
pid_t pid = GetPidByProcessName("hiperf");
|
||||
uint64_t timeOut = 10000;
|
||||
float cpuUsage = GetAverageCpuUsage(pid, timeOut);
|
||||
EXPECT_LE(cpuUsage, F8000_FP_CPU_LIMIT_PROCESS);
|
||||
TestCpuUsage("-f 8000 -s fp -d 10", F8000_FP_CPU_LIMIT_PROCESS, true);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -503,13 +416,7 @@ HWTEST_F(CpuUsageTest, recordCpuUsageF8000_FP_PROCESS, TestSize.Level1)
|
||||
*/
|
||||
HWTEST_F(CpuUsageTest, recordCpuUsageF100_DWARF_PROCESS, TestSize.Level1)
|
||||
{
|
||||
std::string cmd = "hiperf record --app com.ohos.systemui -f 100 -s dwarf -d 10";
|
||||
std::thread perf(system, cmd.c_str());
|
||||
perf.detach();
|
||||
pid_t pid = GetPidByProcessName("hiperf");
|
||||
uint64_t timeOut = 10000;
|
||||
float cpuUsage = GetAverageCpuUsage(pid, timeOut);
|
||||
EXPECT_LE(cpuUsage, F100_DWARF_CPU_LIMIT_PROCESS);
|
||||
TestCpuUsage("-f 100 -s dwarf -d 10", F100_DWARF_CPU_LIMIT_PROCESS, true);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -519,13 +426,7 @@ HWTEST_F(CpuUsageTest, recordCpuUsageF100_DWARF_PROCESS, TestSize.Level1)
|
||||
*/
|
||||
HWTEST_F(CpuUsageTest, recordCpuUsageF500_DWARF_PROCESS, TestSize.Level1)
|
||||
{
|
||||
std::string cmd = "hiperf record --app com.ohos.systemui -f 500 -s dwarf -d 10";
|
||||
std::thread perf(system, cmd.c_str());
|
||||
perf.detach();
|
||||
pid_t pid = GetPidByProcessName("hiperf");
|
||||
uint64_t timeOut = 10000;
|
||||
float cpuUsage = GetAverageCpuUsage(pid, timeOut);
|
||||
EXPECT_LE(cpuUsage, F500_DWARF_CPU_LIMIT_PROCESS);
|
||||
TestCpuUsage("-f 500 -s dwarf -d 10", F500_DWARF_CPU_LIMIT_PROCESS, true);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -535,13 +436,7 @@ HWTEST_F(CpuUsageTest, recordCpuUsageF500_DWARF_PROCESS, TestSize.Level1)
|
||||
*/
|
||||
HWTEST_F(CpuUsageTest, recordCpuUsageF1000_DWARF_PROCESS, TestSize.Level1)
|
||||
{
|
||||
std::string cmd = "hiperf record --app com.ohos.systemui -f 1000 -s dwarf -d 10";
|
||||
std::thread perf(system, cmd.c_str());
|
||||
perf.detach();
|
||||
pid_t pid = GetPidByProcessName("hiperf");
|
||||
uint64_t timeOut = 10000;
|
||||
float cpuUsage = GetAverageCpuUsage(pid, timeOut);
|
||||
EXPECT_LE(cpuUsage, F1000_DWARF_CPU_LIMIT_PROCESS);
|
||||
TestCpuUsage("-f 1000 -s dwarf -d 10", F1000_DWARF_CPU_LIMIT_PROCESS, true);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -551,13 +446,7 @@ HWTEST_F(CpuUsageTest, recordCpuUsageF1000_DWARF_PROCESS, TestSize.Level1)
|
||||
*/
|
||||
HWTEST_F(CpuUsageTest, recordCpuUsageF2000_DWARF_PROCESS, TestSize.Level1)
|
||||
{
|
||||
std::string cmd = "hiperf record --app com.ohos.systemui -f 2000 -s dwarf -d 10";
|
||||
std::thread perf(system, cmd.c_str());
|
||||
perf.detach();
|
||||
pid_t pid = GetPidByProcessName("hiperf");
|
||||
uint64_t timeOut = 10000;
|
||||
float cpuUsage = GetAverageCpuUsage(pid, timeOut);
|
||||
EXPECT_LE(cpuUsage, F2000_DWARF_CPU_LIMIT_PROCESS);
|
||||
TestCpuUsage("-f 2000 -s dwarf -d 10", F2000_DWARF_CPU_LIMIT_PROCESS, true);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -567,13 +456,7 @@ HWTEST_F(CpuUsageTest, recordCpuUsageF2000_DWARF_PROCESS, TestSize.Level1)
|
||||
*/
|
||||
HWTEST_F(CpuUsageTest, recordCpuUsageF4000_DWARF_PROCESS, TestSize.Level1)
|
||||
{
|
||||
std::string cmd = "hiperf record --app com.ohos.systemui -f 4000 -s dwarf -d 10";
|
||||
std::thread perf(system, cmd.c_str());
|
||||
perf.detach();
|
||||
pid_t pid = GetPidByProcessName("hiperf");
|
||||
uint64_t timeOut = 10000;
|
||||
float cpuUsage = GetAverageCpuUsage(pid, timeOut);
|
||||
EXPECT_LE(cpuUsage, F4000_DWARF_CPU_LIMIT_PROCESS);
|
||||
TestCpuUsage("-f 4000 -s dwarf -d 10", F4000_DWARF_CPU_LIMIT_PROCESS, true);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -583,13 +466,7 @@ HWTEST_F(CpuUsageTest, recordCpuUsageF4000_DWARF_PROCESS, TestSize.Level1)
|
||||
*/
|
||||
HWTEST_F(CpuUsageTest, recordCpuUsageF8000_DWARF_PROCESS, TestSize.Level1)
|
||||
{
|
||||
std::string cmd = "hiperf record --app com.ohos.systemui -f 8000 -s dwarf -d 10";
|
||||
std::thread perf(system, cmd.c_str());
|
||||
perf.detach();
|
||||
pid_t pid = GetPidByProcessName("hiperf");
|
||||
uint64_t timeOut = 10000;
|
||||
float cpuUsage = GetAverageCpuUsage(pid, timeOut);
|
||||
EXPECT_LE(cpuUsage, F8000_DWARF_CPU_LIMIT_PROCESS);
|
||||
TestCpuUsage("-f 8000 -s dwarf -d 10", F8000_DWARF_CPU_LIMIT_PROCESS, true);
|
||||
}
|
||||
} // namespace HiPerf
|
||||
} // namespace Developtools
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include <thread>
|
||||
|
||||
#include "utilities.h"
|
||||
#include "utilities_test.h"
|
||||
|
||||
using namespace testing::ext;
|
||||
using namespace std;
|
||||
@ -425,7 +426,7 @@ HWTEST_F(HiperfClientTest, SetDataLimit, TestSize.Level1)
|
||||
HWTEST_F(HiperfClientTest, SetAppPackage, TestSize.Level1)
|
||||
{
|
||||
HiperfClient::RecordOption opt;
|
||||
opt.SetAppPackage("com.ohos.launcher");
|
||||
opt.SetAppPackage(TEST_PROCESSES);
|
||||
|
||||
TestCaseOption(opt);
|
||||
}
|
||||
|
@ -20,4 +20,10 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <hilog/log.h>
|
||||
|
||||
#if defined(__aarch64__)
|
||||
const std::string TEST_PROCESSES = "com.ohos.sceneboard";
|
||||
#else
|
||||
const std::string TEST_PROCESSES = "com.ohos.launcher";
|
||||
#endif
|
||||
|
||||
#endif // HIPERF_UTILITIES_TEST_H
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include "command.h"
|
||||
#include "debug_logger.h"
|
||||
#include "utilities.h"
|
||||
#include "utilities_test.h"
|
||||
|
||||
using namespace std::literals::chrono_literals;
|
||||
using namespace testing::ext;
|
||||
@ -125,7 +126,8 @@ void SubCommandRecordTest::TestRecordCommand(const std::string &option, bool exp
|
||||
|
||||
std::string cmdString = "record ";
|
||||
if (fixPid) {
|
||||
cmdString += "--app com.ohos.launcher ";
|
||||
cmdString += "--app ";
|
||||
cmdString += " " + TEST_PROCESSES;
|
||||
}
|
||||
cmdString += " " + option;
|
||||
printf("command : %s\n", cmdString.c_str());
|
||||
@ -157,7 +159,7 @@ size_t SubCommandRecordTest::GetFileSize(const char* fileName)
|
||||
// app package name
|
||||
HWTEST_F(SubCommandRecordTest, PackageName, TestSize.Level1)
|
||||
{
|
||||
ForkAndRunTest("-d 2 --app com.ohos.launcher ", true, false);
|
||||
ForkAndRunTest("-d 2 ", true, true);
|
||||
}
|
||||
|
||||
HWTEST_F(SubCommandRecordTest, PackageNameErr, TestSize.Level1)
|
||||
@ -1048,7 +1050,7 @@ HWTEST_F(SubCommandRecordTest, FileSizeOnFrequency8000_FP_SYSTEM, TestSize.Level
|
||||
*/
|
||||
HWTEST_F(SubCommandRecordTest, FileSizeOnFrequency100_DWARF_PROCESS, TestSize.Level1)
|
||||
{
|
||||
ForkAndRunTest("-d 10 --app com.ohos.systemui -f 100 -s dwarf", true, false);
|
||||
ForkAndRunTest("-d 10 -f 100 -s dwarf", true, true);
|
||||
std::string fileName = TEST_FILE;
|
||||
size_t fileSize = GetFileSize(fileName.c_str());
|
||||
EXPECT_LE(fileSize, TEST_SIZE_F100_DWARF_PROCESS);
|
||||
@ -1061,7 +1063,7 @@ HWTEST_F(SubCommandRecordTest, FileSizeOnFrequency100_DWARF_PROCESS, TestSize.Le
|
||||
*/
|
||||
HWTEST_F(SubCommandRecordTest, FileSizeOnFrequency500_DWARF_PROCESS, TestSize.Level1)
|
||||
{
|
||||
ForkAndRunTest("-d 10 --app com.ohos.systemui -f 500 -s dwarf", true, false);
|
||||
ForkAndRunTest("-d 10 -f 500 -s dwarf", true, true);
|
||||
std::string fileName = TEST_FILE;
|
||||
size_t fileSize = GetFileSize(fileName.c_str());
|
||||
EXPECT_LE(fileSize, TEST_SIZE_F500_DWARF_PROCESS);
|
||||
@ -1074,7 +1076,7 @@ HWTEST_F(SubCommandRecordTest, FileSizeOnFrequency500_DWARF_PROCESS, TestSize.Le
|
||||
*/
|
||||
HWTEST_F(SubCommandRecordTest, FileSizeOnFrequency1000_DWARF_PROCESS, TestSize.Level1)
|
||||
{
|
||||
ForkAndRunTest("-d 10 --app com.ohos.systemui -f 1000 -s dwarf", true, false);
|
||||
ForkAndRunTest("-d 10 --app -f 1000 -s dwarf", true, true);
|
||||
std::string fileName = TEST_FILE;
|
||||
size_t fileSize = GetFileSize(fileName.c_str());
|
||||
EXPECT_LE(fileSize, TEST_SIZE_F1000_DWARF_PROCESS);
|
||||
@ -1087,7 +1089,7 @@ HWTEST_F(SubCommandRecordTest, FileSizeOnFrequency1000_DWARF_PROCESS, TestSize.L
|
||||
*/
|
||||
HWTEST_F(SubCommandRecordTest, FileSizeOnFrequency2000_DWARF_PROCESS, TestSize.Level1)
|
||||
{
|
||||
ForkAndRunTest("-d 10 --app com.ohos.systemui -f 2000 -s dwarf", true, false);
|
||||
ForkAndRunTest("-d 10 -f 2000 -s dwarf", true, true);
|
||||
std::string fileName = TEST_FILE;
|
||||
size_t fileSize = GetFileSize(fileName.c_str());
|
||||
EXPECT_LE(fileSize, TEST_SIZE_F2000_DWARF_PROCESS);
|
||||
@ -1100,7 +1102,7 @@ HWTEST_F(SubCommandRecordTest, FileSizeOnFrequency2000_DWARF_PROCESS, TestSize.L
|
||||
*/
|
||||
HWTEST_F(SubCommandRecordTest, FileSizeOnFrequency4000_DWARF_PROCESS, TestSize.Level1)
|
||||
{
|
||||
ForkAndRunTest("-d 10 --app com.ohos.systemui -f 4000 -s dwarf", true, false);
|
||||
ForkAndRunTest("-d 10 -f 4000 -s dwarf", true, true);
|
||||
std::string fileName = TEST_FILE;
|
||||
size_t fileSize = GetFileSize(fileName.c_str());
|
||||
EXPECT_LE(fileSize, TEST_SIZE_F4000_DWARF_PROCESS);
|
||||
@ -1113,7 +1115,7 @@ HWTEST_F(SubCommandRecordTest, FileSizeOnFrequency4000_DWARF_PROCESS, TestSize.L
|
||||
*/
|
||||
HWTEST_F(SubCommandRecordTest, FileSizeOnFrequency8000_DWARF_PROCESS, TestSize.Level1)
|
||||
{
|
||||
ForkAndRunTest("-d 10 --app com.ohos.systemui -f 8000 -s dwarf", true, false);
|
||||
ForkAndRunTest("-d 10 -f 8000 -s dwarf", true, true);
|
||||
std::string fileName = TEST_FILE;
|
||||
size_t fileSize = GetFileSize(fileName.c_str());
|
||||
EXPECT_LE(fileSize, TEST_SIZE_F8000_DWARF_PROCESS);
|
||||
@ -1126,7 +1128,7 @@ HWTEST_F(SubCommandRecordTest, FileSizeOnFrequency8000_DWARF_PROCESS, TestSize.L
|
||||
*/
|
||||
HWTEST_F(SubCommandRecordTest, FileSizeOnFrequency100_FP_PROCESS, TestSize.Level1)
|
||||
{
|
||||
ForkAndRunTest("-d 10 --app com.ohos.systemui -f 100 -s fp", true, false);
|
||||
ForkAndRunTest("-d 10 -f 100 -s fp", true, true);
|
||||
std::string fileName = TEST_FILE;
|
||||
size_t fileSize = GetFileSize(fileName.c_str());
|
||||
EXPECT_LE(fileSize, TEST_SIZE_F100_FP_PROCESS);
|
||||
@ -1139,7 +1141,7 @@ HWTEST_F(SubCommandRecordTest, FileSizeOnFrequency100_FP_PROCESS, TestSize.Level
|
||||
*/
|
||||
HWTEST_F(SubCommandRecordTest, FileSizeOnFrequency500_FP_PROCESS, TestSize.Level1)
|
||||
{
|
||||
ForkAndRunTest("-d 10 --app com.ohos.systemui -f 500 -s fp", true, false);
|
||||
ForkAndRunTest("-d 10 -f 500 -s fp", true, true);
|
||||
std::string fileName = TEST_FILE;
|
||||
size_t fileSize = GetFileSize(fileName.c_str());
|
||||
EXPECT_LE(fileSize, TEST_SIZE_F500_FP_PROCESS);
|
||||
@ -1152,7 +1154,7 @@ HWTEST_F(SubCommandRecordTest, FileSizeOnFrequency500_FP_PROCESS, TestSize.Level
|
||||
*/
|
||||
HWTEST_F(SubCommandRecordTest, FileSizeOnFrequency1000_FP_PROCESS, TestSize.Level1)
|
||||
{
|
||||
ForkAndRunTest("-d 10 --app com.ohos.systemui -f 1000 -s fp", true, false);
|
||||
ForkAndRunTest("-d 10 -f 1000 -s fp", true, true);
|
||||
std::string fileName = TEST_FILE;
|
||||
size_t fileSize = GetFileSize(fileName.c_str());
|
||||
EXPECT_LE(fileSize, TEST_SIZE_F1000_FP_PROCESS);
|
||||
@ -1165,7 +1167,7 @@ HWTEST_F(SubCommandRecordTest, FileSizeOnFrequency1000_FP_PROCESS, TestSize.Leve
|
||||
*/
|
||||
HWTEST_F(SubCommandRecordTest, FileSizeOnFrequency2000_FP_PROCESS, TestSize.Level1)
|
||||
{
|
||||
ForkAndRunTest("-d 10 --app com.ohos.systemui -f 2000 -s fp", true, false);
|
||||
ForkAndRunTest("-d 10 -f 2000 -s fp", true, true);
|
||||
std::string fileName = TEST_FILE;
|
||||
size_t fileSize = GetFileSize(fileName.c_str());
|
||||
EXPECT_LE(fileSize, TEST_SIZE_F2000_FP_PROCESS);
|
||||
@ -1178,7 +1180,7 @@ HWTEST_F(SubCommandRecordTest, FileSizeOnFrequency2000_FP_PROCESS, TestSize.Leve
|
||||
*/
|
||||
HWTEST_F(SubCommandRecordTest, FileSizeOnFrequency4000_FP_PROCESS, TestSize.Level1)
|
||||
{
|
||||
ForkAndRunTest("-d 10 --app com.ohos.systemui -f 4000 -s fp", true, false);
|
||||
ForkAndRunTest("-d 10 -f 4000 -s fp", true, true);
|
||||
std::string fileName = TEST_FILE;
|
||||
size_t fileSize = GetFileSize(fileName.c_str());
|
||||
EXPECT_LE(fileSize, TEST_SIZE_F4000_FP_PROCESS);
|
||||
@ -1191,7 +1193,7 @@ HWTEST_F(SubCommandRecordTest, FileSizeOnFrequency4000_FP_PROCESS, TestSize.Leve
|
||||
*/
|
||||
HWTEST_F(SubCommandRecordTest, FileSizeOnFrequency8000_FP_PROCESS, TestSize.Level1)
|
||||
{
|
||||
ForkAndRunTest("-d 10 --app com.ohos.systemui -f 8000 -s fp", true, false);
|
||||
ForkAndRunTest("-d 10 -f 8000 -s fp", true, true);
|
||||
std::string fileName = TEST_FILE;
|
||||
size_t fileSize = GetFileSize(fileName.c_str());
|
||||
EXPECT_LE(fileSize, TEST_SIZE_F8000_FP_PROCESS);
|
||||
|
Loading…
Reference in New Issue
Block a user