From d983d756f114bd93fd7fbf530e52ffaeed735766 Mon Sep 17 00:00:00 2001 From: frank-huangran Date: Thu, 28 Nov 2024 13:34:08 +0800 Subject: [PATCH 01/15] =?UTF-8?q?device=5Ffps=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: frank-huangran --- .../smartperf/client/client_command/Dubai.cpp | 22 +++- .../client/client_command/include/Dubai.h | 1 + .../client_command/include/profiler_fps.h | 6 +- .../client_command/include/sp_thread_socket.h | 12 +-- .../client/client_command/include/sp_utils.h | 4 +- .../client/client_command/profiler_fps.cpp | 102 +++++++++--------- .../client_command/sp_profiler_factory.cpp | 1 - .../client/client_command/sp_utils.cpp | 29 ++--- 8 files changed, 81 insertions(+), 96 deletions(-) diff --git a/host/smartperf/client/client_command/Dubai.cpp b/host/smartperf/client/client_command/Dubai.cpp index d0f0617a5..8feebe373 100644 --- a/host/smartperf/client/client_command/Dubai.cpp +++ b/host/smartperf/client/client_command/Dubai.cpp @@ -36,16 +36,22 @@ void Dubai::DumpDubaiFinish() void Dubai::MoveDubaiDb() { std::string result; - const std::string dubaiXpower = "/data/service/el2/100/xpower"; - const std::string XpowerDb = "/dubai.db"; + const std::string dubaiXpower = "/data/service/el2/100/xpower/dubai.db"; const std::string Database = "/data/app/el2/100/database/"; const std::string PkgEntry = "/entry/rdb"; - const std::string cpDubai = "cp -r " + dubaiXpower + XpowerDb + " " + Database + dubaiPkgName + PkgEntry; - const std::string dubaiPathChmod = "chmod 777 " + Database + dubaiPkgName + PkgEntry + XpowerDb; + const std::string cpDubai = "cp " + dubaiXpower + " " + Database + dubaiPkgName + PkgEntry; + const std::string dubaiPathChmod = "chmod 777 " + Database + dubaiPkgName + PkgEntry + "/dubai.db"; LOGD("cpDubai: (%s), dubaiPathChmod: (%s)", cpDubai.c_str(), dubaiPathChmod.c_str()); + if (!IsFileAccessible(dubaiXpower)) { + sleep(1); + } SPUtils::LoadCmd(cpDubai, result); - SPUtils::LoadCmd(dubaiPathChmod, result); + if (result.empty()) { + LOGE("Dubai::Copy dubai.db failed"); + } else { + SPUtils::LoadCmd(dubaiPathChmod, result); + } } void Dubai::CallBeginAndFinish() @@ -63,5 +69,11 @@ std::string Dubai::CallMoveDubaiDbFinished() dubaiMoveFinish = "get_dubai_db"; return dubaiMoveFinish; } + +bool IsFileAccessible(const std::string &filename) +{ + std::ifstream file(filename); + return file.good(); +} } } diff --git a/host/smartperf/client/client_command/include/Dubai.h b/host/smartperf/client/client_command/include/Dubai.h index 555cae9cb..d7ff59065 100644 --- a/host/smartperf/client/client_command/include/Dubai.h +++ b/host/smartperf/client/client_command/include/Dubai.h @@ -31,6 +31,7 @@ public: static void DumpDubaiFinish(); static void CallBeginAndFinish(); static std::string CallMoveDubaiDbFinished(); + static bool IsFileAccessible(const std::string &filename); static inline std::string dubaiPkgName = " "; static inline bool isDumpDubaiFinish = false; private: diff --git a/host/smartperf/client/client_command/include/profiler_fps.h b/host/smartperf/client/client_command/include/profiler_fps.h index cd3cbe35d..1bbee3e4b 100644 --- a/host/smartperf/client/client_command/include/profiler_fps.h +++ b/host/smartperf/client/client_command/include/profiler_fps.h @@ -66,9 +66,6 @@ public: void GetFPS(std::vector v); void GetResultFPS(int sectionsNum); FpsInfoProfiler GetFpsInfo(); - FpsInfoProfiler selfRerderLayers(const std::string &gameLayer); - bool IsForeGround(); - bool IsFindForeGround(std::string line) const; void CalcFpsAndJitters(); FpsInfoProfiler GetSurfaceFrame(std::string name); FpsInfoProfiler GetFrameInfoFromMap(std::string name); @@ -81,7 +78,6 @@ public: void SetRkFlag(); std::string GetSurface(); FpsInfoProfiler fpsInfo; - FpsInfoProfiler fpsInfoMax; FpsInfoProfiler lastFpsInfoResult; static ProfilerFPS &GetInstance() { @@ -90,6 +86,7 @@ public: } std::map ItemData() override; void SetProcessId(const std::string &pid); + static inline bool isLowCurFps = false; private: ProfilerFPS() {}; ProfilerFPS(const ProfilerFPS &); @@ -102,7 +99,6 @@ private: long long mod = 1e9; long long curScreenTimestamp = 0; long long prevScreenTimestamp = -1; - long long prevlastScreenTimestamp = 0; int fpsNum = 0; bool isFirstResult = false; long oneSec = 1000000; diff --git a/host/smartperf/client/client_command/include/sp_thread_socket.h b/host/smartperf/client/client_command/include/sp_thread_socket.h index ddba73430..3255d4b17 100644 --- a/host/smartperf/client/client_command/include/sp_thread_socket.h +++ b/host/smartperf/client/client_command/include/sp_thread_socket.h @@ -21,6 +21,7 @@ #include "sp_task.h" #include "control_call_cmd.h" #include "startup_delay.h" +#include "profiler_fps.h"" #include "sp_log.h" #include "common.h" #include "heartbeat.h" @@ -335,19 +336,12 @@ public: std::unordered_map::const_iterator iterator) const { std::cout << "iterator->first: " << static_cast(iterator->first) << std::endl; - if (iterator->first == MessageType::GET_LOW_POWER_FPS) { - for (auto iter = data.cbegin(); iter != data.cend(); ++iter) { - if (iter->first != "fpsJitters") { - std::string temp = iter->second + "@@"; - resultFPS += std::string(temp.c_str()); - } - } - } else if (iterator->first == MessageType::GET_CUR_FPS) { + if (iterator->first == MessageType::GET_CUR_FPS) { + ProfilerFPS::isLowCurFps = true; std::string resultfps = "vfps||"; for (auto iter = data.cbegin(); iter != data.cend(); ++iter) { if (iter->first != "fpsJitters") { std::string temp = iter->second + "@@"; - resultFPS += std::string(temp.c_str()); resultfps += std::string(temp.c_str()); } } diff --git a/host/smartperf/client/client_command/include/sp_utils.h b/host/smartperf/client/client_command/include/sp_utils.h index 791b9891b..75b77d2ea 100644 --- a/host/smartperf/client/client_command/include/sp_utils.h +++ b/host/smartperf/client/client_command/include/sp_utils.h @@ -151,8 +151,8 @@ bool IntegerValueVerification(std::set &keys, std::map params; - SPUtils::StrSplit(line, " ", params); - if (params[0].find("CLOCK_REALTIME") != std::string::npos && clockRealTime == 0) { - strRealTime = params[two]; - strRealTime.erase(strRealTime.find('.'), 1); - clockRealTime = SPUtilesTye::StringToSometype(strRealTime); + std::string line(buf); + size_t posRealTime = line.find("CLOCK_REALTIME"); + size_t posMonotonicRaw = line.find("CLOCK_MONOTONIC_RAW"); + if (posRealTime != std::string::npos && clockRealTime == 0) { + auto realTimeStr = line.substr(line.find(' ') + 1); + realTimeStr.erase(realTimeStr.find('.')); + clockRealTime = std::stoll(realTimeStr); currRealTime = clockRealTime; - } else if (params[0].find("CLOCK_MONOTONIC_RAW") != std::string::npos && clockMonotonicRaw == 0) { - strRealTime = params[two]; - strRealTime.erase(strRealTime.find('.'), 1); - clockMonotonicRaw = SPUtilesTye::StringToSometype(strRealTime); + } else if (posMonotonicRaw != std::string::npos && clockMonotonicRaw == 0) { + auto monotonicRawStr = line.substr(line.find(' ') + 1); + monotonicRawStr.erase(monotonicRawStr.find('.')); + clockMonotonicRaw = std::stoll(monotonicRawStr); + } + + if (clockRealTime != 0 && clockMonotonicRaw != 0) { + break; } } if (pclose(fd) == -1) { @@ -271,6 +275,7 @@ std::string ProfilerFPS::GetSurface() FpsInfoProfiler ProfilerFPS::GetFpsInfo() { + FpsInfoProfiler fpsInfoMax; processFlag = false; fpsInfoMax.fps = 0; std::string uniteLayer; @@ -291,7 +296,9 @@ FpsInfoProfiler ProfilerFPS::GetFpsInfo() if (ohFlag) { uniteLayer = GetSurface(); } - if (pkgName.empty() || pkgName.find("sceneboard") != std::string::npos || isGameSurface) { + bool isSceneboardPkg = pkgName.find("sceneboard") != std::string::npos; + bool isGameSurfaceOrSceneboard = isGameSurface || isSceneboardPkg; + if (pkgName.empty() || isGameSurfaceOrSceneboard) { LOGD("ProfilerFPS.pkgName: %s", pkgName.c_str()); OHOS::SmartPerf::SPUtils::GetCurrentTime(fifty, lastFpsInfoResult.curTime); fpsInfoMax = GetSurfaceFrame(uniteLayer); @@ -322,14 +329,9 @@ FpsInfoProfiler ProfilerFPS::GetSurfaceFrame(std::string name) FpsInfoProfiler ProfilerFPS::GetFrameInfoFromMap(std::string name) { - static std::map fpsMap; - if (fpsMap.count(name) == 0) { - FpsInfoProfiler tmp; - tmp.fps = 0; - fpsMap[name] = tmp; - } - fpsInfo = fpsMap[name]; - fpsInfo.fps = 0; + FpsInfoProfiler tmpFps; + tmpFps.fps = 0; + fpsInfo = tmpFps; FILE *fp; static char tmp[1024]; GetTimeDiff(); @@ -351,16 +353,15 @@ FpsInfoProfiler ProfilerFPS::GetFrameInfoFromMap(std::string name) fpsInfo.currTimeDump = (time1.tv_sec - 1) * mod + time1.tv_nsec; LOGD("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()); - curScreenTimestamp = 0; - std::stringstream sstream; - sstream << tmp; - sstream >> curScreenTimestamp; - if (curScreenTimestamp == 0) { + long long NewScreenTimestamp = 0; + if (sscanf(tmp, "%lld", &NewScreenTimestamp) != 1 || NewScreenTimestamp == 0) { continue; } - CalcFpsAndJitters(); + LOGD("ProfilerFPS dump time: %lld", NewScreenTimestamp); + if (curScreenTimestamp != newScreenTimestamp) { + curScreenTimestamp = newScreenTimestamp; + CalcFpsAndJitters(curScreenTimestamp); + } } if (pclose(fp) == -1) { LOGE("Error: Failed to close file"); @@ -372,29 +373,31 @@ FpsInfoProfiler ProfilerFPS::GetFrameInfoFromMap(std::string name) void ProfilerFPS::CalcFpsAndJitters() { - std::string onScreenTime = std::to_string(curScreenTimestamp / mod); - std::string fpsCurTime = std::to_string(fpsInfo.curTime); - if (onScreenTime.find(fpsCurTime) != std::string::npos) { - fpsNum++; - fpsInfo.currTimeStamps.push_back(curScreenTimestamp); - } - fpsInfo.fps = fpsNum; + long long prevlastScreenTimestamp = 0; + long long onScreenTime = curScreenTimestamp / mod; + long long fpsCurTime = fpsInfo.curTime; if (onScreenTime == fpsCurTime) { - long long jitter; - if (prevScreenTimestamp != -1) { - jitter = curScreenTimestamp - prevScreenTimestamp; - fpsInfo.jitters.push_back(jitter); + fpsNum++; + if (isLowCurFps) { + fpsInfo.fps = fpsNum; } else { - if (prevlastScreenTimestamp != 0 && (curScreenTimestamp - prevlastScreenTimestamp) < mod) { - jitter = curScreenTimestamp - prevlastScreenTimestamp; - fpsInfo.jitters.push_back(jitter); + long long jitter; + if (prevScreenTimestamp != -1) { + jitter = curScreenTimestamp - prevScreenTimestamp; } else { - jitter = curScreenTimestamp - curScreenTimestamp / mod * mod; - fpsInfo.jitters.push_back(jitter); + if (prevlastScreenTimestamp != 0 && (curScreenTimestamp - prevlastScreenTimestamp) < mod) { + jitter = curScreenTimestamp - prevlastScreenTimestamp; + } else { + jitter = curScreenTimestamp % mod; + } } + fpsInfo.fps = fpsNum; + fpsInfo.jitters.push_back(jitter); + fpsInfo.currTimeStamps.push_back(curScreenTimestamp); + + prevScreenTimestamp = curScreenTimestamp; + prevlastScreenTimestamp = curScreenTimestamp; } - prevScreenTimestamp = curScreenTimestamp; - prevlastScreenTimestamp = curScreenTimestamp; } } @@ -427,13 +430,6 @@ void ProfilerFPS::SetGameLayer(std::string isGameView) isGameLayer = std::move(isGameView); } -FpsInfoProfiler ProfilerFPS::selfRerderLayers(const std::string &gameLayer) -{ - OHOS::SmartPerf::SPUtils::GetCurrentTime(fifty, lastFpsInfoResult.curTime); - fpsInfoMax = GetSurfaceFrame(gameLayer); - return fpsInfoMax; -} - std::string ProfilerFPS::GetGameLayer() { std::string gameLayer = ""; diff --git a/host/smartperf/client/client_command/sp_profiler_factory.cpp b/host/smartperf/client/client_command/sp_profiler_factory.cpp index dd4ff4ef8..a5ebe6003 100644 --- a/host/smartperf/client/client_command/sp_profiler_factory.cpp +++ b/host/smartperf/client/client_command/sp_profiler_factory.cpp @@ -40,7 +40,6 @@ SpProfiler *SpProfilerFactory::GetProfilerItem(MessageType messageType) profiler = &CPU::GetInstance(); break; case MessageType::GET_FPS_AND_JITTERS: - case MessageType::GET_LOW_POWER_FPS: case MessageType::GET_CUR_FPS: profiler = &ProfilerFPS::GetInstance(); break; diff --git a/host/smartperf/client/client_command/sp_utils.cpp b/host/smartperf/client/client_command/sp_utils.cpp index 3261b9bba..037992277 100644 --- a/host/smartperf/client/client_command/sp_utils.cpp +++ b/host/smartperf/client/client_command/sp_utils.cpp @@ -647,33 +647,25 @@ void SPUtils::GetCurrentTime(int num, int prevTime) } } } -bool SPUtils::IsForeGround(std::string &pkg) +bool SPUtils::IsForeGround(const 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) { + if (!isFoundAppName && strstr(buf, appLine.c_str())) { 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; - } + if (isFoundAppName && strstr(buf, "app state")) { + tag = IsFindForeGround(line); + isFoundAppName = false; + break; } } if (pclose(fd) == -1) { @@ -682,14 +674,9 @@ bool SPUtils::IsForeGround(std::string &pkg) } return tag; } -bool SPUtils::IsFindForeGround(std::string line) +bool SPUtils::IsFindForeGround(const std::string &line) { - std::string foreGroundTag = line.substr(line.find("#") + 1); - if (foreGroundTag.find("FOREGROUND") != std::string::npos) { - return true; - } else { - return false; - } + return line.find("FOREGROUND") != std::string::npos; } bool SPUtils::IsFindAbilist() { -- Gitee From 2a3489975686ead7140ca54b26c9ecfa3cd3f249 Mon Sep 17 00:00:00 2001 From: frank-huangran Date: Thu, 28 Nov 2024 14:04:45 +0800 Subject: [PATCH 02/15] =?UTF-8?q?=E4=BF=AE=E6=94=B9editor=E9=87=87?= =?UTF-8?q?=E9=9B=86=E6=88=AA=E5=9B=BE=E5=A4=9A=E6=9C=80=E5=90=8E=E4=B8=80?= =?UTF-8?q?=E5=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: frank-huangran --- .../client/client_command/Capture.cpp | 4 ++++ .../client/client_command/include/Capture.h | 1 + .../client/client_command/include/sp_task.h | 2 +- .../client_command/include/sp_thread_socket.h | 1 - .../client/client_command/sp_task.cpp | 21 +++++++++++-------- 5 files changed, 18 insertions(+), 11 deletions(-) diff --git a/host/smartperf/client/client_command/Capture.cpp b/host/smartperf/client/client_command/Capture.cpp index 627707b50..461cedb79 100644 --- a/host/smartperf/client/client_command/Capture.cpp +++ b/host/smartperf/client/client_command/Capture.cpp @@ -192,5 +192,9 @@ bool Capture::TakeScreenCap(const std::string &savePath) const (void)fclose(fp); return true; } +void Capture::SetCollectionNum() +{ + callNum = 0; +} } } diff --git a/host/smartperf/client/client_command/include/Capture.h b/host/smartperf/client/client_command/include/Capture.h index f5011dc58..489de434e 100644 --- a/host/smartperf/client/client_command/include/Capture.h +++ b/host/smartperf/client/client_command/include/Capture.h @@ -34,6 +34,7 @@ public: bool TakeScreenCap(const std::string &savePath) const; void SocketMessage(); long long GetCurTimes(); + void SetCollectionNum(); private: Capture() {}; Capture(const Capture &); diff --git a/host/smartperf/client/client_command/include/sp_task.h b/host/smartperf/client/client_command/include/sp_task.h index 7fd2096e7..c3d624d68 100644 --- a/host/smartperf/client/client_command/include/sp_task.h +++ b/host/smartperf/client/client_command/include/sp_task.h @@ -94,7 +94,6 @@ public: ErrCode StartRecord(); ErrCode StopRecord(); bool GetRecordState(); - void SaveScreenShot(); time_t GetRealStartTime() const; void SetTcpToken(std::string token); std::string GetTcpToken(); @@ -131,6 +130,7 @@ private: bool screenshotFlag = false; time_t realTimeStart = 0; std::string tcpToken = ""; + long long nextTime = 0; std::string strOne = R"(hiprofiler_cmd \ -c - \ diff --git a/host/smartperf/client/client_command/include/sp_thread_socket.h b/host/smartperf/client/client_command/include/sp_thread_socket.h index 3255d4b17..1ee32afb6 100644 --- a/host/smartperf/client/client_command/include/sp_thread_socket.h +++ b/host/smartperf/client/client_command/include/sp_thread_socket.h @@ -210,7 +210,6 @@ public: } else { spSocket.Send(std::string("startRecord::") + std::to_string(START_RECORD_FAILED)); } - SPTask::GetInstance().SaveScreenShot(); spSocket.Send("startRecord::True"); } diff --git a/host/smartperf/client/client_command/sp_task.cpp b/host/smartperf/client/client_command/sp_task.cpp index af22e8a1d..955d9bd4a 100644 --- a/host/smartperf/client/client_command/sp_task.cpp +++ b/host/smartperf/client/client_command/sp_task.cpp @@ -363,7 +363,7 @@ void SPTask::AsyncGetDataMap(std::function msgTask) gpuCounter.GetGpuRealtimeData(dataMap); SdkDataRecv::GetInstance().GetSdkDataRealtimeData(dataMap); msgTask(MapToString(dataMap)); - long long nextTime = SPUtils::GetCurTime(); + nextTime = SPUtils::GetCurTime(); long long costTime = nextTime - lastTime; long long pTime = 998; if (costTime < curTaskInfo.freq) { @@ -620,13 +620,23 @@ bool SPTask::GetRecordState() ErrCode SPTask::StartRecord() { startTime = SPUtils::GetCurTime(); + while (startTime > nextTime) { + std::this_thread::sleep_for(std::chrono::milliseconds(1)); + } InitDataFile(); + screenshotFlag = true; recordState = true; return ErrCode::OK; } ErrCode SPTask::StopRecord() { + long long stopRecordTime = SPUtils::GetCurTime(); + while (stopRecordTime > nextTime) { + std::this_thread::sleep_for(std::chrono::milliseconds(1)); + } + screenshotFlag = false; + recordState = false; std::string outGpuCounterDataPath = baseOutPath + "/" + curTaskInfo.sessionId; if (isInit) { @@ -640,17 +650,10 @@ ErrCode SPTask::StopRecord() vmap.clear(); sdkvec.clear(); gpuCounter.GetGpuCounterData().clear(); - - recordState = false; - screenshotFlag = false; + Capture::GetInstance().SetCollectionNum(); return ErrCode::OK; } - -void SPTask::SaveScreenShot() -{ - screenshotFlag = true; -} time_t SPTask::GetRealStartTime() const { return realTimeStart; -- Gitee From 795c0fb6d07eaddfa54a609ef2f88125e6a80291 Mon Sep 17 00:00:00 2001 From: frank-huangran Date: Thu, 28 Nov 2024 14:06:51 +0800 Subject: [PATCH 03/15] =?UTF-8?q?=E4=BF=AE=E6=94=B9editor=E9=87=87?= =?UTF-8?q?=E9=9B=86=E7=AC=AC=E4=B8=80=E7=A7=92=E6=95=B0=E6=8D=AE=E9=94=99?= =?UTF-8?q?=E4=B9=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: frank-huangran --- host/smartperf/client/client_command/sp_task.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/host/smartperf/client/client_command/sp_task.cpp b/host/smartperf/client/client_command/sp_task.cpp index 955d9bd4a..4811dd9de 100644 --- a/host/smartperf/client/client_command/sp_task.cpp +++ b/host/smartperf/client/client_command/sp_task.cpp @@ -439,9 +439,6 @@ void SPTask::StopGetInfo() destMap.insert(cpuInfo.begin(), cpuInfo.end()); destMap.insert(gpuInfo.begin(), gpuInfo.end()); OHOS::SmartPerf::SpCsvUtil::WriteCsvH(destMap); - if (!vmap.empty()) { - vmap.erase(vmap.begin()); - } OHOS::SmartPerf::SpCsvUtil::WriteCsv(outIndexpath, vmap); } void SPTask::StopGpuCounterRecv() -- Gitee From e2f8208bd3014c8813e48c185de6f84e6707f4f2 Mon Sep 17 00:00:00 2001 From: frank-huangran Date: Thu, 28 Nov 2024 14:49:07 +0800 Subject: [PATCH 04/15] =?UTF-8?q?device=5Ffps=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: frank-huangran --- host/smartperf/client/client_command/include/common.h | 4 ---- .../client/client_command/include/sp_thread_socket.h | 7 +------ 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/host/smartperf/client/client_command/include/common.h b/host/smartperf/client/client_command/include/common.h index 65f24bce9..f21e9773e 100644 --- a/host/smartperf/client/client_command/include/common.h +++ b/host/smartperf/client/client_command/include/common.h @@ -40,8 +40,6 @@ enum class MessageType { GET_NETWORK_TRAFFIC, // 获取网络流量信息 BACK_TO_DESKTOP, GET_CUR_FPS, - GET_LOW_POWER_FPS, - FPS_STOP, SET_GAME_VIEW, }; @@ -66,9 +64,7 @@ const std::unordered_map MESSAGE_MAP = { { MessageType::CATCH_NETWORK_TRAFFIC, std::string("catch_network_traffic") }, { MessageType::GET_NETWORK_TRAFFIC, std::string("get_network_traffic") }, { MessageType::BACK_TO_DESKTOP, std::string("back_to_desk") }, - { MessageType::GET_LOW_POWER_FPS, std::string("get_low_power_fps") }, { MessageType::GET_CUR_FPS, std::string("get_cur_fps") }, - { MessageType::FPS_STOP, std::string("fps_stop") }, { MessageType::SET_GAME_VIEW, std::string("set_game_view") }, }; diff --git a/host/smartperf/client/client_command/include/sp_thread_socket.h b/host/smartperf/client/client_command/include/sp_thread_socket.h index 1ee32afb6..4c0c1de83 100644 --- a/host/smartperf/client/client_command/include/sp_thread_socket.h +++ b/host/smartperf/client/client_command/include/sp_thread_socket.h @@ -21,7 +21,7 @@ #include "sp_task.h" #include "control_call_cmd.h" #include "startup_delay.h" -#include "profiler_fps.h"" +#include "profiler_fps.h" #include "sp_log.h" #include "common.h" #include "heartbeat.h" @@ -31,7 +31,6 @@ namespace SmartPerf { class SpThreadSocket { public: static bool flagRunning; - static std::string resultFPS; enum SocketConnectType { CMD_SOCKET, EDITOR_SOCKET, @@ -403,9 +402,6 @@ public: SpProfilerFactory::SetProfilerPkg(retCode); } spSocket.Sendto(retCode); - } else if (iterator->first == MessageType::FPS_STOP) { - spSocket.Sendto(resultFPS); - resultFPS = "FPS||"; } else if (profiler == nullptr && (iterator->first == MessageType::SET_GAME_VIEW)) { retCode = SplitMsg(recvBuf); SpProfilerFactory::SetProfilerGameLayer(retCode); @@ -432,7 +428,6 @@ public: } }; bool SpThreadSocket::flagRunning = false; -std::string SpThreadSocket::resultFPS = "FPS||"; } } #endif \ No newline at end of file -- Gitee From ca083dc25ff199d8ae18c038963272a0df048ec5 Mon Sep 17 00:00:00 2001 From: frank-huangran Date: Thu, 28 Nov 2024 15:04:17 +0800 Subject: [PATCH 05/15] =?UTF-8?q?device=5Ffps=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: frank-huangran --- host/smartperf/client/client_command/sp_utils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/host/smartperf/client/client_command/sp_utils.cpp b/host/smartperf/client/client_command/sp_utils.cpp index 037992277..a3b306db8 100644 --- a/host/smartperf/client/client_command/sp_utils.cpp +++ b/host/smartperf/client/client_command/sp_utils.cpp @@ -663,7 +663,7 @@ bool SPUtils::IsForeGround(const std::string &pkg) isFoundAppName = true; } if (isFoundAppName && strstr(buf, "app state")) { - tag = IsFindForeGround(line); + tag = IsFindForeGround(std::string(buf)); isFoundAppName = false; break; } -- Gitee From b4e17345c57eff675d0c10e54f61df9db76b7fdd Mon Sep 17 00:00:00 2001 From: frank-huangran Date: Thu, 28 Nov 2024 15:38:12 +0800 Subject: [PATCH 06/15] =?UTF-8?q?device=5Ffps=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: frank-huangran --- .../client/client_command/include/profiler_fps.h | 3 +-- .../client/client_command/profiler_fps.cpp | 13 +++++-------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/host/smartperf/client/client_command/include/profiler_fps.h b/host/smartperf/client/client_command/include/profiler_fps.h index 1bbee3e4b..2e2889408 100644 --- a/host/smartperf/client/client_command/include/profiler_fps.h +++ b/host/smartperf/client/client_command/include/profiler_fps.h @@ -66,7 +66,7 @@ public: void GetFPS(std::vector v); void GetResultFPS(int sectionsNum); FpsInfoProfiler GetFpsInfo(); - void CalcFpsAndJitters(); + void CalcFpsAndJitters(long long curScreenTimestamp); FpsInfoProfiler GetSurfaceFrame(std::string name); FpsInfoProfiler GetFrameInfoFromMap(std::string name); void PrintSections(int msCount, long long currTimeLast, long long currTimeStart, long long currLastTime) const; @@ -97,7 +97,6 @@ private: int number = 2; bool refresh = false; long long mod = 1e9; - long long curScreenTimestamp = 0; long long prevScreenTimestamp = -1; int fpsNum = 0; bool isFirstResult = false; diff --git a/host/smartperf/client/client_command/profiler_fps.cpp b/host/smartperf/client/client_command/profiler_fps.cpp index 15218974d..bfba9ad91 100644 --- a/host/smartperf/client/client_command/profiler_fps.cpp +++ b/host/smartperf/client/client_command/profiler_fps.cpp @@ -353,15 +353,12 @@ FpsInfoProfiler ProfilerFPS::GetFrameInfoFromMap(std::string name) fpsInfo.currTimeDump = (time1.tv_sec - 1) * mod + time1.tv_nsec; LOGD("ProfilerFPS fpsInfo.curTime: %d", fpsInfo.curTime); while (fgets(tmp, sizeof(tmp), fp) != nullptr) { - long long NewScreenTimestamp = 0; - if (sscanf(tmp, "%lld", &NewScreenTimestamp) != 1 || NewScreenTimestamp == 0) { + long long curScreenTimestamp = 0; + if (sscanf(tmp, "%lld", &curScreenTimestamp) != 1 || curScreenTimestamp == 0) { continue; } - LOGD("ProfilerFPS dump time: %lld", NewScreenTimestamp); - if (curScreenTimestamp != newScreenTimestamp) { - curScreenTimestamp = newScreenTimestamp; - CalcFpsAndJitters(curScreenTimestamp); - } + LOGD("ProfilerFPS dump time: %lld", curScreenTimestamp); + CalcFpsAndJitters(curScreenTimestamp); } if (pclose(fp) == -1) { LOGE("Error: Failed to close file"); @@ -371,7 +368,7 @@ FpsInfoProfiler ProfilerFPS::GetFrameInfoFromMap(std::string name) return fpsInfo; } -void ProfilerFPS::CalcFpsAndJitters() +void ProfilerFPS::CalcFpsAndJitters(long long curScreenTimestamp) { long long prevlastScreenTimestamp = 0; long long onScreenTime = curScreenTimestamp / mod; -- Gitee From 66ea1f3394d1930149d27db14285ccbadb62b804 Mon Sep 17 00:00:00 2001 From: frank-huangran Date: Thu, 28 Nov 2024 15:39:37 +0800 Subject: [PATCH 07/15] =?UTF-8?q?device=5Ffps=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: frank-huangran --- host/smartperf/client/client_command/include/profiler_fps.h | 2 +- host/smartperf/client/client_command/profiler_fps.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/host/smartperf/client/client_command/include/profiler_fps.h b/host/smartperf/client/client_command/include/profiler_fps.h index 2e2889408..95880eda3 100644 --- a/host/smartperf/client/client_command/include/profiler_fps.h +++ b/host/smartperf/client/client_command/include/profiler_fps.h @@ -66,7 +66,7 @@ public: void GetFPS(std::vector v); void GetResultFPS(int sectionsNum); FpsInfoProfiler GetFpsInfo(); - void CalcFpsAndJitters(long long curScreenTimestamp); + void CalcFpsAndJitters(const long long &curScreenTimestamp); FpsInfoProfiler GetSurfaceFrame(std::string name); FpsInfoProfiler GetFrameInfoFromMap(std::string name); void PrintSections(int msCount, long long currTimeLast, long long currTimeStart, long long currLastTime) const; diff --git a/host/smartperf/client/client_command/profiler_fps.cpp b/host/smartperf/client/client_command/profiler_fps.cpp index bfba9ad91..a241c4470 100644 --- a/host/smartperf/client/client_command/profiler_fps.cpp +++ b/host/smartperf/client/client_command/profiler_fps.cpp @@ -368,7 +368,7 @@ FpsInfoProfiler ProfilerFPS::GetFrameInfoFromMap(std::string name) return fpsInfo; } -void ProfilerFPS::CalcFpsAndJitters(long long curScreenTimestamp) +void ProfilerFPS::CalcFpsAndJitters(const long long &curScreenTimestamp) { long long prevlastScreenTimestamp = 0; long long onScreenTime = curScreenTimestamp / mod; -- Gitee From a80cbed138fa84e5209973c96a82da1216624a5a Mon Sep 17 00:00:00 2001 From: frank-huangran Date: Thu, 28 Nov 2024 17:10:04 +0800 Subject: [PATCH 08/15] =?UTF-8?q?device=5Ffps=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: frank-huangran --- .../smartperf/client/client_command/Dubai.cpp | 2 + .../client_command/include/profiler_fps.h | 3 +- .../client/client_command/include/sp_utils.h | 2 +- .../client/client_command/profiler_fps.cpp | 43 +++++++++---------- .../client/client_command/sp_utils.cpp | 15 ++++--- 5 files changed, 34 insertions(+), 31 deletions(-) diff --git a/host/smartperf/client/client_command/Dubai.cpp b/host/smartperf/client/client_command/Dubai.cpp index 8feebe373..ef76f0761 100644 --- a/host/smartperf/client/client_command/Dubai.cpp +++ b/host/smartperf/client/client_command/Dubai.cpp @@ -14,6 +14,8 @@ */ #include #include +#include +#include #include "include/sp_utils.h" #include "include/Dubai.h" #include "include/sp_log.h" diff --git a/host/smartperf/client/client_command/include/profiler_fps.h b/host/smartperf/client/client_command/include/profiler_fps.h index 95880eda3..1bbee3e4b 100644 --- a/host/smartperf/client/client_command/include/profiler_fps.h +++ b/host/smartperf/client/client_command/include/profiler_fps.h @@ -66,7 +66,7 @@ public: void GetFPS(std::vector v); void GetResultFPS(int sectionsNum); FpsInfoProfiler GetFpsInfo(); - void CalcFpsAndJitters(const long long &curScreenTimestamp); + void CalcFpsAndJitters(); FpsInfoProfiler GetSurfaceFrame(std::string name); FpsInfoProfiler GetFrameInfoFromMap(std::string name); void PrintSections(int msCount, long long currTimeLast, long long currTimeStart, long long currLastTime) const; @@ -97,6 +97,7 @@ private: int number = 2; bool refresh = false; long long mod = 1e9; + long long curScreenTimestamp = 0; long long prevScreenTimestamp = -1; int fpsNum = 0; bool isFirstResult = false; diff --git a/host/smartperf/client/client_command/include/sp_utils.h b/host/smartperf/client/client_command/include/sp_utils.h index 75b77d2ea..6a8d04bd2 100644 --- a/host/smartperf/client/client_command/include/sp_utils.h +++ b/host/smartperf/client/client_command/include/sp_utils.h @@ -151,7 +151,7 @@ bool IntegerValueVerification(std::set &keys, std::map params; while ((fgets(buf, sizeof(buf), fd)) != nullptr) { std::string line(buf); - size_t posRealTime = line.find("CLOCK_REALTIME"); - size_t posMonotonicRaw = line.find("CLOCK_MONOTONIC_RAW"); - if (posRealTime != std::string::npos && clockRealTime == 0) { - auto realTimeStr = line.substr(line.find(' ') + 1); - realTimeStr.erase(realTimeStr.find('.')); - clockRealTime = std::stoll(realTimeStr); + SPUtils::StrSplit(line, " ", params); + if (params[0].find("CLOCK_REALTIME") != std::string::npos && clockRealTime == 0) { + strRealTime = params[two]; + strRealTime.erase(strRealTime.find('.'), 1); + clockRealTime = std::stoll(strRealTime); currRealTime = clockRealTime; - } else if (posMonotonicRaw != std::string::npos && clockMonotonicRaw == 0) { - auto monotonicRawStr = line.substr(line.find(' ') + 1); - monotonicRawStr.erase(monotonicRawStr.find('.')); - clockMonotonicRaw = std::stoll(monotonicRawStr); - } - - if (clockRealTime != 0 && clockMonotonicRaw != 0) { - break; + } else if (params[0].find("CLOCK_MONOTONIC_RAW") != std::string::npos && clockMonotonicRaw == 0) { + strRealTime = params[two]; + strRealTime.erase(strRealTime.find('.'), 1); + clockMonotonicRaw =std::stoll(strRealTime); } } if (pclose(fd) == -1) { @@ -333,7 +329,7 @@ FpsInfoProfiler ProfilerFPS::GetFrameInfoFromMap(std::string name) tmpFps.fps = 0; fpsInfo = tmpFps; FILE *fp; - static char tmp[1024]; + char tmp[1024]; GetTimeDiff(); std::string cmd = "hidumper -s 10 -a \"fps " + name + "\""; if (cmd.empty()) { @@ -352,12 +348,14 @@ FpsInfoProfiler ProfilerFPS::GetFrameInfoFromMap(std::string name) fpsInfo.curTime = static_cast(time1.tv_sec - 1); fpsInfo.currTimeDump = (time1.tv_sec - 1) * mod + time1.tv_nsec; LOGD("ProfilerFPS fpsInfo.curTime: %d", fpsInfo.curTime); + std::stringstream sstream; while (fgets(tmp, sizeof(tmp), fp) != nullptr) { - long long curScreenTimestamp = 0; - if (sscanf(tmp, "%lld", &curScreenTimestamp) != 1 || curScreenTimestamp == 0) { + sstream.clear(); + sstream.str(tmp); + sstream >> curScreenTimestamp; + if (curScreenTimestamp == 0) { continue; } - LOGD("ProfilerFPS dump time: %lld", curScreenTimestamp); CalcFpsAndJitters(curScreenTimestamp); } if (pclose(fp) == -1) { @@ -368,7 +366,7 @@ FpsInfoProfiler ProfilerFPS::GetFrameInfoFromMap(std::string name) return fpsInfo; } -void ProfilerFPS::CalcFpsAndJitters(const long long &curScreenTimestamp) +void ProfilerFPS::CalcFpsAndJitters() { long long prevlastScreenTimestamp = 0; long long onScreenTime = curScreenTimestamp / mod; @@ -378,6 +376,8 @@ void ProfilerFPS::CalcFpsAndJitters(const long long &curScreenTimestamp) if (isLowCurFps) { fpsInfo.fps = fpsNum; } else { + fpsInfo.fps = fpsNum; + fpsInfo.currTimeStamps.push_back(curScreenTimestamp); long long jitter; if (prevScreenTimestamp != -1) { jitter = curScreenTimestamp - prevScreenTimestamp; @@ -388,10 +388,7 @@ void ProfilerFPS::CalcFpsAndJitters(const long long &curScreenTimestamp) jitter = curScreenTimestamp % mod; } } - fpsInfo.fps = fpsNum; fpsInfo.jitters.push_back(jitter); - fpsInfo.currTimeStamps.push_back(curScreenTimestamp); - prevScreenTimestamp = curScreenTimestamp; prevlastScreenTimestamp = curScreenTimestamp; } diff --git a/host/smartperf/client/client_command/sp_utils.cpp b/host/smartperf/client/client_command/sp_utils.cpp index a3b306db8..73cb56101 100644 --- a/host/smartperf/client/client_command/sp_utils.cpp +++ b/host/smartperf/client/client_command/sp_utils.cpp @@ -647,7 +647,7 @@ void SPUtils::GetCurrentTime(int num, int prevTime) } } } -bool SPUtils::IsForeGround(const std::string &pkg) +bool SPUtils::IsForeGround(std::string &pkg) { bool isFoundAppName = false; const std::string cmd = "aa dump -l"; @@ -659,13 +659,16 @@ bool SPUtils::IsForeGround(const std::string &pkg) } bool tag = false; while (fgets(buf, sizeof(buf), fd) != nullptr) { - if (!isFoundAppName && strstr(buf, appLine.c_str())) { + std::string line(buf); + if (line.find(appLine) != std::string::npos) { isFoundAppName = true; } - if (isFoundAppName && strstr(buf, "app state")) { - tag = IsFindForeGround(std::string(buf)); - isFoundAppName = false; - break; + if (isFoundAppName) { + if (line.find("app state") != std::string::npos) { + tag = IsFindForeGround(line); + isFoundAppName = false; + break; + } } } if (pclose(fd) == -1) { -- Gitee From 00a60b1df0ff770e9495b26e25911467084584fc Mon Sep 17 00:00:00 2001 From: frank-huangran Date: Thu, 28 Nov 2024 17:11:09 +0800 Subject: [PATCH 09/15] =?UTF-8?q?device=5Ffps=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: frank-huangran --- host/smartperf/client/client_command/Dubai.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/host/smartperf/client/client_command/Dubai.cpp b/host/smartperf/client/client_command/Dubai.cpp index ef76f0761..f9fcac7c8 100644 --- a/host/smartperf/client/client_command/Dubai.cpp +++ b/host/smartperf/client/client_command/Dubai.cpp @@ -72,7 +72,7 @@ std::string Dubai::CallMoveDubaiDbFinished() return dubaiMoveFinish; } -bool IsFileAccessible(const std::string &filename) +bool Dubai::IsFileAccessible(const std::string &filename) { std::ifstream file(filename); return file.good(); -- Gitee From 1eb93daa63c19e970dddcaf3e08225540b309bf6 Mon Sep 17 00:00:00 2001 From: frank-huangran Date: Thu, 28 Nov 2024 17:15:42 +0800 Subject: [PATCH 10/15] =?UTF-8?q?device=5Ffps=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: frank-huangran --- host/smartperf/client/client_command/profiler_fps.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/host/smartperf/client/client_command/profiler_fps.cpp b/host/smartperf/client/client_command/profiler_fps.cpp index 0eeb77875..dba506126 100644 --- a/host/smartperf/client/client_command/profiler_fps.cpp +++ b/host/smartperf/client/client_command/profiler_fps.cpp @@ -292,9 +292,7 @@ FpsInfoProfiler ProfilerFPS::GetFpsInfo() if (ohFlag) { uniteLayer = GetSurface(); } - bool isSceneboardPkg = pkgName.find("sceneboard") != std::string::npos; - bool isGameSurfaceOrSceneboard = isGameSurface || isSceneboardPkg; - if (pkgName.empty() || isGameSurfaceOrSceneboard) { + if (pkgName.empty() || pkgName.find("sceneboard") != std::string::npos || isGameSurface) { LOGD("ProfilerFPS.pkgName: %s", pkgName.c_str()); OHOS::SmartPerf::SPUtils::GetCurrentTime(fifty, lastFpsInfoResult.curTime); fpsInfoMax = GetSurfaceFrame(uniteLayer); @@ -356,7 +354,7 @@ FpsInfoProfiler ProfilerFPS::GetFrameInfoFromMap(std::string name) if (curScreenTimestamp == 0) { continue; } - CalcFpsAndJitters(curScreenTimestamp); + CalcFpsAndJitters(); } if (pclose(fp) == -1) { LOGE("Error: Failed to close file"); -- Gitee From d5a7b6caca5bd91f3053d987203a18a016dad765 Mon Sep 17 00:00:00 2001 From: frank-huangran Date: Thu, 28 Nov 2024 17:17:43 +0800 Subject: [PATCH 11/15] =?UTF-8?q?device=5Ffps=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: frank-huangran --- host/smartperf/client/client_command/FPS.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/host/smartperf/client/client_command/FPS.cpp b/host/smartperf/client/client_command/FPS.cpp index db635e0a5..54dc4d6d0 100644 --- a/host/smartperf/client/client_command/FPS.cpp +++ b/host/smartperf/client/client_command/FPS.cpp @@ -202,9 +202,10 @@ void FPS::ReadDataFromPipe(int fd) sstream.clear(); sstream.str(tmp); sstream >> curScreenTimestamp; - if (curScreenTimestamp != 0) { - CalcFpsAndJitters(); + if (curScreenTimestamp == 0) { + continue; } + CalcFpsAndJitters(); } } -- Gitee From 69843142fc4978bca5ab3aeca885b6842d9a2940 Mon Sep 17 00:00:00 2001 From: frank-huangran Date: Thu, 28 Nov 2024 19:47:27 +0800 Subject: [PATCH 12/15] =?UTF-8?q?device=5Ffps=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: frank-huangran --- host/smartperf/client/client_command/FPS.cpp | 2 +- host/smartperf/client/client_command/sp_utils.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/host/smartperf/client/client_command/FPS.cpp b/host/smartperf/client/client_command/FPS.cpp index 54dc4d6d0..73fa7f03b 100644 --- a/host/smartperf/client/client_command/FPS.cpp +++ b/host/smartperf/client/client_command/FPS.cpp @@ -216,6 +216,7 @@ void FPS::CalcFpsAndJitters() long long fpsCurTime = fpsInfo.curTime; if (onScreenTime == fpsCurTime) { fpsNum++; + fpsInfo.fps = fpsNum; fpsInfo.currTimeStamps.push_back(curScreenTimestamp); long long jitter; if (prevScreenTimestamp != -1) { @@ -231,7 +232,6 @@ void FPS::CalcFpsAndJitters() prevScreenTimestamp = curScreenTimestamp; prevlastScreenTimestamp = curScreenTimestamp; } - fpsInfo.fps = fpsNum; } void FPS::SetRkFlag() diff --git a/host/smartperf/client/client_command/sp_utils.cpp b/host/smartperf/client/client_command/sp_utils.cpp index 73cb56101..37eea1cb4 100644 --- a/host/smartperf/client/client_command/sp_utils.cpp +++ b/host/smartperf/client/client_command/sp_utils.cpp @@ -677,7 +677,7 @@ bool SPUtils::IsForeGround(std::string &pkg) } return tag; } -bool SPUtils::IsFindForeGround(const std::string &line) +bool SPUtils::IsFindForeGround(std::string line) { return line.find("FOREGROUND") != std::string::npos; } -- Gitee From 70b60d601a7b6dbc9345bd89ab4b8c762064cf5f Mon Sep 17 00:00:00 2001 From: frank-huangran Date: Thu, 28 Nov 2024 20:06:27 +0800 Subject: [PATCH 13/15] =?UTF-8?q?device=5Ffps=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: frank-huangran --- .../client_command/include/profiler_fps.h | 2 +- .../client/client_command/profiler_fps.cpp | 28 +++++++++++-------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/host/smartperf/client/client_command/include/profiler_fps.h b/host/smartperf/client/client_command/include/profiler_fps.h index 1bbee3e4b..aff3b6daa 100644 --- a/host/smartperf/client/client_command/include/profiler_fps.h +++ b/host/smartperf/client/client_command/include/profiler_fps.h @@ -67,13 +67,13 @@ public: void GetResultFPS(int sectionsNum); FpsInfoProfiler GetFpsInfo(); void CalcFpsAndJitters(); + long long CalculateJitter(); FpsInfoProfiler GetSurfaceFrame(std::string name); FpsInfoProfiler GetFrameInfoFromMap(std::string name); void PrintSections(int msCount, long long currTimeLast, long long currTimeStart, long long currLastTime) const; void GetSectionsFps(FpsInfoProfiler &fpsInfoResult, int nums) const; void GetSectionsPrint(int printCount, long long msStartTime, int numb, long long harTime) const; void GetTimeDiff(); - void GetCurrentTime(int sleepNum); void GetOhFps(std::vector v); void SetRkFlag(); std::string GetSurface(); diff --git a/host/smartperf/client/client_command/profiler_fps.cpp b/host/smartperf/client/client_command/profiler_fps.cpp index dba506126..a72f08ba4 100644 --- a/host/smartperf/client/client_command/profiler_fps.cpp +++ b/host/smartperf/client/client_command/profiler_fps.cpp @@ -149,7 +149,7 @@ void ProfilerFPS::GetTimeDiff() } else if (params[0].find("CLOCK_MONOTONIC_RAW") != std::string::npos && clockMonotonicRaw == 0) { strRealTime = params[two]; strRealTime.erase(strRealTime.find('.'), 1); - clockMonotonicRaw =std::stoll(strRealTime); + clockMonotonicRaw = std::stoll(strRealTime); } } if (pclose(fd) == -1) { @@ -376,16 +376,7 @@ void ProfilerFPS::CalcFpsAndJitters() } else { fpsInfo.fps = fpsNum; fpsInfo.currTimeStamps.push_back(curScreenTimestamp); - long long jitter; - if (prevScreenTimestamp != -1) { - jitter = curScreenTimestamp - prevScreenTimestamp; - } else { - if (prevlastScreenTimestamp != 0 && (curScreenTimestamp - prevlastScreenTimestamp) < mod) { - jitter = curScreenTimestamp - prevlastScreenTimestamp; - } else { - jitter = curScreenTimestamp % mod; - } - } + long long jitter = CalculateJitter(); fpsInfo.jitters.push_back(jitter); prevScreenTimestamp = curScreenTimestamp; prevlastScreenTimestamp = curScreenTimestamp; @@ -393,6 +384,21 @@ void ProfilerFPS::CalcFpsAndJitters() } } +long long ProfilerFPS::CalculateJitter() +{ + long long jitter; + if (prevScreenTimestamp == -1) { + if (prevlastScreenTimestamp != 0 && (curScreenTimestamp - prevlastScreenTimestamp) < mod) { + jitter = curScreenTimestamp - prevlastScreenTimestamp; + } else { + jitter = curScreenTimestamp % mod; + } + } else { + jitter = curScreenTimestamp - prevScreenTimestamp; + } + return jitter; +} + void ProfilerFPS::GetOhFps(std::vector v) { if (v[number] == "") { -- Gitee From cbfb386652b8124cbe992ab2b3f2da8b73f61a74 Mon Sep 17 00:00:00 2001 From: frank-huangran Date: Thu, 28 Nov 2024 20:07:53 +0800 Subject: [PATCH 14/15] =?UTF-8?q?device=5Ffps=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: frank-huangran --- host/smartperf/client/client_command/include/sp_utils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/host/smartperf/client/client_command/include/sp_utils.h b/host/smartperf/client/client_command/include/sp_utils.h index 6a8d04bd2..791b9891b 100644 --- a/host/smartperf/client/client_command/include/sp_utils.h +++ b/host/smartperf/client/client_command/include/sp_utils.h @@ -152,7 +152,7 @@ bool IsHmKernel(); std::string GetCpuNum(); void GetCurrentTime(int num, int prevTime); bool IsForeGround(std::string &pkg); -bool IsFindForeGround(const std::string &line); +bool IsFindForeGround(std::string line); bool IsFindAbilist(); void SetRkFlag(); bool GetPathPermissions(const std::string &path); -- Gitee From 6b8ccf87d5b0d879767001b4e50019c54e022aae Mon Sep 17 00:00:00 2001 From: frank-huangran Date: Thu, 28 Nov 2024 20:44:36 +0800 Subject: [PATCH 15/15] =?UTF-8?q?device=5Ffps=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: frank-huangran --- host/smartperf/client/client_command/FPS.cpp | 2 +- host/smartperf/client/client_command/include/profiler_fps.h | 1 + host/smartperf/client/client_command/profiler_fps.cpp | 1 - 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/host/smartperf/client/client_command/FPS.cpp b/host/smartperf/client/client_command/FPS.cpp index 73fa7f03b..54dc4d6d0 100644 --- a/host/smartperf/client/client_command/FPS.cpp +++ b/host/smartperf/client/client_command/FPS.cpp @@ -216,7 +216,6 @@ void FPS::CalcFpsAndJitters() long long fpsCurTime = fpsInfo.curTime; if (onScreenTime == fpsCurTime) { fpsNum++; - fpsInfo.fps = fpsNum; fpsInfo.currTimeStamps.push_back(curScreenTimestamp); long long jitter; if (prevScreenTimestamp != -1) { @@ -232,6 +231,7 @@ void FPS::CalcFpsAndJitters() prevScreenTimestamp = curScreenTimestamp; prevlastScreenTimestamp = curScreenTimestamp; } + fpsInfo.fps = fpsNum; } void FPS::SetRkFlag() diff --git a/host/smartperf/client/client_command/include/profiler_fps.h b/host/smartperf/client/client_command/include/profiler_fps.h index aff3b6daa..180a58109 100644 --- a/host/smartperf/client/client_command/include/profiler_fps.h +++ b/host/smartperf/client/client_command/include/profiler_fps.h @@ -97,6 +97,7 @@ private: int number = 2; bool refresh = false; long long mod = 1e9; + long long prevlastScreenTimestamp = 0; long long curScreenTimestamp = 0; long long prevScreenTimestamp = -1; int fpsNum = 0; diff --git a/host/smartperf/client/client_command/profiler_fps.cpp b/host/smartperf/client/client_command/profiler_fps.cpp index a72f08ba4..7165224c0 100644 --- a/host/smartperf/client/client_command/profiler_fps.cpp +++ b/host/smartperf/client/client_command/profiler_fps.cpp @@ -366,7 +366,6 @@ FpsInfoProfiler ProfilerFPS::GetFrameInfoFromMap(std::string name) void ProfilerFPS::CalcFpsAndJitters() { - long long prevlastScreenTimestamp = 0; long long onScreenTime = curScreenTimestamp / mod; long long fpsCurTime = fpsInfo.curTime; if (onScreenTime == fpsCurTime) { -- Gitee