!1894 内存调优

Merge pull request !1894 from 金海/master
This commit is contained in:
openharmony_ci 2024-09-14 09:23:02 +00:00 committed by Gitee
commit 4959aed214
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
33 changed files with 102 additions and 1333 deletions

View File

@ -53,11 +53,8 @@ ohos_executable("SP_daemon") {
"navigation.cpp",
"parse_click_complete_trace.cpp",
"parse_click_response_trace.cpp",
"parse_page_fps_trace.cpp",
"parse_radar.cpp",
"parse_slide_fps_trace.cpp",
"parse_start_frame_trace.cpp",
"parse_trace.cpp",
"profiler_fps.cpp",
"sdk_data_recv.cpp",
"smartperf_command.cpp",

View File

@ -45,7 +45,6 @@ void ByTrace::ThreadGetTrace() const
std::string traceFile = "/data/local/tmp/sptrace_" + time + ".ftrace";
std::string traceCmdExe = cmdString + traceFile;
SPUtils::LoadCmd(traceCmdExe, result);
std::cout << "TRACE threadGetTrace >> CMD >>" << traceCmdExe << std::endl;
LOGI("TRACE threadGetTrace CMD(%s)", traceCmdExe.c_str());
}
TraceStatus ByTrace::CheckFpsJitters(std::vector<long long> jitters, int cfps) const
@ -61,9 +60,6 @@ TraceStatus ByTrace::CheckFpsJitters(std::vector<long long> jitters, int cfps) c
}
}
}
std::cout << "TRACE CHECK RUNING >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" << std::endl;
std::cout << "TRACE CHECK lastTriggerTime:" << lastTriggerTime << " curTime:" << curTime << " currentTrigger:" <<
currentTrigger << std::endl;
if ((curTime - lastTriggerTime) / 1e3 > interval && currentTrigger == 1) {
currentTrigger = -1;
}

View File

