diff --git a/host/smartperf/client/client_command/Capture.cpp b/host/smartperf/client/client_command/Capture.cpp index 627707b5002b3c280a2bec05033cc87847ffbaab..461cedb792f8c45d13859cb878d6e6e06be014ae 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/Dubai.cpp b/host/smartperf/client/client_command/Dubai.cpp index d0f0617a59844e11e37de1aa4f1dfe744ccc0465..f9fcac7c831b3cb93e59300960e603fc3e5f5d68 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" @@ -36,16 +38,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 +71,11 @@ std::string Dubai::CallMoveDubaiDbFinished() dubaiMoveFinish = "get_dubai_db"; return dubaiMoveFinish; } + +bool Dubai::IsFileAccessible(const std::string &filename) +{ + std::ifstream file(filename); + return file.good(); +} } } diff --git a/host/smartperf/client/client_command/FPS.cpp b/host/smartperf/client/client_command/FPS.cpp index db635e0a53a0e4a49416d1a63734a639e34ead07..54dc4d6d02bd21ec3eaf7d3e00789a5cfaf32e5c 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(); } } diff --git a/host/smartperf/client/client_command/include/Capture.h b/host/smartperf/client/client_command/include/Capture.h index f5011dc5835614e349e881160a368ad56688ddcc..489de434e0ebcc0a5cf7460b8f72ac6b34bb7498 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/Dubai.h b/host/smartperf/client/client_command/include/Dubai.h index 555cae9cb746b6d60360b98cefa5184085846e04..d7ff59065ace774da956023c0bda839f8eb58acb 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/common.h b/host/smartperf/client/client_command/include/common.h index 65f24bce93ce7f230720b298f6de21d0b074cb68..f21e9773ec377cc9979123e97c29c90c37630461 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/profiler_fps.h b/host/smartperf/client/client_command/include/profiler_fps.h index cd3cbe35d13e9d636c079475ab4ec95994ee9e8f..180a581090f7419b7eb26c20107ff7370677de0b 100644 --- a/host/smartperf/client/client_command/include/profiler_fps.h +++ b/host/smartperf/client/client_command/include/profiler_fps.h @@ -66,22 +66,18 @@ 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(); + 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(); 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 &); @@ -100,9 +97,9 @@ private: int number = 2; bool refresh = false; long long mod = 1e9; + long long prevlastScreenTimestamp = 0; 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_task.h b/host/smartperf/client/client_command/include/sp_task.h index 7fd2096e720c6de9e0f89d4a98c77b15ca5ffc5d..c3d624d685cdab09336598235cb4f855c5d4fd86 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 ddba734308a5fef5ced59794a5416afb3f8e657c..4c0c1de835cb002c682468a7db8b63757602f015 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" @@ -30,7 +31,6 @@ namespace SmartPerf { class SpThreadSocket { public: static bool flagRunning; - static std::string resultFPS; enum SocketConnectType { CMD_SOCKET, EDITOR_SOCKET, @@ -209,7 +209,6 @@ public: } else { spSocket.Send(std::string("startRecord::") + std::to_string(START_RECORD_FAILED)); } - SPTask::GetInstance().SaveScreenShot(); spSocket.Send("startRecord::True"); } @@ -335,19 +334,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()); } } @@ -410,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); @@ -439,7 +428,6 @@ public: } }; bool SpThreadSocket::flagRunning = false; -std::string SpThreadSocket::resultFPS = "FPS||"; } } #endif \ No newline at end of file diff --git a/host/smartperf/client/client_command/profiler_fps.cpp b/host/smartperf/client/client_command/profiler_fps.cpp index a3e5a8c92bcaa33fc02e165972d50c2027649ba7..7165224c0a0baf4695f5cfc0ff70f74609cdd7a1 100644 --- a/host/smartperf/client/client_command/profiler_fps.cpp +++ b/host/smartperf/client/client_command/profiler_fps.cpp @@ -129,7 +129,7 @@ void ProfilerFPS::GetTimeDiff() { long long clockRealTime = 0; long long clockMonotonicRaw = 0; - int two = 2; + const int two = 2; std::string strRealTime; const std::string cmd = CMD_COMMAND_MAP.at(CmdCommand::TIMESTAMPS); FILE *fd = popen(cmd.c_str(), "r"); @@ -137,19 +137,19 @@ void ProfilerFPS::GetTimeDiff() return; } char buf[1024] = {'\0'}; + std::vector params; while ((fgets(buf, sizeof(buf), fd)) != nullptr) { - std::string line = buf; - std::vector params; + std::string line(buf); 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); + clockRealTime = std::stoll(strRealTime); 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); + clockMonotonicRaw = std::stoll(strRealTime); } } if (pclose(fd) == -1) { @@ -271,6 +271,7 @@ std::string ProfilerFPS::GetSurface() FpsInfoProfiler ProfilerFPS::GetFpsInfo() { + FpsInfoProfiler fpsInfoMax; processFlag = false; fpsInfoMax.fps = 0; std::string uniteLayer; @@ -322,16 +323,11 @@ 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]; + char tmp[1024]; GetTimeDiff(); std::string cmd = "hidumper -s 10 -a \"fps " + name + "\""; if (cmd.empty()) { @@ -350,12 +346,10 @@ 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) { - std::string str(tmp); - LOGD("ProfilerFPS dump time: %s", str.c_str()); - curScreenTimestamp = 0; - std::stringstream sstream; - sstream << tmp; + sstream.clear(); + sstream.str(tmp); sstream >> curScreenTimestamp; if (curScreenTimestamp == 0) { continue; @@ -372,30 +366,36 @@ 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 onScreenTime = curScreenTimestamp / mod; + long long fpsCurTime = fpsInfo.curTime; if (onScreenTime == fpsCurTime) { - long long jitter; - if (prevScreenTimestamp != -1) { - jitter = curScreenTimestamp - prevScreenTimestamp; + fpsNum++; + if (isLowCurFps) { + fpsInfo.fps = fpsNum; + } else { + fpsInfo.fps = fpsNum; + fpsInfo.currTimeStamps.push_back(curScreenTimestamp); + long long jitter = CalculateJitter(); fpsInfo.jitters.push_back(jitter); + prevScreenTimestamp = curScreenTimestamp; + prevlastScreenTimestamp = curScreenTimestamp; + } + } +} + +long long ProfilerFPS::CalculateJitter() +{ + long long jitter; + if (prevScreenTimestamp == -1) { + if (prevlastScreenTimestamp != 0 && (curScreenTimestamp - prevlastScreenTimestamp) < mod) { + jitter = curScreenTimestamp - prevlastScreenTimestamp; } else { - if (prevlastScreenTimestamp != 0 && (curScreenTimestamp - prevlastScreenTimestamp) < mod) { - jitter = curScreenTimestamp - prevlastScreenTimestamp; - fpsInfo.jitters.push_back(jitter); - } else { - jitter = curScreenTimestamp - curScreenTimestamp / mod * mod; - fpsInfo.jitters.push_back(jitter); - } + jitter = curScreenTimestamp % mod; } - prevScreenTimestamp = curScreenTimestamp; - prevlastScreenTimestamp = curScreenTimestamp; + } else { + jitter = curScreenTimestamp - prevScreenTimestamp; } + return jitter; } void ProfilerFPS::GetOhFps(std::vector v) @@ -427,13 +427,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 dd4ff4ef869484dad99558bbbb9848735c6697f6..a5ebe60034b29eb8123a692ad89cbcf0e4d8542e 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_task.cpp b/host/smartperf/client/client_command/sp_task.cpp index af22e8a1d99653abcbd24bfc96753c862a125b90..4811dd9de007ce8719cc8fe7e9bfbd16d245b86d 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) { @@ -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() @@ -620,13 +617,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 +647,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; diff --git a/host/smartperf/client/client_command/sp_utils.cpp b/host/smartperf/client/client_command/sp_utils.cpp index 3261b9bba1c9f7336bd8d6b943abf3d7e26da34a..37eea1cb4e32e181408ac9568ba2a9222a1c29ec 100644 --- a/host/smartperf/client/client_command/sp_utils.cpp +++ b/host/smartperf/client/client_command/sp_utils.cpp @@ -650,29 +650,24 @@ void SPUtils::GetCurrentTime(int num, int prevTime) 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; + 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 (isFoundAppName) { if (line.find("app state") != std::string::npos) { tag = IsFindForeGround(line); isFoundAppName = false; - isFoundBundleName = false; + break; } } } @@ -684,12 +679,7 @@ bool SPUtils::IsForeGround(std::string &pkg) } 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; - } + return line.find("FOREGROUND") != std::string::npos; } bool SPUtils::IsFindAbilist() {