@ -37,13 +37,14 @@ std::map<std::string, std::string> Capture::ItemData()
int two = 2;
if (callNum % two == 0) {
curTime = GetCurTimes();
std::string screenCapPath = "data/local/tmp/capture/screenCap_" + std::to_string(curTime);
if (isSocketMessage) {
std::string path = "data/local/tmp/capture/screenCap_" + std::to_string(curTime) + ".jpeg";
std::string path = screenCapPath + ".jpeg";
result["capture"] = path;
Capture::TriggerGetCatchSocket(curTime);
isSocketMessage = false;
} else {
std::string path = "data/local/tmp/capture/screenCap_" + std::to_string(curTime) + ".png";
std::string path = screenCapPath + ".png";
result["capture"] = path;
Capture::TriggerGetCatch();
if (result.find("capture") != result.end() && result["capture"].empty()) {
@ -83,21 +84,19 @@ void Capture::ThreadGetCatch()
std::ostringstream errorRecv;
auto fd = open(savePath.c_str(), O_RDWR | O_CREAT, 0666);
if (fd == -1) {
printf("Failed to open file: %s\n", savePath.c_str());
LOGI("Failed to open file: %s", savePath.c_str());
}
if (!TakeScreenCap(savePath)) {
std::cout << "Screen Capture Failed:---" << errorRecv.str() << std::endl;
LOGE("Screen Capture Failed!");
}
close(fd);
}
void Capture::ThreadGetCatchSocket(const std::string &curTime) const
void Capture::ThreadGetCatchSocket(const std::string &captureTime) const
{
std::string captureDir = "/data/local/tmp/capture";
std::string savePath = captureDir + "/screenCap_" + curTime + ".jpeg";
std::string savePath = captureDir + "/screenCap_" + captureTime + ".jpeg";
std::string cmdResult;
if (!SPUtils::FileAccess(captureDir)) {
std::string capturePath = CMD_COMMAND_MAP.at(CmdCommand::CAPTURE_FILE);
@ -116,7 +115,6 @@ void Capture::ThreadGetCatchSocket(const std::string &curTime) const
auto fd = open(realPath, O_RDWR | O_CREAT, 0644);
if (fd == -1) {
printf("Failed to open file: %s\n", savePath.c_str());
LOGI("Failed to open file: %s", savePath.c_str());
}
std::string snapshot = CMD_COMMAND_MAP.at(CmdCommand::SNAPSHOT);
@ -147,12 +145,10 @@ void Capture::TriggerGetCatchSocket(long long captureTime) const
bool Capture::TakeScreenCap(const std::string &savePath) const
{
// get PixelMap from DisplayManager API
Rosen::DisplayManager &displayMgr = Rosen::DisplayManager::GetInstance();
std::shared_ptr<Media::PixelMap> pixelMap = displayMgr.GetScreenshot(displayMgr.GetDefaultDisplayId());
static constexpr int bitmapDepth = 8;
if (pixelMap == nullptr) {
std::cout << "Failed to get display pixelMap" << std::endl;
LOGE("Failed to get display pixelMap");
return false;
}
@ -162,13 +158,11 @@ bool Capture::TakeScreenCap(const std::string &savePath) const
auto stride = static_cast<uint32_t>(pixelMap->GetRowBytes());
png_structp pngStruct = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr);
if (pngStruct == nullptr) {
std::cout << "error: png_create_write_struct nullptr!" << std::endl;
LOGE("png_create_write_struct nullptr!");
return false;
}
png_infop pngInfo = png_create_info_struct(pngStruct);
if (pngInfo == nullptr) {
std::cout << "error: png_create_info_struct error nullptr!" << std::endl;
LOGE("png_create_info_struct error nullptr!");
png_destroy_write_struct(&pngStruct, nullptr);
return false;
@ -179,7 +173,6 @@ bool Capture::TakeScreenCap(const std::string &savePath) const
}
FILE *fp = fopen(realPath, "wb");
if (fp == nullptr) {
std::cout << "error: open file error!" << std::endl;
LOGE("open file error!");
png_destroy_write_struct(&pngStruct, &pngInfo);
return false;

View File

@ -39,11 +39,10 @@ std::map<std::string, std::string> FPS::ItemData()
FpsInfo fpsInfoResult;
if (surfaceViewName.length() > 0) {
fpsInfoResult = GetDiffLayersFpsInfo(surfaceViewName);
prevResultFpsInfo = fpsInfoResult;
} else {
fpsInfoResult = GetFpsInfo();
prevResultFpsInfo = fpsInfoResult;
}
prevResultFpsInfo = fpsInfoResult;
std::string screenInfo;
SPUtils::LoadFile(screenPath, screenInfo);
size_t pos = 0;
@ -67,8 +66,8 @@ std::map<std::string, std::string> FPS::ItemData()
fpsInfoResult.fps = fullFrame;
}
result["fps"] = std::to_string(fpsInfoResult.fps);
LOGI("result.fps====: %s", std::to_string(fpsInfoResult.fps).c_str());
LOGI("result.curTime====: %s", std::to_string(fpsInfoResult.curTime).c_str());
LOGI("result.fps: %s", std::to_string(fpsInfoResult.fps).c_str());
LOGI("result.curTime: %s", std::to_string(fpsInfoResult.curTime).c_str());
std::string jitterStr = "";
std::string split = "";
for (size_t i = 0; i < fpsInfoResult.jitters.size(); i++) {
@ -78,10 +77,9 @@ std::map<std::string, std::string> FPS::ItemData()
jitterStr += split + std::to_string(fpsInfoResult.jitters[i]);
}
result["fpsJitters"] = jitterStr;
LOGI("result.jitters====: %s", jitterStr.c_str());
LOGI("result.jitters: %s", jitterStr.c_str());
SetFpsCurrentFpsTime(fpsInfoResult);
}
LOGI("FPS::ItemData map size(%u)", result.size());
return result;
}
@ -115,25 +113,11 @@ void FPS::SetLayerName(std::string sName)
}
FpsInfo FPS::GetDiffLayersFpsInfo(const std::string &sName)
{
GetCurrentTime();
OHOS::SmartPerf::SPUtils::GetCurrentTime(fifty, prevResultFpsInfo.curTime);
fpsInfoMax = GetSurfaceFrame(sName);
return fpsInfoMax;
}
void FPS::GetCurrentTime()
{
for (int i = 0; i < fifty; i++) {
struct timespec time1 = { 0 };
clock_gettime(CLOCK_MONOTONIC, &time1);
int curTimeNow = static_cast<int>(time1.tv_sec - 1);
if (curTimeNow == prevResultFpsInfo.curTime) {
usleep(sleepNowTime);
} else {
break;
}
}
}
FpsInfo FPS::GetFpsInfo()
{
processFlag = false;
@ -141,13 +125,13 @@ FpsInfo FPS::GetFpsInfo()
if (pkgName.empty()) {
return fpsInfoMax;
}
bool onTop = IsForeGround();
bool onTop = OHOS::SmartPerf::SPUtils::IsForeGround(pkgName);
if (onTop) {
LOGI("onTop===========");
std::string uniteLayer = "UniRender";
GetCurrentTime();
OHOS::SmartPerf::SPUtils::GetCurrentTime(fifty, prevResultFpsInfo.curTime);
fpsInfoMax = GetSurfaceFrame(uniteLayer);
} else {
LOGI("FPS:app is in the background");
if (processId.empty()) {
processFlag = true;
fpsInfoMax.Clear();
@ -210,10 +194,8 @@ void FPS::ReadDataFromPipe(int fd)
clock_gettime(CLOCK_MONOTONIC, &time1);
fpsInfo.curTime = static_cast<int>(time1.tv_sec - 1);
fpsInfo.currTimeDump = (time1.tv_sec - 1) * mod + time1.tv_nsec;
LOGI("FPS::time1.tv_sec: %s", std::to_string(time1.tv_sec).c_str());
LOGI("FPS::time1.tv_nsec: %s", std::to_string(time1.tv_nsec).c_str());
LOGI("FPS::fpsInfo.curTime: %s", std::to_string(fpsInfo.curTime).c_str());
LOGI("FPS::psInfo.currTimeDump: %s", std::to_string(fpsInfo.currTimeDump).c_str());
LOGI("FPS:fpsInfo.curTime: %d", fpsInfo.curTime);
LOGI("FPS:psInfo.currTimeDump: %lld", fpsInfo.currTimeDump);
FILE *fp = fdopen(fd, "r");
if (!fp) {
LOGE("FPS::Failed to open file descriptor");
@ -263,46 +245,6 @@ void FPS::CalcFpsAndJitters()
prevlastScreenTimestamp = curScreenTimestamp;
}
}
bool FPS::IsForeGround()
{
const std::string cmd = "aa dump -l";
char buf[1024] = {'\0'};
std::string appLine = "app name [" + pkgName;
std::string bundleLine = "bundle name [" + pkgName;
FILE *fd = popen(cmd.c_str(), "r");
if (fd == nullptr) {
return false;
}
bool tag = false;
while (fgets(buf, sizeof(buf), fd) != nullptr) {
std::string line = buf;
if (line.find(appLine) != std::string::npos) {
isFoundAppName = true;
}
if (line.find(bundleLine) != std::string::npos) {
isFoundBundleName = true;
}
if (isFoundAppName || isFoundBundleName) {
if (line.find("app state") != std::string::npos) {
tag = IsFindForeGround(line);
isFoundAppName = false;
isFoundBundleName = false;
}
}
}
pclose(fd);
return tag;
}
bool FPS::IsFindForeGround(std::string line) const
{
std::string foreGroundTag = line.substr(line.find("#") + 1);
if (foreGroundTag.find("FOREGROUND") != std::string::npos) {
return true;
} else {
return false;
}
}
}
}

View File

@ -32,9 +32,7 @@ namespace OHOS {
namespace SmartPerf {
std::map<std::string, std::string> Network::ItemData()
{
std::map<std::string, std::string> result;
std::map<std::string, std::string> networkInfo = Network::GetNetworkInfo();
result = networkInfo;
std::map<std::string, std::string> result = Network::GetNetworkInfo();
LOGI("Network ItemData map siez=%u", result.size());
if (result.find("networkUp") != result.end() && result["networkUp"].empty()) {
result["networkUp"] = "NA";

View File

@ -81,7 +81,6 @@ int ClientControl::InitSocket()
{
clientSocket = socket(AF_INET, SOCK_STREAM, 0);
if (clientSocket == -1) {
std::cout << "Faild to create socket" << std::endl;
LOGE("Faild to create socket");
return -1;
}
@ -89,7 +88,6 @@ int ClientControl::InitSocket()
serverAddress.sin_addr.s_addr = inet_addr("127.0.0.1");
serverAddress.sin_port = htons(protNumber);
if (connect(clientSocket, reinterpret_cast<struct sockaddr *>(&serverAddress), sizeof(serverAddress)) < 0) {
std::cout << "Failed to connect to server" << std::endl;
OHOS::SmartPerf::StartUpDelay sd;
sd.GetSpClear();
LOGE("Failed to connect to server");

View File

@ -22,12 +22,9 @@
#include <future>
#include "include/control_call_cmd.h"
#include "include/startup_delay.h"
#include "include/parse_trace.h"
#include "include/sp_utils.h"
#include "include/parse_click_complete_trace.h"
#include "include/parse_click_response_trace.h"
#include "include/parse_page_fps_trace.h"
#include "include/parse_start_frame_trace.h"
#include "include/parse_radar.h"
#include "include/parse_slide_fps_trace.h"
#include "include/sp_log.h"
@ -40,23 +37,10 @@ std::string ControlCallCmd::GetResult(std::vector<std::string> v)
{
if (v[ohType] == "ohtest") {
isOhTest = true;
}
if (v[typeName] == "coldStart") {
time = SmartPerf::ControlCallCmd::ColdStart(v);
} else if (v[typeName] == "hotStart") {
time = SmartPerf::ControlCallCmd::HotStart(v);
} else if (v[typeName] == "responseTime") {
time = SmartPerf::ControlCallCmd::ResponseTime();
} else if (v[typeName] == "completeTime") {
time = SmartPerf::ControlCallCmd::CompleteTime();
} else if (v[typeName] == "startResponse") {
time = SmartPerf::ControlCallCmd::StartResponse(v);
} else if (v[typeName] == "coldStartHM") {
time = SmartPerf::ControlCallCmd::ColdStartHM(v);
} else if (v[typeName] == "pagefps") {
result = SmartPerf::ControlCallCmd::PageFps();
} else if (v[typeName] == "startFrame") {
result = SmartPerf::ControlCallCmd::StartFrameFps(v);
} else if (v[typeName] == "fpsohtest") {
std::string ohTestFps = CMD_COMMAND_MAP.at(CmdCommand::OHTESTFPS);
SPUtils::LoadCmd(ohTestFps, result);
@ -197,21 +181,6 @@ std::string ControlCallCmd::GetFrame()
std::string reslut = radar.ParseRadarFrame(str);
return result;
}
std::string ControlCallCmd::PageFps()
{
OHOS::SmartPerf::StartUpDelay sd;
OHOS::SmartPerf::ParsePageFpsTrace pageFpsTrace;
std::string cmdResult;
std::string rmTrace = CMD_COMMAND_MAP.at(CmdCommand::RM_FILE) + "*" + ".ftrace";
SPUtils::LoadCmd(rmTrace, cmdResult);
std::string traceName = std::string("/data/local/tmp/") + std::string("sp_trace_") + "fps" + ".ftrace";
std::thread thGetTrace = std::thread([&sd, traceName]() { sd.GetTrace("fps", traceName); });
thGetTrace.join();
double fps = pageFpsTrace.PageFpsTrace(traceName);
stream << fps;
result = "FPS:" + stream.str() + "fps";
return result;
}
double ControlCallCmd::ResponseTime()
{
OHOS::SmartPerf::ParseClickResponseTrace pcrt;
@ -235,20 +204,6 @@ double ControlCallCmd::ResponseTime()
}
return time;
}
double ControlCallCmd::ColdStartHM(std::vector<std::string> v) const
{
OHOS::SmartPerf::StartUpDelay sd;
OHOS::SmartPerf::ParseTrace parseTrace;
std::string cmdResult;
int typePKG = 3;
std::string rmTrace = CMD_COMMAND_MAP.at(CmdCommand::RM_FILE) + "*" + ".ftrace";
SPUtils::LoadCmd(rmTrace, cmdResult);
std::string traceName = std::string("/data/local/tmp/") + std::string("sp_trace_") + "coldStart" + ".ftrace";
std::thread thGetTrace = std::thread([&sd, traceName]() { sd.GetTrace("coldStart", traceName); });
thGetTrace.join();
std::string pid = sd.GetPidByPkg(v[typePKG]);
return parseTrace.ParseTraceCold(traceName, pid);
}
double ControlCallCmd::CompleteTime()
{
OHOS::SmartPerf::StartUpDelay sd;
@ -272,69 +227,6 @@ double ControlCallCmd::CompleteTime()
}
return time;
}
std::string ControlCallCmd::StartFrameFps(std::vector<std::string> v)
{
OHOS::SmartPerf::StartUpDelay sd;
OHOS::SmartPerf::ParseTrace parseTrace;
OHOS::SmartPerf::StartFrameTraceNoh startFrameTraceNoh;
std::string cmdResult;
int type = 4;
int typePKG = 3;
std::string rmTrace = CMD_COMMAND_MAP.at(CmdCommand::RM_FILE);
std::string uitest = CMD_COMMAND_MAP.at(CmdCommand::UITEST_DUMPLAYOUT);
SPUtils::LoadCmd(rmTrace + "*" + ".json", cmdResult);
SPUtils::LoadCmd(rmTrace + "*" + ".ftrace", cmdResult);
SPUtils::LoadCmd(uitest, cmdResult);
sleep(1);
size_t position = cmdResult.find(":");
size_t position2 = cmdResult.find("json");
std::string pathJson = cmdResult.substr(position + 1, position2 - position + typePKG);
sd.InitXY2(v[type], pathJson, v[typePKG]);
std::string traceName = std::string("/data/local/tmp/") + std::string("sp_trace_") + "coldStart" + ".ftrace";
std::thread thGetTrace = std::thread([&sd, traceName]() { sd.GetTrace("coldStart", traceName); });
std::string cmd = CMD_COMMAND_MAP.at(CmdCommand::UINPUT_POINT) + sd.pointXY + " -u " + sd.pointXY;
sleep(1);
SPUtils::LoadCmd(cmd, cmdResult);
sleep(1);
thGetTrace.join();
double fps = startFrameTraceNoh.ParseStartFrameTraceNoh(traceName);
stream << fps;
result = "FPS:" + stream.str() + "fps";
return result;
}
double ControlCallCmd::StartResponse(std::vector<std::string> v)
{
OHOS::SmartPerf::StartUpDelay sd;
OHOS::SmartPerf::ParseTrace parseTrace;
OHOS::SmartPerf::ParseRadar radar;
std::string cmdResult;
int type = 4;
int typePKG = 3;
std::string rmTrace = CMD_COMMAND_MAP.at(CmdCommand::RM_FILE);
std::string uitest = CMD_COMMAND_MAP.at(CmdCommand::UITEST_DUMPLAYOUT);
SPUtils::LoadCmd(rmTrace + "*" + ".json", cmdResult);
SPUtils::LoadCmd(rmTrace + "*" + ".ftrace", cmdResult);
SPUtils::LoadCmd(uitest, cmdResult);
sleep(1);
size_t position = cmdResult.find(":");
size_t position2 = cmdResult.find("json");
std::string pathJson = cmdResult.substr(position + 1, position2 - position + typePKG);
sd.InitXY2(v[type], pathJson, v[typePKG]);
std::string traceName = std::string("/data/local/tmp/") + std::string("sp_trace_") + "startResponse" + ".ftrace";
if (sd.pointXY == "0 0") {
return noNameType;
} else {
std::thread thGetTrace = std::thread([&sd, traceName]() { sd.GetTrace("startResponse", traceName); });
std::thread thInputEvent = std::thread([&sd]() { sd.InputEvent(sd.pointXY); });
std::thread thGetHisysId = std::thread([&sd]() { sd.GetHisysId(); });
std::string str = SPUtils::GetRadar();
thGetTrace.join();
thInputEvent.join();
thGetHisysId.join();
time = radar.ParseRadarStartResponse(str);
return time;
}
}
std::string ControlCallCmd::GetAppStartTime() const
{
OHOS::SmartPerf::StartUpDelay sd;
@ -374,98 +266,5 @@ std::string ControlCallCmd::GetAppStartTime() const
resultStream = resultStream + hitchTimeRate + resultStream2;
return resultStream;
}
double ControlCallCmd::ColdStart(std::vector<std::string> v)
{
OHOS::SmartPerf::StartUpDelay sd;
OHOS::SmartPerf::ParseTrace parseTrace;
OHOS::SmartPerf::ParseRadar radar;
std::string cmdResult;
int type = 4;
int typePKG = 3;
std::string rmTrace = CMD_COMMAND_MAP.at(CmdCommand::RM_FILE);
std::string uitest = CMD_COMMAND_MAP.at(CmdCommand::UITEST_DUMPLAYOUT);
SPUtils::LoadCmd(rmTrace + "*" + ".json", cmdResult);
SPUtils::LoadCmd(rmTrace + "*" + ".ftrace", cmdResult);
SPUtils::LoadCmd(uitest, cmdResult);
sleep(1);
size_t position = cmdResult.find(":");
size_t position2 = cmdResult.find("json");
std::string pathJson = cmdResult.substr(position + 1, position2 - position + typePKG);
sd.InitXY2(v[type], pathJson, v[typePKG]);
std::string traceName = std::string("/data/local/tmp/") + std::string("sp_trace_") + "coldStart" + ".ftrace";
if (sd.pointXY == "0 0") {
return noNameType;
} else {
if (isOhTest) {
std::thread thGetTrace = std::thread([&sd, traceName]() { sd.GetTrace("coldStart", traceName); });
std::string cmd = CMD_COMMAND_MAP.at(CmdCommand::UINPUT_POINT) + sd.pointXY + " -u " + sd.pointXY;
sleep(1);
SPUtils::LoadCmd(cmd, cmdResult);
sleep(1);
std::string pid = sd.GetPidByPkg(v[typePKG]);
thGetTrace.join();
time = parseTrace.ParseTraceCold(traceName, pid);
} else {
std::thread thGetTrace = std::thread([&sd, traceName]() { sd.GetTrace("coldStart", traceName); });
std::thread thInputEvent = std::thread([&sd]() { sd.InputEvent(sd.pointXY); });
std::thread thGetHisysId = std::thread([&sd]() { sd.GetHisysId(); });
sleep(1);
std::string str = SPUtils::GetRadar();
thGetTrace.join();
thInputEvent.join();
thGetHisysId.join();
time = radar.ParseRadarStart(str);
}
return time;
}
}
double ControlCallCmd::HotStart(std::vector<std::string> v)
{
OHOS::SmartPerf::StartUpDelay sd;
OHOS::SmartPerf::ParseTrace parseTrace;
OHOS::SmartPerf::ParseRadar radar;
std::string cmdResult;
if (isOhTest) {
std::string rmTrace = CMD_COMMAND_MAP.at(CmdCommand::RM_FILE) + "*" + ".ftrace";
SPUtils::LoadCmd(rmTrace, cmdResult);
std::string traceName = std::string("/data/local/tmp/") + std::string("sp_trace_") + "hotStart" + ".ftrace";
std::thread thGetTrace = std::thread([&sd, traceName]() { sd.GetTrace("hotStart", traceName); });
thGetTrace.join();
return parseTrace.ParseTraceHot(traceName);
} else {
int type = 4;
int typePKG = 3;
std::string rmTrace = CMD_COMMAND_MAP.at(CmdCommand::RM_FILE);
std::string uitest = CMD_COMMAND_MAP.at(CmdCommand::UITEST_DUMPLAYOUT);
SPUtils::LoadCmd(rmTrace + "*" + ".json", cmdResult);
SPUtils::LoadCmd(rmTrace + "*" + ".ftrace", cmdResult);
SPUtils::LoadCmd(uitest, cmdResult);
sleep(1);
size_t position = cmdResult.find(":");
size_t position2 = cmdResult.find("json");
std::string pathJson = cmdResult.substr(position + 1, position2 - position + typePKG);
sd.InitXY2(v[type], pathJson, v[typePKG]);
if (sd.pointXY == "0 0") {
return noNameType;
} else {
std::string cmd = CMD_COMMAND_MAP.at(CmdCommand::UINPUT_POINT) + sd.pointXY + " -u " + sd.pointXY;
SPUtils::LoadCmd(cmd, cmdResult);
sleep(1);
sd.ChangeToBackground();
sleep(1);
std::string traceName = std::string("/data/local/tmp/") + std::string("sp_trace_") + "hotStart" + ".ftrace";
std::thread thGetTrace = std::thread([&sd, traceName]() { sd.GetTrace("hotStart", traceName); });
std::thread thInputEvent = std::thread([&sd]() { sd.InputEvent(sd.pointXY); });
std::thread thGetHisysId = std::thread([&sd]() { sd.GetHisysId(); });
sleep(1);
std::string str = SPUtils::GetRadar();
thGetTrace.join();
thInputEvent.join();
thGetHisysId.join();
time = radar.ParseRadarStart(str);
return time;
}
}
}
}
}

View File

@ -27,7 +27,7 @@ public:
}
// 截图线程
void ThreadGetCatch();
void ThreadGetCatchSocket(const std::string &curTime) const;
void ThreadGetCatchSocket(const std::string &captureTime) const;
// 触发线程
void TriggerGetCatch();
void TriggerGetCatchSocket(long long captureTime) const;

View File

@ -64,10 +64,7 @@ public:
void SetLayerName(std::string sName);
FpsInfo GetFpsInfo();
FpsInfo GetDiffLayersFpsInfo(const std::string &sName);
bool IsForeGround();
bool IsFindForeGround(std::string line) const;
void CalcFpsAndJitters();
void GetCurrentTime();
FpsInfo fpsInfo;
FpsInfo fpsInfoMax;
FpsInfo prevResultFpsInfo;
@ -95,9 +92,6 @@ private:
long long prevlastScreenTimestamp = 0;
int fpsNum = 0;
FpsInfo GetSurfaceFrame(std::string name);
unsigned long sleepNowTime = 10000;
bool isFoundAppName = false;
bool isFoundBundleName = false;
int fifty = 50;
FpsCurrentFpsTime ffTime;
bool processFlag = false;

View File

@ -181,8 +181,6 @@ enum class CmdCommand {
SERVER,
OHTESTFPS,
RM_FILE,
UITEST_DUMPLAYOUT,
UINPUT_POINT,
DUBAI_CP,
DUBAI_CHMOD,
TASKSET,
@ -213,8 +211,6 @@ const std::unordered_map<CmdCommand, std::string> CMD_COMMAND_MAP = {
{ CmdCommand::SERVER, std::string("SP_daemon -server") },
{ CmdCommand::OHTESTFPS, std::string("SP_daemon -ohtestfps 10") },
{ CmdCommand::RM_FILE, std::string("rm -rfv /data/local/tmp/") },
{ CmdCommand::UITEST_DUMPLAYOUT, std::string("uitest dumpLayout") },
{ CmdCommand::UINPUT_POINT, std::string("uinput -T -d ") },
{ CmdCommand::DUBAI_CP, std::string(
"cp /data/service/el2/100/xpower/dubai.db /data/app/el2/100/database/com.ohos.smartperf/entry/rdb") },
{ CmdCommand::DUBAI_CHMOD, std::string(

View File

@ -22,14 +22,8 @@ namespace OHOS {
namespace SmartPerf {
class ControlCallCmd {
public:
double ColdStart(std::vector<std::string> v);
double ColdStartHM(std::vector<std::string> v) const;
double HotStart(std::vector<std::string> v);
double CompleteTime();
double ResponseTime();
double StartResponse(std::vector<std::string> v);
std::string PageFps();
std::string StartFrameFps(std::vector<std::string> v);
std::string GetResult(std::vector<std::string> v);
std::string GetFrame();
std::string GetAppStartTime() const;

View File

@ -1,47 +0,0 @@
/*
* Copyright (C) 2021 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 PARSE_PAGE_FPS_TRACE_H
#define PARSE_PAGE_FPS_TRACE_H
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
namespace OHOS {
namespace SmartPerf {
class ParsePageFpsTrace {
public:
double PageFpsTrace(std::string file);
double CalculateTime();
double CalculateTimeEnd();
std::string GetLineTime(std::string line);
std::string CutString(std::string line, const std::string &start, const std::string &end, size_t offset);
private:
std::ifstream infile;
std::string startLine = "";
std::string responseLine = "";
std::string completeLine = "";
bool needUpdateResponseLine = false;
int frameNum = 0;
std::string pid = "";
int count = 0;
bool updateCount = false;
double frameStartTime = 0;
double frameEndTime = 0;
double frameStartInterval = 0;
};
}
}
#endif

View File

@ -1,56 +0,0 @@
/*
* Copyright (C) 2021 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 PARSE_START_FRAME_TRACE_H
#define PARSE_START_FRAME_TRACE_H
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
namespace OHOS {
namespace SmartPerf {
class StartFrameTraceNoh {
public:
double ParseStartFrameTraceNoh(std::string file);
double CalculateTime();
double GetFps();
std::string GetLineTime(std::string line);
std::string CutString(std::string line, const std::string &start, const std::string &end, size_t offset);
std::vector<std::string> Split(std::string str, const std::string &pattern);
private:
std::ifstream infile;
int twelve = 12;
int four = 4;
std::string startLine = "";
std::string fullScreenLine = "";
int frameNum = 0;
int count = 0;
std::string pid = "";
bool isNeedEnd = false;
double frameStartTime = 0;
double frameEndTime = 0;
struct FrameTimeSet {
int frameId = 0;
double times = 0.0;
};
FrameTimeSet startTimes;
FrameTimeSet endTimes;
std::vector<FrameTimeSet> startTimeArr;
std::vector<FrameTimeSet> endTimeArr;
std::string::size_type maxnpos = std::string::npos;
};
}
}
#endif

View File

@ -1,48 +0,0 @@
/*
* Copyright (C) 2021 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 PARSE_TRACE_H
#define PARSE_TRACE_H
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
namespace OHOS {
namespace SmartPerf {
class ParseTrace {
public:
double ParseTraceCold(const std::string &fileNamePath, const std::string &appPid);
double ParseTraceHot(const std::string &fileNamePath);
double ParseNohTrace(const std::string &fileNamePath, const std::string &appPid);
double ParseTraceNoh(const std::string &fileNamePath, const std::string &appPid);
double ParseCodeTrace(const std::string &fileNamePath, const std::string &appPid);
double ParseHotTrace(const std::string &fileNamePath);
static double GetTime(std::string start, std::string end);
std::string GetStartTime(std::string line, const std::string &startTimeBefore);
std::string GetWindowTime(std::string line, const std::string &wt);
std::string GetFrameId(std::string line, const std::string &appPid, const std::string &fid);
private:
std::ifstream infile;
std::string flagTime = "0";
size_t flagTouch = 0;
std::string startTime = "0";
std::string endTime = "0";
std::string endTimeFlag = "0";
std::string windowTime = "0";
std::string frameId = "0";
};
}
}
#endif

View File

@ -137,6 +137,9 @@ bool IntegerValueVerification(std::set<std::string> &keys, std::map<std::string,
std::string &errorInfo);
bool IsHmKernel();
std::string GetCpuNum();
void GetCurrentTime(int num, int prevTime);
bool IsForeGround(std::string &pkg);
bool IsFindForeGround(std::string line);
};
}
}

View File

@ -23,23 +23,12 @@ public:
StartUpDelay();
~StartUpDelay();
void GetTrace(const std::string &sessionID, const std::string &traceName) const;
std::thread ThreadGetTrace(const std::string &sessionID, const std::string &traceName) const;
void GetLayout();
std::thread ThreadGetLayout();
void InputEvent(const std::string &point);
std::thread ThreadInputEvent(const std::string &point);
void GetHisysIdAndKill() const;
std::thread ThreadGetHisysIds() const;
void GetHisysId() const;
std::thread ThreadGetHisysId() const;
void ChangeToBackground();
std::string GetPidByPkg(const std::string &curPkgName);
bool GetSpTcp();
bool GetSpClear();
void ClearOldServer();
void InitXY2(const std::string &curAppName, const std::string &fileName, const std::string &appPkgName);
void InitXY(const std::string &curAppName, const std::string &fileName);
std::string pointXY = "0 0";
};
}
}

View File

@ -23,11 +23,7 @@ namespace OHOS {
namespace SmartPerf {
std::map<std::string, std::string> Navigation::ItemData()
{
std::map<std::string, std::string> result;
std::map<std::string, std::string> navInfo = Navigation::GetNavInfo();
for (auto it = navInfo.begin(); it != navInfo.end(); ++it) {
result.insert(*it);
}
std::map<std::string, std::string> result = Navigation::GetNavInfo();
LOGI("Navigation::ItemData map size(%u)", result.size());
return result;
}

View File

@ -34,8 +34,6 @@ double ParseClickCompleteTrace::ParseCompleteTrace(std::string fileNamePath)
}
infile.open(realPath);
if (infile.fail()) {
std::cout << "File "
<< "open fail" << std::endl;
LOGE("ParseClickCompleteTrace open file(%s) fialed ", fileNamePath.c_str());
return 0;
}

View File

@ -34,8 +34,6 @@ double ParseClickResponseTrace::ParseResponseTrace(std::string fileNamePath)
}
infile.open(realPath);
if (infile.fail()) {
std::cout << "File "
<< "open fail" << std::endl;
LOGE("ParseClickResponseTrace open file(%s) fialed ", fileNamePath.c_str());
return 0;
}

View File

@ -1,113 +0,0 @@
/*
* Copyright (C) 2021 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 <fstream>
#include <string>
#include "include/parse_page_fps_trace.h"
#include "include/sp_log.h"
namespace OHOS {
namespace SmartPerf {
double ParsePageFpsTrace::PageFpsTrace(std::string file)
{
double fps = -1.0;
char realPath[PATH_MAX] = {0x00};
if ((realpath(file.c_str(), realPath) == nullptr)) {
std::cout << "" << std::endl;
}
infile.open(realPath);
if (infile.fail()) {
std::cout << "file open fail:" << file << std::endl;
LOGE("ParsePageFpsTrace open file(%s) fialed ", file.c_str());
return fps;
}
fps = SmartPerf::ParsePageFpsTrace::CalculateTime();
infile.close();
return fps;
}
double ParsePageFpsTrace::CalculateTime()
{
std::string line;
size_t offset = 2;
double minFrameInterval = 0.05;
while (getline(infile, line)) {
if (line.find("H:touchEventDispatch") != std::string::npos) {
startLine = line;
needUpdateResponseLine = true;
frameNum = 0;
} else if (line.find("H:RSMainThread::DoComposition") != std::string::npos) {
updateCount = true;
count = 0;
pid = SmartPerf::ParsePageFpsTrace::CutString(line, "B|", "|H:RSMainThread::DoComposition", offset);
frameNum++;
if (needUpdateResponseLine) {
responseLine = line;
needUpdateResponseLine = false;
}
frameStartTime = std::stod(SmartPerf::ParsePageFpsTrace::GetLineTime(line));
}
if (updateCount) {
if (line.find("B|" + pid + "|") != std::string::npos && line.find("-" + pid) != std::string::npos) {
count++;
} else if (line.find("E|" + pid + "|") != std::string::npos && line.find("-" + pid) != std::string::npos) {
count--;
}
if (count == 0) {
completeLine = line;
frameStartInterval = frameEndTime;
frameEndTime = std::stod(SmartPerf::ParsePageFpsTrace::GetLineTime(completeLine));
updateCount = false;
}
}
if (frameStartInterval != 0) {
double frameInterval = frameStartTime - frameStartInterval;
if (frameInterval > minFrameInterval) {
std::cout << "NO." << frameNum << "fps Time: " << frameInterval << "s" << std::endl;
}
}
}
return CalculateTimeEnd();
}
double ParsePageFpsTrace::CalculateTimeEnd()
{
if (startLine.compare("") == 0) {
LOGW("can not find start point {H:touchEventDispatch}");
} else if (completeLine.compare("") == 0) {
LOGW("can not find response and complete point {H:RSMainThread::DoComposition}");
} else {
double responseTime = std::stod(SmartPerf::ParsePageFpsTrace::GetLineTime(responseLine));
double completeTime = std::stod(SmartPerf::ParsePageFpsTrace::GetLineTime(completeLine));
return frameNum / (completeTime - responseTime);
}
return -1.0;
}
std::string ParsePageFpsTrace::GetLineTime(std::string line)
{
size_t num = 7;
size_t position1 = line.find("....");
size_t position2 = line.find(":");
return line.substr(position1 + num, position2 - position1 - num);
}
std::string ParsePageFpsTrace::CutString(std::string line, const std::string &start,
const std::string &end, size_t offset)
{
size_t position1 = line.find(start);
size_t position2 = line.find(end);
return line.substr(position1 + offset, position2 - position1 - offset);
}
}
}

View File

@ -148,7 +148,7 @@ std::string ParseRadar::ParseRadarFrame(const std::string &string) const
}
std::string ParseRadar::ExtractString(const std::string &str, const std::string &target) const
{
LOGI("Radar.str====: %s", str.c_str());
LOGI("Radar.str: %s", str.c_str());
size_t pos = str.find(target);
if (pos != std::string::npos) {
pos += target.length();

View File

@ -30,7 +30,6 @@ double ParseSlideFpsTrace::ParseSlideFpsTraceNoh(std::string file)
}
infile.open(realPath);
if (infile.fail()) {
std::cout << "file open fail:" << file << std::endl;
LOGE("ParseSlideFpsTrace open file(%s) fialed ", file.c_str());
return fps;
}

View File

@ -1,161 +0,0 @@
/*
* Copyright (C) 2021 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 <thread>
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <cstdio>
#include <sstream>
#include <iomanip>
#include "include/parse_start_frame_trace.h"
#include "include/sp_utils.h"
#include "include/sp_log.h"
namespace OHOS {
namespace SmartPerf {
const unsigned int SFTN_UI_INDEX_2 = 2;
const unsigned int SFTN_UI_INDEX_3 = 3;
double StartFrameTraceNoh::ParseStartFrameTraceNoh(std::string file)
{
double frameRate = -1.0;
char realPath[PATH_MAX] = {0x00};
if ((realpath(file.c_str(), realPath) == nullptr)) {
std::cout << "" << std::endl;
}
infile.open(realPath);
if (infile.fail()) {
std::cout << "file open fail:" << file << std::endl;
LOGE("ParseStartFrameTraceNoh open file(%s) failed ", file.c_str());
return frameRate;
}
frameRate = SmartPerf::StartFrameTraceNoh::CalculateTime();
infile.close();
return frameRate;
}
double StartFrameTraceNoh::CalculateTime()
{
std::string line;
std::string screenStr = SPUtils::GetScreen();
size_t pos = screenStr.find("x");
std::string width = screenStr.substr(twelve, pos - twelve);
std::string height = screenStr.substr(pos + 1, four);
while (getline(infile, line)) {
if (line.find("H:touchEventDispatch") != std::string::npos) {
startLine = line;
frameNum = 0;
} else if (line.find("H:RSUniRender::Process:[WindowScene") != std::string::npos) {
std::string tmpStr = Split(line, "H:RSUniRender::Process:[WindowScene")[1];
std::string numsStr = CutString(tmpStr, "(", ")", 1);
std::vector<std::string> nums = Split(numsStr, ",");
std::string alpha = Split(tmpStr, "Alpha:")[1];
if ((stof(nums[0]) == 0 && stof(nums[1]) == 0 && stof(nums[SFTN_UI_INDEX_2]) == stof(width) &&
stof(nums[SFTN_UI_INDEX_3]) == stof(height)) &&
stof(alpha) == 1) {
fullScreenLine = line;
break;
}
} else if (line.find("H:RSMainThread::DoComposition") != std::string::npos) {
isNeedEnd = true;
frameNum++;
count = 0;
int size = 2;
pid = CutString(line, "B|", "|H:RSMainThread::DoComposition", size);
frameStartTime = std::stod(GetLineTime(line));
startTimes.frameId = frameNum;
startTimes.times = frameStartTime;
startTimeArr.push_back(startTimes);
}
if (isNeedEnd) {
if (line.find("B|" + pid + "|") != std::string::npos && line.find("-" + pid) != std::string::npos) {
count++;
} else if (line.find("E|" + pid + "|") != maxnpos && line.find("-" + pid) != maxnpos) {
count--;
}
if (count == 0) {
frameEndTime = std::stod(GetLineTime(line));
endTimes.frameId = frameNum;
endTimes.times = frameEndTime;
endTimeArr.push_back(endTimes);
isNeedEnd = false;
}
}
}
double fps = GetFps();
return fps;
}
double StartFrameTraceNoh::GetFps()
{
if (startLine.compare("") == 0) {
std::cout << "can not find start point {H:touchEventDispatch}" << std::endl;
LOGE("can not find start point {H:touchEventDispatch}");
} else if (fullScreenLine.compare("") == 0) {
std::cout << "can not find complete point {H:RSMainThread::WindowScene}" << std::endl;
LOGE("can not find complete point {H:RSMainThread::WindowScene}");
} else {
double startTime = std::stod(SmartPerf::StartFrameTraceNoh::GetLineTime(startLine));
double endTime = std::stod(SmartPerf::StartFrameTraceNoh::GetLineTime(fullScreenLine));
for (size_t i = 0; i + 1 < startTimeArr.size(); ++i) {
double result = 0;
if (startTimeArr[i].times >= startTime && endTimeArr[i].times > startTimeArr[i].times) {
size_t next = i + 1;
result = startTimeArr[next].times - endTimeArr[i].times;
}
double mark = 0.05;
if (result > mark) {
std::cout << "NO." << startTimeArr[i].frameId << "fps Time: " << result << "s" << std::endl;
}
}
return frameNum / (endTime - startTime);
}
return -1.0;
}
std::string StartFrameTraceNoh::GetLineTime(std::string line)
{
size_t num = 7;
size_t position1 = line.find("....");
size_t position2 = line.find(":");
return line.substr(position1 + num, position2 - position1 - num);
}
std::string StartFrameTraceNoh::CutString(std::string line, const std::string &start,
const std::string &end, size_t offset)
{
int position1 = static_cast<int>(line.find(start));
int position2 = static_cast<int>(line.find(end));
return line.substr(position1 + offset, position2 - position1 - static_cast<int>(offset));
}
std::vector<std::string> StartFrameTraceNoh::Split(std::string str, const std::string &pattern)
{
std::vector<std::string> result;
if (str.empty() || pattern.empty() || str.size() < pattern.size()) {
return result;
}
size_t start = 0; // start index
while (start < str.size()) {
size_t pos = str.find(pattern, start);
if (pos != std::string::npos) {
result.push_back(str.substr(start, pos - start));
start = pos + pattern.size(); // next start index
} else {
//the last start
result.push_back(str.substr(start));
break;
}
}
return result;
}
}
}

View File

@ -1,267 +0,0 @@
/*
* Copyright (C) 2021 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 <thread>
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <cstdio>
#include <sstream>
#include <iomanip>
#include "include/parse_trace.h"
#include "include/sp_log.h"
namespace OHOS {
namespace SmartPerf {
double ParseTrace::ParseTraceNoh(const std::string &fileNamePath, const std::string &appPid)
{
int conversion = 1000;
double code = -1;
char realPath[PATH_MAX] = {0x00};
if ((realpath(fileNamePath.c_str(), realPath) == nullptr)) {
std::cout << "" << std::endl;
}
infile.open(realPath);
if (infile.fail()) {
std::cout << "File "
<< "open fail" << std::endl;
LOGE("ParseTrace open file(%s) failed ", fileNamePath.c_str());
return code;
}
code = SmartPerf::ParseTrace::ParseNohTrace(fileNamePath, appPid);
infile.close();
return code * conversion;
}
double ParseTrace::ParseNohTrace(const std::string &fileNamePath, const std::string &appPid)
{
std::string line;
std::string::size_type positionPid;
double codeTime = -1;
while (getline(infile, line)) {
startTime = SmartPerf::ParseTrace::GetStartTime(line, startTime);
frameId = SmartPerf::ParseTrace::GetFrameId(line, appPid, frameId);
positionPid = line.find("[" + appPid + "," + frameId + "]");
if (positionPid != std::string::npos) {
size_t position1 = line.find("....");
size_t position2 = line.find(":");
size_t flagTimeSize = 5;
flagTime = line.substr(position1 + flagTimeSize, position2 - position1 - flagTimeSize);
if (std::stof(endTime) == 0) {
endTime = flagTime;
continue;
}
float dataThreshold = 0.3;
if ((std::stof(flagTime) - std::stof(endTime)) > dataThreshold) {
break;
} else {
endTime = flagTime;
}
}
}
codeTime = SmartPerf::ParseTrace::GetTime(startTime, endTime);
return codeTime;
}
std::string ParseTrace::GetFrameId(std::string line, const std::string &appPid, const std::string &fid)
{
std::string::size_type positionTransactionFlag = line.find("transactionFlag:[" + appPid);
if (positionTransactionFlag != std::string::npos) {
size_t positionFrame1 = line.rfind("[" + appPid + ",");
size_t positionFrame2 = line.rfind("]");
size_t subNum = 2;
size_t off = positionFrame1 + subNum + appPid.length();
size_t count = positionFrame2 - positionFrame1 - subNum - appPid.length();
frameId = line.substr(off, count);
} else {
frameId = fid;
}
return frameId;
}
std::string ParseTrace::GetWindowTime(std::string line, const std::string &wt)
{
size_t positionWindow = line.find("H:RSUniRender::Process:[leashWindow");
if (positionWindow != std::string::npos) {
size_t positionWindow1 = line.rfind(")");
size_t subNumSize = 4;
std::string windowSizeFlag = line.substr(positionWindow1 - subNumSize, subNumSize);
std::string windowSize = "";
if (std::stof(windowSize) == 0) {
const int windowSizeNum = 1344;
if (std::stof(windowSizeFlag) == windowSizeNum) {
windowSize = "";
} else {
windowSize = windowSizeFlag;
}
} else {
if (std::stof(windowSize) != std::stof(windowSizeFlag)) {
size_t subNum = 5;
size_t position1 = line.find("....");
size_t position2 = line.find(":");
windowTime = line.substr(position1 + subNum, position2 - position1 - subNum);
windowSize = windowSizeFlag;
} else {
windowTime = wt;
}
}
}
return windowTime;
}
double ParseTrace::ParseTraceCold(const std::string &fileNamePath, const std::string &appPid)
{
int conversion = 1000;
double code = -1;
char realPath[PATH_MAX] = {0x00};
if ((realpath(fileNamePath.c_str(), realPath) == nullptr)) {
std::cout << "" << std::endl;
}
infile.open(realPath);
if (infile.fail()) {
std::cout << "File "
<< "open fail" << std::endl;
LOGE("ParseTrace::ParseTraceCold open file(%s) failed ", fileNamePath.c_str());
return 0;
}
code = SmartPerf::ParseTrace::ParseCodeTrace(fileNamePath, appPid);
infile.close();
LOGI("ParseTrace::ParseTraceCold OK");
return code * conversion;
}
double ParseTrace::ParseTraceHot(const std::string &fileNamePath)
{
int conversion = 1000;
double code = -1;
char realPath[PATH_MAX] = {0x00};
if ((realpath(fileNamePath.c_str(), realPath) == nullptr)) {
std::cout << "" << std::endl;
}
infile.open(realPath);
if (infile.fail()) {
std::cout << "File "
<< "open fail" << std::endl;
LOGE("ParseTrace::ParseTraceHot open file(%s) failed ", fileNamePath.c_str());
return 0;
}
code = SmartPerf::ParseTrace::ParseHotTrace(fileNamePath);
infile.close();
LOGI("ParseTrace::ParseTraceHot OK");
return code * conversion;
}
double ParseTrace::ParseCodeTrace(const std::string &fileNamePath, const std::string &appPid)
{
std::string line;
std::string::size_type tracingMarkWrite;
std::string::size_type fourPoint;
double codeTime = -1;
while (getline(infile, line)) {
startTime = SmartPerf::ParseTrace::GetStartTime(line, startTime);
tracingMarkWrite = line.find("tracing_mark_write: B|" + appPid + "|H:RSRenderThread DrawFrame:");
fourPoint = line.find("....");
if (tracingMarkWrite != std::string::npos && fourPoint != std::string::npos) {
size_t p1 = line.find("....");
size_t p2 = line.find(":");
size_t subNum = 5;
endTime = line.substr(p1 + subNum, p2 - p1 - subNum);
int endNum = std::stof(endTime);
int endFlagNum = std::stof(endTimeFlag);
int startNum = std::stof(startTime);
int timeNum = endNum - endFlagNum;
double interval = 0.3;
if (timeNum < interval) {
endTimeFlag = endTime;
continue;
}
if (std::stof(endTimeFlag) == 0) {
endTimeFlag = endTime;
} else if (endFlagNum != 0 && startNum != 0 && timeNum > interval) {
break;
} else {
endTimeFlag = endTime;
}
}
}
codeTime = SmartPerf::ParseTrace::GetTime(startTime, endTime);
return codeTime;
}
double ParseTrace::ParseHotTrace(const std::string &fileNamePath)
{
std::string line;
std::string::size_type doComposition;
double codeTime = -1;
while (getline(infile, line)) {
startTime = SmartPerf::ParseTrace::GetStartTime(line, startTime);
doComposition = line.find("H:RSMainThread::DoComposition");
if (doComposition != std::string::npos) {
size_t position1 = line.find("....");
size_t position2 = line.find(":");
int subNum = 5;
endTime = line.substr(position1 + subNum, position2 - position1 - subNum);
int endNum = std::stof(endTime);
int endFlagNum = std::stof(endTimeFlag);
int startNum = std::stof(startTime);
int timeNum = endNum - endFlagNum;
double interval = 0.3;
if (timeNum < interval) {
endTimeFlag = endTime;
continue;
}
if (std::stof(endTimeFlag) == 0) {
endTimeFlag = endTime;
} else if (endFlagNum != 0 && startNum != 0 && timeNum > interval) {
break;
} else {
endTimeFlag = endTime;
}
}
}
codeTime = SmartPerf::ParseTrace::GetTime(startTime, endTime);
return codeTime;
}
double ParseTrace::GetTime(std::string start, std::string end)
{
double codeTime = -1;
if (std::stof(end) == 0 || std::stof(start) == 0) {
return codeTime;
} else {
double displayTime = 0.040;
codeTime = std::stof(end) - std::stof(start) + displayTime;
}
return codeTime;
}
std::string ParseTrace::GetStartTime(std::string line, const std::string &startTimeBefore)
{
std::string::size_type te = line.find("H:touchEventDispatch");
std::string::size_type td = line.find("H:TouchEventDispatch");
std::string::size_type pd = line.find("H:PointerEventDispatch");
std::string::size_type kd = line.find("H:KeyEventDispatch");
std::string::size_type nop = std::string::npos;
if (te != nop || td != nop || pd != nop || kd != nop) {
size_t touchNum = 3;
if (flagTouch <= touchNum) {
size_t position1 = line.find("....");
size_t position2 = line.find(":");
size_t subNum = 5;
startTime = line.substr(position1 + subNum, position2 - position1 - subNum);
flagTime = "0";
flagTouch++;
} else {
startTime = startTimeBefore;
}
} else {
startTime = startTimeBefore;
}
return startTime;
}
}
}

View File

@ -55,8 +55,8 @@ std::map<std::string, std::string> ProfilerFPS::ItemData()
finalResult.fps = fullFrame;
}
result["fps"] = std::to_string(finalResult.fps);
LOGI("ProfilerFPS.result.fps====: %s", std::to_string(finalResult.fps).c_str());
LOGI("ProfilerFPS.result.curTime====: %s", std::to_string(finalResult.curTime).c_str());
LOGI("ProfilerFPS.result.fps: %s", std::to_string(finalResult.fps).c_str());
LOGI("ProfilerFPS.result.curTime: %s", std::to_string(finalResult.curTime).c_str());
std::string jitterStr = "";
std::string split = "";
for (size_t i = 0; i < finalResult.jitters.size(); i++) {
@ -66,7 +66,7 @@ std::map<std::string, std::string> ProfilerFPS::ItemData()
jitterStr += split + std::to_string(finalResult.jitters[i]);
}
result["fpsJitters"] = jitterStr;
LOGI("ProfilerFPS.result.jitters====: %s", jitterStr.c_str());
LOGI("ProfilerFPS.result.jitters: %s", jitterStr.c_str());
if (isCatchTrace > 0) {
ByTrace::GetInstance().CheckFpsJitters(finalResult.jitters, finalResult.fps);
}
@ -125,25 +125,11 @@ void ProfilerFPS::GetResultFPS(int sectionsNum)
fflush(stdout);
gettimeofday(&end, nullptr);
runTime = end.tv_sec * 1e6 - start.tv_sec * 1e6 + end.tv_usec - start.tv_usec;
LOGI("printf time is---runTime: %s", std::to_string(runTime).c_str());
LOGI("printf time is runTime: %s", std::to_string(runTime).c_str());
if (runTime < sleepTime) {
usleep(sleepTime - runTime);
}
GetCurrentTime(ten);
}
void ProfilerFPS::GetCurrentTime(int sleepNum)
{
for (int i = 0; i < sleepNum; i++) {
struct timespec time1 = { 0 };
clock_gettime(CLOCK_MONOTONIC, &time1);
int curTimeNow = static_cast<int>(time1.tv_sec - 1);
if (curTimeNow == lastFpsInfoResult.curTime) {
usleep(sleepNowTime);
} else {
break;
}
}
OHOS::SmartPerf::SPUtils::GetCurrentTime(ten, lastFpsInfoResult.curTime);
}
void ProfilerFPS::GetTimeDiff()
@ -223,7 +209,6 @@ void ProfilerFPS::GetSectionsFps(FpsInfoProfiler &fpsInfoResult, int nums) const
long long currLastTime = lastCurrTime;
long long harTime = msJiange / 1000000;
int printCount = 0;
size_t count = 0;
long long currTimeStart = 0;
long long currTimeLast = 0;
for (size_t i = 0; i < fpsInfoResult.currTimeStamps.size(); i++) {
@ -234,24 +219,16 @@ void ProfilerFPS::GetSectionsFps(FpsInfoProfiler &fpsInfoResult, int nums) const
}
currTimeLast = currTime;
msCount++;
} else if (currTime > msStartTime && currTime <= (msStartTime + msJiange)) {
PrintSections(msCount, currTimeLast, currTimeStart, currLastTime);
msCount = 1;
if (msCount == 1) {
} else {
while (currTime > msStartTime) {
PrintSections(msCount, currTimeLast, currTimeStart, currLastTime);
printCount++;
msCount = 1;
msStartTime += msJiange;
currLastTime += harTime;
currTimeLast = currTime;
currTimeStart = currTime;
}
currTimeLast = currTime;
msStartTime += msJiange;
currLastTime += harTime;
printCount++;
} else {
PrintSections(msCount, currTimeLast, currTimeStart, currLastTime);
printCount++;
msCount = 0;
msStartTime += msJiange;
currLastTime += harTime;
currTimeLast = currTime;
count--;
}
if (i == (static_cast<size_t>(fpsInfoResult.currTimeStamps.size()) - 1)) {
PrintSections(msCount, currTimeLast, currTimeStart, currLastTime);
@ -259,7 +236,6 @@ void ProfilerFPS::GetSectionsFps(FpsInfoProfiler &fpsInfoResult, int nums) const
printCount++;
GetSectionsPrint(printCount, currLastTime, nums, harTime);
}
count++;
}
}
@ -274,7 +250,7 @@ void ProfilerFPS::GetFPS(std::vector<std::string> v)
}
printf("set num:%d success\n", this->num);
int sectionsNum;
if (static_cast<int>(v.size()) < four) {
if (static_cast<int>(v.size()) < four || static_cast<int>(v.size()) > ten) {
sectionsNum = 0;
} else {
sectionsNum = atoi(v[four].c_str());
@ -293,8 +269,8 @@ std::string ProfilerFPS::GetSurface()
SPUtils::LoadCmd(dumperSurface, cmdResult);
size_t positionLeft = cmdResult.find("[");
size_t positionRight = cmdResult.find("]");
size_t num = 1;
return cmdResult.substr(positionLeft + num, positionRight - positionLeft - num);
size_t positionNum = 1;
return cmdResult.substr(positionLeft + positionNum, positionRight - positionLeft - positionNum);
}
FpsInfoProfiler ProfilerFPS::GetFpsInfo()
@ -306,16 +282,16 @@ FpsInfoProfiler ProfilerFPS::GetFpsInfo()
uniteLayer = GetSurface();
}
if (pkgName.empty() || pkgName.find("sceneboard") != std::string::npos) {
LOGI("ProfilerFPS.pkgName====: %s", pkgName.c_str());
GetCurrentTime(fifty);
LOGI("ProfilerFPS.pkgName: %s", pkgName.c_str());
OHOS::SmartPerf::SPUtils::GetCurrentTime(fifty, lastFpsInfoResult.curTime);
fpsInfoMax = GetSurfaceFrame(uniteLayer);
} else {
bool onTop = IsForeGround();
bool onTop = OHOS::SmartPerf::SPUtils::IsForeGround(pkgName);
if (onTop) {
LOGI("ProfilerFPS.onTop===========");
GetCurrentTime(fifty);
OHOS::SmartPerf::SPUtils::GetCurrentTime(fifty, lastFpsInfoResult.curTime);
fpsInfoMax = GetSurfaceFrame(uniteLayer);
} else {
LOGI("ProfilerFPS::app is in the background");
if (processId.empty()) {
processFlag = true;
fpsInfoMax.Clear();
@ -356,7 +332,7 @@ FpsInfoProfiler ProfilerFPS::GetSurfaceFrame(std::string name)
clock_gettime(CLOCK_MONOTONIC, &time1);
fpsInfo.curTime = static_cast<int>(time1.tv_sec - 1);
fpsInfo.currTimeDump = (time1.tv_sec - 1) * mod + time1.tv_nsec;
LOGI("ProfilerFPS Time-------fpsInfo.curTime: %s", std::to_string(fpsInfo.curTime).c_str());
LOGI("ProfilerFPS fpsInfo.curTime: %d", fpsInfo.curTime);
while (fgets(tmp, sizeof(tmp), fp) != nullptr) {
std::string str(tmp);
LOGD("ProfilerFPS dump time: %s", str.c_str());
@ -370,7 +346,7 @@ FpsInfoProfiler ProfilerFPS::GetSurfaceFrame(std::string name)
CalcFpsAndJitters();
}
pclose(fp);
LOGI("ProfilerFPS Time-------fpsNum: %s", std::to_string(fpsNum).c_str());
LOGI("ProfilerFPS fpsNum: %d", fpsNum);
return fpsInfo;
}
@ -402,46 +378,6 @@ void ProfilerFPS::CalcFpsAndJitters()
}
}
bool ProfilerFPS::IsForeGround()
{
const std::string cmd = "aa dump -l";
char buf[1024] = {'\0'};
std::string appLine = "app name [" + pkgName;
std::string bundleLine = "bundle name [" + pkgName;
FILE *fd = popen(cmd.c_str(), "r");
if (fd == nullptr) {
return false;
}
bool tag = false;
while (fgets(buf, sizeof(buf), fd) != nullptr) {
std::string line = buf;
if (line.find(appLine) != std::string::npos) {
isFoundAppName = true;
}
if (line.find(bundleLine) != std::string::npos) {
isFoundBundleName = true;
}
if (isFoundAppName || isFoundBundleName) {
if (line.find("app state") != std::string::npos) {
tag = IsFindForeGround(line);
isFoundAppName = false;
isFoundBundleName = false;
}
}
}
pclose(fd);
return tag;
}
bool ProfilerFPS::IsFindForeGround(std::string line) const
{
std::string foreGroundTag = line.substr(line.find("#") + 1);
if (foreGroundTag.find("FOREGROUND") != std::string::npos) {
return true;
} else {
return false;
}
}
void ProfilerFPS::GetOhFps(std::vector<std::string> v)
{
if (v[number] == "") {
@ -473,7 +409,7 @@ void ProfilerFPS::SetGameLayer(std::string isGameView)
FpsInfoProfiler ProfilerFPS::selfRerderLayers(const std::string &gameLayer)
{
GetCurrentTime(fifty);
OHOS::SmartPerf::SPUtils::GetCurrentTime(fifty, lastFpsInfoResult.curTime);
fpsInfoMax = GetSurfaceFrame(gameLayer);
return fpsInfoMax;
}

View File

@ -268,7 +268,6 @@ void SmartPerfCommand::InitSomething()
std::string cmdResult;
std::string stat = CMD_COMMAND_MAP.at(CmdCommand::PROC_STAT);
if (SPUtils::LoadCmd(stat, cmdResult)) {
printf("Privilege escalation! \n");
LOGI("SmartPerfCommand::InitSomething Privilege escalation!");
};
}

View File

@ -39,14 +39,12 @@ int SpServerSocket::Init(ProtoType type)
sockPort = (type == ProtoType::UDP ? udpPort : udpExPort);
}
if (sock < 0) {
std::cout << "Socket Create Failed:" << sock << std::endl;
LOGE("SpServerSocket::Init Socket Create Failed");
return -1;
}
if (type == ProtoType::TCP) {
int optval = 1;
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval)) < 0) {
std::cout << "Socket Setsockopt failed: " << sock << std::endl;
LOGE("SpServerSocket::Init Socket Setsockopt failed prot(%d)", sockPort);
return -1;
}
@ -55,13 +53,11 @@ int SpServerSocket::Init(ProtoType type)
local.sin_port = htons(sockPort);
local.sin_addr.s_addr = inet_addr("127.0.0.1");
if (::bind(sock, reinterpret_cast<struct sockaddr *>(&local), sizeof(local)) < 0) {
std::cout << "Socket Bind failed:" << sock << std::endl;
LOGE("SpServerSocket::Init Socket Bind failed prot(%d)", sockPort);
return -1;
}
if (type == ProtoType::TCP) {
if (listen(sock, listenCount) < 0) {
std::cout << "Socket Listen failed:" << sock << std::endl;
LOGE("SpServerSocket::Init Socket Listen failed");
return -1;
}
@ -88,7 +84,6 @@ int SpServerSocket::Send(const std::string &sendBuf) const
{
int sendBytes = send(connFd, sendBuf.c_str(), sendBuf.size(), 0);
if (sendBytes < 0) {
std::cout << "Send:Error" << std::endl;
LOGE("SpServerSocket::Send Error(%d) fd(%d)", sendBytes, connFd);
return -1;
}
@ -103,7 +98,6 @@ void SpServerSocket::Close()
local.sin_port = htons(sockPort);
local.sin_addr.s_addr = inet_addr("127.0.0.1");
if (::bind(sock, reinterpret_cast<struct sockaddr *>(&local), sizeof(local)) < 0) {
std::cout << "Socket Bind failed:" << sock << std::endl;
LOGI("SpServerSocket::Init Socket Bind failed");
}
}
@ -127,7 +121,6 @@ int SpServerSocket::Recv()
std::cout << "Client:" << rbuf << std::endl;
} else {
LOGE("SpServerSocket::recv Error(%d) fd(%d)", l, connFd);
perror("recv error:");
return -1;
}
return l;

View File

@ -128,7 +128,6 @@ ErrCode SPTask::InitTask(const std::string &recvStr)
std::string errInfo = EXCEPTION_MSG_MAP.at(exMsg);
LOGI("SPTask::InitTask error(%s)", errInfo.c_str());
std::cout << "ExceptionMsg:" << errInfo << std::endl;
return ErrCode::FAILED;
}

View File

@ -627,5 +627,60 @@ std::string SPUtils::GetCpuNum()
}
return cpuCores;
}
void SPUtils::GetCurrentTime(int num, int prevTime)
{
unsigned long sleepNowTime = 10000;
for (int i = 0; i < num; i++) {
struct timespec time1 = { 0 };
clock_gettime(CLOCK_MONOTONIC, &time1);
int curTimeNow = static_cast<int>(time1.tv_sec - 1);
if (curTimeNow == prevTime) {
usleep(sleepNowTime);
} else {
break;
}
}
}
bool SPUtils::IsForeGround(std::string &pkg)
{
bool isFoundAppName = false;
bool isFoundBundleName = false;
const std::string cmd = "aa dump -l";
char buf[1024] = {'\0'};
std::string appLine = "app name [" + pkg;
std::string bundleLine = "bundle name [" + pkg;
FILE *fd = popen(cmd.c_str(), "r");
if (fd == nullptr) {
return false;
}
bool tag = false;
while (fgets(buf, sizeof(buf), fd) != nullptr) {
std::string line = buf;
if (line.find(appLine) != std::string::npos) {
isFoundAppName = true;
}
if (line.find(bundleLine) != std::string::npos) {
isFoundBundleName = true;
}
if (isFoundAppName || isFoundBundleName) {
if (line.find("app state") != std::string::npos) {
tag = IsFindForeGround(line);
isFoundAppName = false;
isFoundBundleName = false;
}
}
}
pclose(fd);
return tag;
}
bool SPUtils::IsFindForeGround(std::string line)
{
std::string foreGroundTag = line.substr(line.find("#") + 1);
if (foreGroundTag.find("FOREGROUND") != std::string::npos) {
return true;
} else {
return false;
}
}
}
}

View File

@ -31,7 +31,6 @@ double StallingRateTrace::StallingRateResult(std::string file)
}
infile.open(realPath);
if (infile.fail()) {
std::cout << "file open fail:" << file << std::endl;
LOGI("StallingRateTrace open file(%s) fialed ", file.c_str());
return stalligRate;
}

View File

@ -45,35 +45,6 @@ void StartUpDelay::GetTrace(const std::string &sessionID, const std::string &tra
SPUtils::LoadCmd(cmdString + traceName, result);
}
std::thread StartUpDelay::ThreadGetTrace(const std::string &sessionID, const std::string &traceName) const
{
auto thGetTrace = std::thread([this, sessionID, traceName]() { this->GetTrace(sessionID, traceName); });
return thGetTrace;
}
void StartUpDelay::GetLayout()
{
std::string result;
std::string uitest = CMD_COMMAND_MAP.at(CmdCommand::UITEST_DUMPLAYOUT);
SPUtils::LoadCmd(uitest, result);
}
std::thread StartUpDelay::ThreadGetLayout()
{
auto thGetLayout = std::thread([this]() { this->GetLayout(); });
return thGetLayout;
}
void StartUpDelay::InputEvent(const std::string &point)
{
std::string cmdResult = "";
int time = 4;
sleep(time);
std::string cmd = CMD_COMMAND_MAP.at(CmdCommand::UINPUT_POINT) + point + " -u" + point;
SPUtils::LoadCmd(cmd, cmdResult);
}
std::thread StartUpDelay::ThreadInputEvent(const std::string &point)
{
auto thInputEvent = std::thread([this, point]() { this->InputEvent(point); });
return thInputEvent;
}
void StartUpDelay::GetHisysId() const
{
int time = 10;
@ -198,25 +169,6 @@ void StartUpDelay::ClearOldServer()
}
}
std::thread StartUpDelay::ThreadGetHisysIds() const
{
auto thGetHisysIds = std::thread([this]() { this->GetHisysIdAndKill(); });
return thGetHisysIds;
}
std::thread StartUpDelay::ThreadGetHisysId() const
{
auto thGetHisysId = std::thread([this]() { this->GetHisysId(); });
return thGetHisysId;
}
void StartUpDelay::ChangeToBackground()
{
std::string result;
sleep(1);
std::string uinput = CMD_COMMAND_MAP.at(CmdCommand::UINPUT_BACK);
SPUtils::LoadCmd(uinput, result);
sleep(1);
}
std::string StartUpDelay::GetPidByPkg(const std::string &curPkgName)
{
std::string resultPid = "";
@ -253,98 +205,5 @@ std::string StartUpDelay::GetPidByPkg(const std::string &curPkgName)
}
return resultProcId;
}
void StartUpDelay::InitXY2(const std::string &curAppName, const std::string &fileName, const std::string &appPkgName)
{
char realPath[PATH_MAX] = {0x00};
if ((realpath(fileName.c_str(), realPath) == nullptr)) {
std::cout << "" << std::endl;
}
std::ifstream file(realPath, std::ios::in);
std::string strLine = "";
std::regex pattern("\\d+");
size_t findIndex = std::string::npos;
while (getline(file, strLine)) {
size_t appPkgIndex = strLine.find("AppName_text_" + appPkgName);
size_t appIndex = strLine.find(curAppName);
if (appIndex != std::string::npos) {
findIndex = appIndex;
} else {
findIndex = appPkgIndex;
}
if (findIndex == std::string::npos) {
break;
}
size_t bounds = strLine.rfind("bounds", findIndex);
if (bounds > 0) {
std::string boundStr = strLine.substr(bounds, 30);
std::smatch result;
std::string::const_iterator iterStart = boundStr.begin();
std::string::const_iterator iterEnd = boundStr.end();
std::vector<std::string> pointVector;
while (std::regex_search(iterStart, iterEnd, result, pattern)) {
std::string startX = result[0];
iterStart = result[0].second;
pointVector.push_back(startX);
}
size_t num = 3;
if (pointVector.size() > num) {
int x = (std::atoi(pointVector[2].c_str()) + std::atoi(pointVector[0].c_str())) / 2;
int y = (std::atoi(pointVector[3].c_str()) + std::atoi(pointVector[1].c_str())) / 2;
pointXY = std::to_string(x) + " " + std::to_string(y);
} else {
size_t leftStart = boundStr.find_first_of("[");
size_t leftEnd = boundStr.find_first_of("]");
int pointXYlength = static_cast<int>(leftEnd - leftStart);
pointXY = boundStr.substr(leftStart + 1, pointXYlength - 1);
pointXY = pointXY.replace(pointXY.find(","), 1, " ");
}
break;
}
}
}
void StartUpDelay::InitXY(const std::string &curAppName, const std::string &fileName)
{
char realPath[PATH_MAX] = {0x00};
if ((realpath(fileName.c_str(), realPath) == nullptr)) {
std::cout << "" << std::endl;
}
std::ifstream file(realPath, std::ios::in);
std::string strLine = "";
std::regex pattern("\\d+");
size_t appIndex = -1;
while (getline(file, strLine)) {
appIndex = strLine.find(curAppName);
if (appIndex <= 0) {
break;
}
size_t bounds = strLine.rfind("bounds", appIndex);
if (bounds > 0) {
std::string boundStr = strLine.substr(bounds, 30);
std::smatch result;
std::string::const_iterator iterStart = boundStr.begin();
std::string::const_iterator iterEnd = boundStr.end();
std::vector<std::string> pointVector;
while (std::regex_search(iterStart, iterEnd, result, pattern)) {
std::string startX = result[0];
iterStart = result[0].second;
pointVector.push_back(startX);
}
size_t num = 3;
size_t pointNum = pointVector.size();
if (pointNum > num) {
int x = (std::atoi(pointVector[2].c_str()) + std::atoi(pointVector[0].c_str())) / 2;
int y = (std::atoi(pointVector[3].c_str()) + std::atoi(pointVector[1].c_str())) / 2;
pointXY = std::to_string(x) + " " + std::to_string(y);
} else {
size_t leftStart = boundStr.find_first_of("[");
size_t leftEnd = boundStr.find_first_of("]");
int pointXYlength = static_cast<int>(leftEnd - leftStart);
pointXY = boundStr.substr(leftStart + 1, pointXYlength - 1);
pointXY = pointXY.replace(pointXY.find(","), 1, " ");
}
break;
}
}
}
}
}

View File

@ -37,10 +37,8 @@ ohos_unittest("sp_daemon_ut") {
"../Temperature.cpp",
"../parse_click_complete_trace.cpp",
"../parse_click_response_trace.cpp",
"../parse_page_fps_trace.cpp",
"../parse_radar.cpp",
"../parse_slide_fps_trace.cpp",
"../parse_start_frame_trace.cpp",
"../profiler_fps.cpp",
"../sp_log.cpp",
"../sp_task.cpp",

View File

@ -28,11 +28,9 @@
#include "Capture.h"
#include "Network.h"
#include "profiler_fps.h"
#include "parse_page_fps_trace.h"
#include "parse_click_complete_trace.h"
#include "parse_click_response_trace.h"
#include "parse_slide_fps_trace.h"
#include "parse_start_frame_trace.h"
using namespace testing::ext;
using namespace std;
@ -120,7 +118,6 @@ HWTEST_F(SPdaemonTest, FpsTestCase, TestSize.Level1)
fps.SetFpsCurrentFpsTime(fpsInfoResult);
fps.SetPackageName(packName);
fps.SetLayerName(surfaceViewName);
fps.GetCurrentTime();
fps.CalcFpsAndJitters();
std::string cmd = "SP_daemon -N 1 -PKG ohos.samples.ecg -f";
@ -312,7 +309,6 @@ HWTEST_F(SPdaemonTest, ProfilerFpsTestCase, TestSize.Level1)
{
ProfilerFPS &profiler = ProfilerFPS::GetInstance();
std::string packName = "ohos.samples.ecg";
int sleepNum = 100;
int sectionsNum = 10;
FpsInfoProfiler fpsInfoResult;
int nums = 10;
@ -320,8 +316,7 @@ HWTEST_F(SPdaemonTest, ProfilerFpsTestCase, TestSize.Level1)
long long msStartTime = 0;
int numb = 20;
long long harTime = 0;
profiler.GetCurrentTime(sleepNum);
profiler.GetResultFPS(sectionsNum);
profiler.CalcFpsAndJitters();
profiler.GetSectionsFps(fpsInfoResult, nums);
@ -383,34 +378,6 @@ HWTEST_F(SPdaemonTest, FrameLossTestCase, TestSize.Level1)
EXPECT_EQ(flag, true);
}
HWTEST_F(SPdaemonTest, ParsePageFpsTraceTest, TestSize.Level1)
{
ParsePageFpsTrace parsePageFpsTrace;
double calculateTime = 0.0;
double calculateTimeEnd = 0.0;
std::string line = "";
std::string curString = "";
std::string start = "";
std::string end = "";
size_t offset = 0;
curString = parsePageFpsTrace.CutString(line, start, end, offset);
calculateTime = parsePageFpsTrace.CalculateTime();
calculateTimeEnd = parsePageFpsTrace.CalculateTimeEnd();
std::string cmd = "SP_daemon -editor pagefps ohos.samples.ecg 设置 ohtest";
std::string result = "";
bool flag = false;
auto ret = SPUtils::LoadCmd(cmd, result);
std::string::size_type strOne = result.find("FPS");
if ((strOne != result.npos)) {
flag = true;
}
EXPECT_EQ(ret, true);
EXPECT_EQ(flag, true);
}
HWTEST_F(SPdaemonTest, ParseClickResponseTraceTest, TestSize.Level1)
{
ParseClickResponseTrace parseClickResponseTrace;
@ -437,39 +404,5 @@ HWTEST_F(SPdaemonTest, ParseClickResponseTraceTest, TestSize.Level1)
EXPECT_EQ(ret, true);
EXPECT_EQ(flag, true);
}
HWTEST_F(SPdaemonTest, StartFrameTraceNohTest, TestSize.Level1)
{
StartFrameTraceNoh startFrameTraceNoh;
double parseStartFrameTraceNoh = 0.0;
double calculateTime = 0.0;
double getFps = 0.0;
std::vector<std::string> split;
std::string str = "";
std::string curString = "";
std::string pattern = "";
std::string file = "";
std::string start = "";
std::string end = "";
size_t offset = 0;
curString = startFrameTraceNoh.CutString(str, start, end, offset);
calculateTime = startFrameTraceNoh.CalculateTime();
parseStartFrameTraceNoh = startFrameTraceNoh.ParseStartFrameTraceNoh(file);
getFps = startFrameTraceNoh.GetFps();
split = startFrameTraceNoh.Split(str, pattern);
std::string cmd = "SP_daemon -editor startFrame ohos.samples.ecg 设置 ohtest";
std::string result = "";
bool flag = false;
auto ret = SPUtils::LoadCmd(cmd, result);
std::string::size_type strOne = result.find("FPS");
if ((strOne != result.npos)) {
flag = true;
}
EXPECT_EQ(ret, true);
EXPECT_EQ(flag, true);
}
} // namespace OHOS
} // namespace SmartPerf