diff --git a/smartperf_device/device_command/scenarios/include/parse_click_complete_trace.h b/smartperf_device/device_command/scenarios/include/parse_click_complete_trace.h new file mode 100644 index 0000000000000000000000000000000000000000..b7d046a0cac8a43f050cc5e1f036709d05e94928 --- /dev/null +++ b/smartperf_device/device_command/scenarios/include/parse_click_complete_trace.h @@ -0,0 +1,43 @@ +/* + * 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_CLICK_COMPLETE_TRACE_H +#define PARSE_CLICK_COMPLETE_TRACE_H +#include +#include +#include +#include +namespace OHOS { +namespace SmartPerf { +class ParseClickCompleteTrace { +public: + double ParseCompleteTrace(const std::string& fileNamePath); + double GetTime(std::string endTime); + std::string GetPid(const std::string& line, const std::string &pn, const std::string &pb); + std::string GetStartTime(const std::string& line, const std::string &startTimeBefore); + double GetLineTime(); + +private: + std::ifstream infile; + std::string flagTime = "0"; + size_t flagTouch = 0; + int appPidnum = 0; + double completeTime = -1; + std::string startTime = "0"; + std::string endTimeFlag = "0"; + std::string appPid = "0"; +}; +} +} +#endif \ No newline at end of file diff --git a/smartperf_device/device_command/scenarios/include/parse_click_response_trace.h b/smartperf_device/device_command/scenarios/include/parse_click_response_trace.h new file mode 100644 index 0000000000000000000000000000000000000000..1e0207cf360ffa6a2bdfb410758d14a24f872537 --- /dev/null +++ b/smartperf_device/device_command/scenarios/include/parse_click_response_trace.h @@ -0,0 +1,40 @@ +/* + * 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_CLICK_RESPONSE_TRACE_H +#define PARSE_CLICK_RESPONSE_TRACE_H +#include +#include +#include +#include +namespace OHOS { +namespace SmartPerf { +class ParseClickResponseTrace { +public: + double ParseResponseTrace(const std::string& fileNamePath); + double GetTime(std::string startTime, std::string endTime); + std::string GetPid(const std::string& line, const std::string &pn, const std::string &pb); + std::string GetStartTime(const std::string& line, const std::string &startTimeBefore); + double GetLineTime(); + +private: + std::string flagTime = "0"; + int flagTouch = 0; + int appPidnum = 0; + double completeTime = -1; + std::ifstream infile; +}; +} +} +#endif \ No newline at end of file diff --git a/smartperf_device/device_command/scenarios/include/parse_radar.h b/smartperf_device/device_command/scenarios/include/parse_radar.h new file mode 100644 index 0000000000000000000000000000000000000000..e2a2e51ae8d0f1d4ec2fe22ad58c07586171b9de --- /dev/null +++ b/smartperf_device/device_command/scenarios/include/parse_radar.h @@ -0,0 +1,41 @@ +/* + * 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_RADAR_H +#define PARSE_RADAR_H +#include +#include +#include +#include +namespace OHOS { +namespace SmartPerf { +class ParseRadar { +public: + double ParseRadarResponse(const std::string &string) const; + double ParseRadarDelayTime(const std::string &string, const std::string &target, const int &delayTime) const; + std::string ParseRadarAppStrart(const std::string &string) const; + double ParseRadarComplete(const std::string &string) const; + std::string ExtractString(const std::string &str, const std::string &target) const; + std::string ParseRadarFrame(const std::string &string) const; + std::string ParseRadarMaxFrame(const std::string &string) const; + int GetMaxDelayTime(const int &delayTime, std::vector &delayTimeVec) const; +private: + const int delayTimeResponse = 2000; + const int delayTimeComplete = 2500; + const std::string targetResponse = "\"RESPONSE_LATENCY\""; + const std::string targetComplete = "\"E2E_LATENCY\""; +}; +} +} +#endif // PARSE_RADAR_H \ No newline at end of file diff --git a/smartperf_device/device_command/scenarios/include/stalling_rate_trace.h b/smartperf_device/device_command/scenarios/include/stalling_rate_trace.h new file mode 100644 index 0000000000000000000000000000000000000000..15988e8a347deb6909a21ae9b4f4d11b6f331690 --- /dev/null +++ b/smartperf_device/device_command/scenarios/include/stalling_rate_trace.h @@ -0,0 +1,91 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2023. All rights reserved. + * 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 STALLINGRATETRACE_H +#define STALLINGRATETRACE_H +#include +#include +#include +#include + +namespace OHOS { +namespace SmartPerf { +class StallingRateTrace { +public: + enum SWIM_TYPE { + SWIM_APPLIST = 1, + SWIM_APPSWIPER = 2, + SWIM_APPTABS = 3, + }; +public: + double StallingRateResult(const std::string& file); + double CalculateTime(); + double GetFrameRate(const std::string &line) const; + int GetFenceId(const std::string &line) const; + std::string GetOnScreenTimeStart(const std::string &line) const; + double GetTimes(const std::string &line, const std::string &sign) const; + void AppList(const std::string &line, const std::string &signS, const std::string &signF); + void APPTabs(const std::string &line, const std::string &signS, const std::string &signF); + void AppSwiperScroll(const std::string &line, const std::string &signS, const std::string &signF); + void GetRsHardWareRate(double curFrameRate, const std::string &line, SWIM_TYPE type); + void GetFrameLossTime(double &curTime, double &prevTime, double &drawTime, double &totalFrameLossTime); + void CalcFrameRate(); + void JudgFrameRate(); + void MultiLaneFrameRate(); + void AddMultiLaneFrameRate(); + void UpdateRoundTime(double curFrameRate, SWIM_TYPE type); + bool IsAppLaunchPatternMatched(const std::string &line); +private: + std::ifstream infile; + double nowFrameRate = 0; + double nowSwiperFrameRate = 0; + double nowTabsFrameRate = 0; + double oneThousand = 1000; + double roundTime = 0; + double roundSwiperTime = 0; + double roundTabsTime = 0; + int fenceId = 0; + int fenceIdSwiper = 0; + int fenceIdTabs = 0; + double nowTime = 0; + double nowSwiperTime = 0; + double nowTabsTime = 0; + double lastTime = 0; + double lastSwiperTime = 0; + double lastTabsTime = 0; + double frameLossTime = 0; + double frameLossRate = 0; + double frameLossSwiperTime = 0; + double frameLossTabsTime = 0; + double swiperFrameLossRate = 0; + double appFrameLossRate = 0; + double tabsFrameLossRate = 0; + double appListDynamicStartTime = 0; + double appListDynamicFinishTime = 0; + double appTabsDynamicStartTime = 0; + double appTabsDynamicFinishTime = 0; + double swiperDynamicStartTime = 0; + double swiperDynamicFinishTime = 0; + bool upperScreenFlag = false; + bool upperScreenSwiperFlag = false; + bool upperScreenTabsFlag = false; + int swiperScrollFlag = 0; + int swiperFlingFlag = 0; + bool listFlag = false; + bool tabsFlag = false; + bool swiperFlag = false; +}; +} +} +#endif // STALLINGRATETRACE_H \ No newline at end of file diff --git a/smartperf_device/device_command/scenarios/src/parse_click_complete_trace.cpp b/smartperf_device/device_command/scenarios/src/parse_click_complete_trace.cpp new file mode 100644 index 0000000000000000000000000000000000000000..65147da92270df65c7938a5d53228a4468fae73a --- /dev/null +++ b/smartperf_device/device_command/scenarios/src/parse_click_complete_trace.cpp @@ -0,0 +1,149 @@ +/* + * 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 +#include +#include +#include +#include +#include +#include +#include "include/parse_click_complete_trace.h" +#include "include/sp_utils.h" +#include "include/sp_log.h" +namespace OHOS { +namespace SmartPerf { +double ParseClickCompleteTrace::ParseCompleteTrace(const std::string& fileNamePath) +{ + int conversion = 1000; + char realPath[PATH_MAX] = {0x00}; + if ((realpath(fileNamePath.c_str(), realPath) == nullptr)) { + std::cout << "" << std::endl; + } + infile.open(realPath); + if (infile.fail()) { + LOGE("ParseClickCompleteTrace open file(%s) fialed ", fileNamePath.c_str()); + return 0; + } + completeTime = GetLineTime(); + infile.close(); + return completeTime * conversion; +} +double ParseClickCompleteTrace::GetLineTime() +{ + std::string line; + std::string endTime = "0"; + std::string::size_type doComposition; + while (getline(infile, line)) { + appPid = GetPid(line, "pid", appPid); + startTime = GetStartTime(line, startTime); + doComposition = line.find("H:RSMainThread::DoComposition"); + if (doComposition != std::string::npos) { + size_t subNum = 5; + size_t position1 = line.find("...."); + size_t position2 = line.find(":"); + endTime = line.substr(position1 + subNum, position2 - position1 - subNum); + int endNum = SPUtilesTye::StringToSometype(endTime); + int endFlagNum = SPUtilesTye::StringToSometype(endTimeFlag); + int startNum = SPUtilesTye::StringToSometype(startTime); + int timeNum = endNum - endFlagNum; + float interval = 0.3; + if (timeNum < interval) { + endTimeFlag = endTime; + continue; + } + if (SPUtilesTye::StringToSometype(endTimeFlag) == 0) { + endTimeFlag = endTime; + } else if (endFlagNum != 0 && startNum != 0 && timeNum > interval) { + break; + } else { + endTimeFlag = endTime; + } + } + } + completeTime = GetTime(endTime); + return completeTime; +} +double ParseClickCompleteTrace::GetTime(std::string endTime) +{ + size_t point = endTime.find("."); + float subNum = 2; + endTime = endTime.substr(point - subNum); + startTime = startTime.substr(point - subNum); + if (SPUtilesTye::StringToSometype(endTime) == 0 || SPUtilesTye::StringToSometype(startTime) == 0) { + } else { + double displayTime = 0.032; + completeTime = SPUtilesTye::StringToSometype(endTime) - + SPUtilesTye::StringToSometype(startTime) + displayTime; + } + return completeTime; +} +std::string ParseClickCompleteTrace::GetPid(const std::string& line, const std::string &pn, const std::string &pb) +{ + if (appPidnum == 0) { + std::string::size_type positionPackgeName; + size_t packageNameNumSize = 5; + if (pn.length() < packageNameNumSize) { + std::string::size_type positionAppspawn; + positionPackgeName = line.find("task_newtask: pid="); + positionAppspawn = line.find("comm=appspawn"); + if (positionPackgeName != std::string::npos && positionAppspawn != std::string::npos) { + size_t position1 = line.find("pid="); + size_t position2 = line.find(" comm=appspawn"); + size_t subNum = 4; + appPid = line.substr(position1 + subNum, position2 - position1 - subNum); + appPidnum++; + } else { + appPid = pb; + } + } else { + positionPackgeName = line.find(pn); + if (positionPackgeName != std::string::npos) { + size_t p1 = line.find(pn); + size_t p2 = line.find(" prio"); + appPid = line.substr(p1 + pn.length(), p2 - p1 - pn.length()); + appPidnum++; + } else { + appPid = pb; + } + } + } + return appPid; +} +std::string ParseClickCompleteTrace::GetStartTime(const 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; +} +} +} \ No newline at end of file diff --git a/smartperf_device/device_command/scenarios/src/parse_click_response_trace.cpp b/smartperf_device/device_command/scenarios/src/parse_click_response_trace.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b371e66f52a1c132b9542d10633103b39169c3e4 --- /dev/null +++ b/smartperf_device/device_command/scenarios/src/parse_click_response_trace.cpp @@ -0,0 +1,142 @@ +/* + * 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 +#include +#include +#include +#include +#include +#include +#include "include/parse_click_response_trace.h" +#include "include/sp_utils.h" +#include "include/sp_log.h" +namespace OHOS { +namespace SmartPerf { +double ParseClickResponseTrace::ParseResponseTrace(const std::string& fileNamePath) +{ + int conversion = 1000; + char realPath[PATH_MAX] = {0x00}; + if ((realpath(fileNamePath.c_str(), realPath) == nullptr)) { + std::cout << "" << std::endl; + } + infile.open(realPath); + if (infile.fail()) { + LOGE("ParseClickResponseTrace open file(%s) fialed ", fileNamePath.c_str()); + return 0; + } + completeTime = GetLineTime(); + infile.close(); + return completeTime * conversion; +} +double ParseClickResponseTrace::GetLineTime() +{ + std::string line; + std::string startTime = "0"; + std::string endTime = "0"; + std::string appPid = "0"; + std::string::size_type doComposition; + size_t subNum = 5; + while (getline(infile, line)) { + appPid = GetPid(line, "pid", appPid); + startTime = GetStartTime(line, startTime); + doComposition = line.find("H:RSMainThread::DoComposition"); + if (doComposition != std::string::npos) { + size_t position1 = line.find("...."); + size_t position2 = line.find(":"); + endTime = line.substr(position1 + subNum, position2 - position1 - subNum); + if (SPUtilesTye::StringToSometype(startTime) == 0) { + } else { + break; + } + } + } + completeTime = GetTime(startTime, endTime); + return completeTime; +} +double ParseClickResponseTrace::GetTime(std::string startTime, std::string endTime) +{ + size_t point = endTime.find("."); + float subNum = 2; + endTime = endTime.substr(point - subNum); + startTime = startTime.substr(point - subNum); + if (SPUtilesTye::StringToSometype(endTime) == 0 || SPUtilesTye::StringToSometype(startTime) == 0) { + } else { + double displayTime = 0.032; + completeTime = SPUtilesTye::StringToSometype(endTime) - + SPUtilesTye::StringToSometype(startTime) + displayTime; + } + return completeTime; +} +std::string ParseClickResponseTrace::GetPid(const std::string& line, const std::string &pn, const std::string &pb) +{ + std::string appPid; + if (appPidnum == 0) { + size_t packageNameNumSize = 5; + std::string::size_type positionPackgeName; + if (pn.length() < packageNameNumSize) { + std::string::size_type positionAppspawn; + positionPackgeName = line.find("task_newtask: pid="); + positionAppspawn = line.find("comm=appspawn"); + if (positionPackgeName != std::string::npos && positionAppspawn != std::string::npos) { + size_t subNum = 4; + size_t position1 = line.find("pid="); + size_t position2 = line.find(" comm=appspawn"); + appPid = line.substr(position1 + subNum, position2 - position1 - subNum); + appPidnum++; + } else { + appPid = pb; + } + } else { + positionPackgeName = line.find(pn); + if (positionPackgeName != std::string::npos) { + size_t p1 = line.find(pn); + size_t p2 = line.find(" prio"); + appPid = line.substr(p1 + pn.length(), p2 - p1 - pn.length()); + appPidnum++; + } else { + appPid = pb; + } + } + } + return appPid; +} +std::string ParseClickResponseTrace::GetStartTime(const std::string& line, const std::string &startTimeBefore) +{ + std::string startTime; + 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) { + int 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; +} +} +} \ No newline at end of file diff --git a/smartperf_device/device_command/scenarios/src/parse_radar.cpp b/smartperf_device/device_command/scenarios/src/parse_radar.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5e8a12d584505e94fb0db66a7645ccaa9683244f --- /dev/null +++ b/smartperf_device/device_command/scenarios/src/parse_radar.cpp @@ -0,0 +1,148 @@ +/* + * 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "include/parse_radar.h" +#include "include/sp_utils.h" +namespace OHOS { +namespace SmartPerf { +std::string ParseRadar::ParseRadarAppStrart(const std::string &string) const +{ + std::ostringstream stream; + std::ostringstream streamComplete; + std::string animationCompleteTime = ExtractString(string, "\"ANIMATION_LATENCY\":"); + double completeTime = ParseRadarDelayTime(string, targetComplete, delayTimeComplete); + streamComplete << completeTime; + double responseTime = ParseRadarDelayTime(string, targetResponse, delayTimeResponse); + stream << responseTime; + std::string firstFrameDrawnTime = ExtractString(string, "\"FIRST_FRAEM_DRAWN_LATENCY\":"); + std::string result = "ResponseTime:" + stream.str() + + "ms\n" + "FirstFrameDrawnTime:" + + firstFrameDrawnTime + + "ms\n" + "AnimationCompleteTime:" + + animationCompleteTime + + "ms\n" + "CompleteTime:" + + streamComplete.str() + "ms\n"; + return result; +} +double ParseRadar::ParseRadarResponse(const std::string &string) const +{ + double time = -1; + time = ParseRadarDelayTime(string, targetResponse, delayTimeResponse); + return time; +} + +double ParseRadar::ParseRadarDelayTime(const std::string &string, const std::string &target, const int &delayTime) const +{ + std::stringstream ss(string); + std::string segment; + int maxDelayTime = -1; + std::vector delayTimeVec; + while (getline(ss, segment, '}')) { + if (segment.empty()) { + continue; + } + std::string segments = segment.substr(1); + std::stringstream ss2(segments); + std::string pair; + while (getline(ss2, pair, ',')) { + std::string key = pair.substr(0, pair.find(':')); + std::string value = pair.substr(pair.find(':') + 1); + if (key == target) { + delayTimeVec.push_back(value); + maxDelayTime = GetMaxDelayTime(delayTime, delayTimeVec); + } + } + } + return static_cast(maxDelayTime); +} +int ParseRadar::GetMaxDelayTime(const int &delayTime, std::vector &delayTimeVec) const +{ + int maxNum = -1; + for (size_t i = 0; i < delayTimeVec.size(); i++) { + int num = SPUtilesTye::StringToSometype(delayTimeVec[i]); + if (num < delayTime && num > maxNum) { + maxNum = num; + } + } + return maxNum; +} +double ParseRadar::ParseRadarComplete(const std::string &string) const +{ + double time = -1; + time = ParseRadarDelayTime(string, targetComplete, delayTimeComplete); + return time; +} +std::string ParseRadar::ParseRadarMaxFrame(const std::string &string) const +{ + std::string maxRenderSeqMissedFrames = ExtractString(string, "\"MAX_RENDER_SEQ_MISSED_FRAMES\":"); + std::string result = "MAX_RENDER_SEQ_MISSED_FRAMES:" + maxRenderSeqMissedFrames; + return result; +} +std::string ParseRadar::ParseRadarFrame(const std::string &string) const +{ + std::string budleName = ExtractString(string, "\"BUNDLE_NAME_EX\":"); + std::cout << "BUNDLE_NAME:" << budleName << std::endl; + std::string sceneId = ExtractString(string, "\"SCENE_ID\":"); + std::cout << "SCENE_ID:" << sceneId << std::endl; + std::string totalAppFrames = ExtractString(string, "\"TOTAL_APP_FRAMES\":"); + std::cout << "TOTAL_APP_FRAMES:" << totalAppFrames << std::endl; + std::string totalAppMissedFrames = ExtractString(string, "\"TOTAL_APP_MISSED_FRAMES\":"); + std::cout << "TOTAL_APP_MISSED_FRAMES:" << totalAppMissedFrames << std::endl; + std::string maxAppFramsestime = ExtractString(string, "\"MAX_APP_FRAMETIME\":"); + std::cout << "MAX_APP_FRAMETIME:" << maxAppFramsestime << "ms" << std::endl; + std::string maxAppSeqMissedFrames = ExtractString(string, "\"MAX_APP_SEQ_MISSED_FRAMES\":"); + std::cout << "MAX_APP_SEQ_MISSED_FRAMES:" << maxAppSeqMissedFrames << std::endl; + std::string totalRenderFrames = ExtractString(string, "\"TOTAL_RENDER_FRAMES\":"); + std::cout << "TOTAL_RENDER_FRAMES:" << totalRenderFrames << std::endl; + std::string totalRenderMissedFrames = ExtractString(string, "\"TOTAL_RENDER_MISSED_FRAMES\":"); + std::cout << "TOTAL_RENDER_MISSED_FRAMES:" << totalRenderMissedFrames << std::endl; + std::string maxRenderFrametime = ExtractString(string, "\"MAX_RENDER_FRAMETIME\":"); + std::cout << "MAX_RENDER_FRAMETIME:" << maxRenderFrametime << "ms" << std::endl; + std::string averageRenderFrametime = ExtractString(string, "\"AVERAGE_RENDER_FRAMETIME\":"); + std::cout << "AVERAGE_RENDER_FRAMETIME:" << averageRenderFrametime << "ms" << std::endl; + std::string maxRenderSeqMissedFrames = ExtractString(string, "\"MAX_RENDER_SEQ_MISSED_FRAMES\":"); + std::cout << "MAX_RENDER_SEQ_MISSED_FRAMES:" << maxRenderSeqMissedFrames << std::endl; + std::string result = ""; + return result; +} +std::string ParseRadar::ExtractString(const std::string &str, const std::string &target) const +{ + size_t pos = str.find(target); + if (pos != std::string::npos) { + pos += target.length(); + size_t commaPos = str.find(",", pos); + if (commaPos != std::string::npos) { + std::string result = str.substr(pos, commaPos - pos); + return result; + } + } + + return "-1"; +} +} +} \ No newline at end of file diff --git a/smartperf_device/device_command/scenarios/src/stalling_rate_trace.cpp b/smartperf_device/device_command/scenarios/src/stalling_rate_trace.cpp new file mode 100644 index 0000000000000000000000000000000000000000..77b31060b560176838095fa634d880e843a62953 --- /dev/null +++ b/smartperf_device/device_command/scenarios/src/stalling_rate_trace.cpp @@ -0,0 +1,447 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2023. All rights reserved. + * 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 +#include +#include +#include +#include +#include "include/stalling_rate_trace.h" +#include "include/sp_log.h" +#include "include/sp_utils.h" + +namespace OHOS { +namespace SmartPerf { +double StallingRateTrace::StallingRateResult(const std::string& file) +{ + double stalligRate = 0; + char realPath[PATH_MAX] = {0x00}; + if ((realpath(file.c_str(), realPath) == nullptr)) { + std::cout << "" << std::endl; + } + infile.open(realPath); + if (infile.fail()) { + LOGE("StallingRateTrace open file(%s) fialed ", file.c_str()); + return stalligRate; + } + stalligRate = SmartPerf::StallingRateTrace::CalculateTime(); + infile.close(); + return stalligRate; +} + +double StallingRateTrace::CalculateTime() +{ + frameLossRate = 0; + frameLossTime = 0; + swiperFrameLossRate = 0; + appFrameLossRate = 0; + tabsFrameLossRate = 0; + frameLossSwiperTime = 0; + frameLossTabsTime = 0; + std::string signS = "S|"; + std::string signF = "F|"; + std::string line; + while (getline(infile, line)) { + AppList(line, signS, signF); + AppSwiperScroll(line, signS, signF); + APPTabs(line, signS, signF); + } + CalcFrameRate(); + JudgFrameRate(); + MultiLaneFrameRate(); + return frameLossRate; +} + +void StallingRateTrace::CalcFrameRate() +{ + if (appListDynamicStartTime != 0 && appListDynamicFinishTime != 0) { + appFrameLossRate = (frameLossTime / (appListDynamicFinishTime - appListDynamicStartTime) * oneThousand); + } else { + appFrameLossRate = -1; + } + + if (swiperDynamicFinishTime != 0 && swiperDynamicStartTime != 0) { + swiperFrameLossRate = (frameLossSwiperTime / (swiperDynamicFinishTime - swiperDynamicStartTime) * oneThousand); + } else { + swiperFrameLossRate = -1; + } + + if (appTabsDynamicStartTime != 0 && appTabsDynamicFinishTime != 0) { + tabsFrameLossRate = (frameLossTabsTime / (appTabsDynamicFinishTime - appTabsDynamicStartTime) * oneThousand); + } else { + tabsFrameLossRate = -1; + } + LOGD("result.appFrameLossRate: (%s), result.swiperFrameLossRate: (%s), result.tabsFrameLossRate: (%s)", + std::to_string(appFrameLossRate).c_str(), + std::to_string(swiperFrameLossRate).c_str(), + std::to_string(tabsFrameLossRate).c_str()); +} + +void StallingRateTrace::JudgFrameRate() +{ + auto hasDynamic = [](bool finishTime, bool startTime) { + return finishTime != 0 || startTime != 0; + }; + + bool appListDynamicExists = hasDynamic(appListDynamicFinishTime, appListDynamicStartTime); + bool swiperDynamicExists = hasDynamic(swiperDynamicFinishTime, swiperDynamicStartTime); + bool tabsDynamicExists = hasDynamic(appTabsDynamicFinishTime, appTabsDynamicStartTime); + + if (!appListDynamicExists) { + LOGD("no app list Dynamic"); //û��APP listӾ�� + frameLossRate = swiperDynamicExists ? swiperFrameLossRate : + tabsDynamicExists ? tabsFrameLossRate : -1; + } else if (!swiperDynamicExists) { + LOGD("no swiper Dynamic"); //û��swiper Ӿ�� + frameLossRate = appListDynamicExists ? appFrameLossRate : + tabsDynamicExists ? tabsFrameLossRate : -1; + } else if (!tabsDynamicExists) { + LOGD("no tabs Dynamic"); //û��tabs Ӿ�� + frameLossRate = appListDynamicExists ? appFrameLossRate : + swiperDynamicExists ? swiperFrameLossRate : -1; + } else { + frameLossRate = -1; + } +} + +void StallingRateTrace::MultiLaneFrameRate() +{ + if (appFrameLossRate == 0) { + if (swiperFrameLossRate > 0) { + LOGD("no app list hitchTime"); //û��app list���ٴ��� + frameLossRate = swiperFrameLossRate; + } else if (tabsFrameLossRate > 0) { + frameLossRate = tabsFrameLossRate; + } else { + frameLossRate = 0; + } + } else if (swiperFrameLossRate == 0) { + LOGD("no swiper list hitchTime"); //û��swiper list���ٴ��� + if (appFrameLossRate > 0) { + frameLossRate = appFrameLossRate; + } else if (tabsFrameLossRate > 0) { + frameLossRate = tabsFrameLossRate; + } else { + frameLossRate = 0; + } + } else if (tabsFrameLossRate == 0) { + LOGD("no tabs list hitchTime"); //û��tabs list���ٴ��� + if (appFrameLossRate > 0) { + frameLossRate = appFrameLossRate; + } else if (swiperFrameLossRate > 0) { + frameLossRate = swiperFrameLossRate; + } + } + AddMultiLaneFrameRate(); +} + +void StallingRateTrace::AddMultiLaneFrameRate() +{ + if (appFrameLossRate > 0 && swiperFrameLossRate > 0) { + //app and swiper hitchTime 1 + if (appListDynamicStartTime < swiperDynamicStartTime) { + frameLossRate = appFrameLossRate; + } else { + frameLossRate = swiperFrameLossRate; + } + } else if (appFrameLossRate > 0 && tabsFrameLossRate > 0) { + //app and tabs hitchTime 2 + if (appListDynamicStartTime < appTabsDynamicStartTime) { + frameLossRate = appFrameLossRate; + } else { + frameLossRate = appTabsDynamicStartTime; + } + } else if (tabsFrameLossRate > 0 && swiperFrameLossRate > 0) { + //tabs and swiper hitchTime 3 + if (appTabsDynamicStartTime < swiperDynamicStartTime) { + frameLossRate = tabsFrameLossRate; + } else { + frameLossRate = swiperFrameLossRate; + } + } +} + + +void StallingRateTrace::AppList(const std::string &line, const std::string &signS, const std::string &signF) +{ + if (IsAppLaunchPatternMatched(line)) { + if (listFlag) { + appListDynamicFinishTime = GetTimes(line, signF); + LOGD("AppList line start: (%s), appListDynamicFinishTime: (%s)", + line.c_str(), std::to_string(appListDynamicFinishTime).c_str()); + listFlag = false; + } else { + appListDynamicStartTime = GetTimes(line, signS); + LOGD("AppList line finish: (%s), appListDynamicStartTime: (%s)", + line.c_str(), std::to_string(appListDynamicStartTime).c_str()); + listFlag = true; + frameLossTime = 0; + } + } + if (listFlag) { + GetRsHardWareRate(nowFrameRate, line, SWIM_APPLIST); + if (upperScreenFlag) { + if (line.find("|H:Present Fence ") != std::string::npos) { + fenceId = GetFenceId(line); + LOGD("fenceID:(%d)", fenceId); + } + std::string waitFenceId = "|H:Waiting for Present Fence " + std::to_string(fenceId); + if (line.find(waitFenceId) != std::string::npos) { + nowTime = SPUtilesTye::StringToSometype(StallingRateTrace::GetOnScreenTimeStart(line)); + GetFrameLossTime(nowTime, lastTime, roundTime, frameLossTime); + LOGD("frameLossTime: (%s)", std::to_string(frameLossTime).c_str()); + lastTime = nowTime; + upperScreenFlag = false; + } + } + } +} + +void StallingRateTrace::GetFrameLossTime(double &curTime, double &prevTime, + double &drawTime, double &totalFrameLossTime) +{ + if ((curTime - prevTime) > drawTime && prevTime != 0) { + double diffTime = (curTime - prevTime) - drawTime; + totalFrameLossTime += diffTime; + LOGD("diffTime: (%s), totalFrameLossTime: (%s)", + std::to_string(diffTime).c_str(), std::to_string(totalFrameLossTime).c_str()); + } +} + +void StallingRateTrace::GetRsHardWareRate(double curFrameRate, const std::string &line, SWIM_TYPE type) +{ + if (line.find("H:RSHardwareThread::CommitAndReleaseLayers") != std::string::npos) { + switch (type) { + case SWIM_APPLIST: + upperScreenFlag = true; + break; + case SWIM_APPSWIPER: + upperScreenSwiperFlag = true; + break; + case SWIM_APPTABS: + upperScreenTabsFlag = true; + break; + default: + break; + } + curFrameRate = GetFrameRate(line); + if (curFrameRate != 0) { + UpdateRoundTime(curFrameRate, type); + } + } else if (line.find("H:RSHardwareThread::PerformSetActiveMode setting active mode") != std::string::npos) { + switch (type) { + case SWIM_APPLIST: + upperScreenFlag = true; + break; + case SWIM_APPSWIPER: + upperScreenSwiperFlag = true; + break; + case SWIM_APPTABS: + upperScreenTabsFlag = true; + break; + default: + break; + } + curFrameRate = GetFrameRate(line); + if (curFrameRate != 0) { + UpdateRoundTime(curFrameRate, type); + } + } +} + +void StallingRateTrace::UpdateRoundTime(double curFrameRate, SWIM_TYPE type) +{ + const double kadunNum = 1.5; + const double num = 1; + if (curFrameRate != 0) { + switch (type) { + case SWIM_APPLIST: + roundTime = (num / curFrameRate) * kadunNum; + break; + case SWIM_APPSWIPER: + roundSwiperTime = (num / curFrameRate) * kadunNum; + break; + case SWIM_APPTABS: + roundTabsTime = (num / curFrameRate) * kadunNum; + break; + default: + break; + } + } +} + +void StallingRateTrace::AppSwiperScroll(const std::string &line, const std::string &signS, const std::string &signF) +{ + if (IsAppLaunchPatternMatched(line)) { + if (swiperScrollFlag == 0) { + swiperDynamicStartTime = GetTimes(line, signS); + LOGD("AppSwiperScroll line start: (%s), swiperDynamicStartTime: (%s)", + line.c_str(), std::to_string(swiperDynamicStartTime).c_str()); + frameLossSwiperTime = 0; + swiperScrollFlag = 1; + swiperFlag = true; + } + } + if (IsAppLaunchPatternMatched(line)) { + if (swiperFlingFlag == 1) { + swiperDynamicFinishTime = GetTimes(line, signF); + LOGD("AppSwiper FinishTime line: (%s), swiperDynamicFinishTime: (%s)", + line.c_str(), std::to_string(swiperDynamicFinishTime).c_str()); + swiperFlag = false; + } + if (swiperDynamicFinishTime == 0) { + swiperFlingFlag = 0; + } + swiperFlingFlag++; + } + if (swiperFlag) { + GetRsHardWareRate(nowSwiperFrameRate, line, SWIM_APPSWIPER); + if (upperScreenSwiperFlag) { + if (line.find("|H:Present Fence ") != std::string::npos) { + fenceIdSwiper = GetFenceId(line); + } + std::string waitFenceId = "|H:Waiting for Present Fence " + std::to_string(fenceIdSwiper); + if (line.find(waitFenceId) != std::string::npos) { + nowSwiperTime = SPUtilesTye::StringToSometype(StallingRateTrace::GetOnScreenTimeStart(line)); + GetFrameLossTime(nowSwiperTime, lastSwiperTime, roundSwiperTime, frameLossSwiperTime); + LOGD("nowSwiperTime: (%s), frameLossSwiperTime: (%s)", + std::to_string(nowSwiperTime).c_str(), std::to_string(frameLossSwiperTime).c_str()); + lastSwiperTime = nowSwiperTime; + upperScreenSwiperFlag = false; + } + } + } +} + +void StallingRateTrace::APPTabs(const std::string &line, const std::string &signS, const std::string &signF) +{ + if (IsAppLaunchPatternMatched(line)) { + if (tabsFlag) { + appTabsDynamicFinishTime = GetTimes(line, signF); + LOGD("APPTabs line start: (%s), appTabsDynamicFinishTime: (%s)", + line.c_str(), std::to_string(appTabsDynamicFinishTime).c_str()); + tabsFlag = false; + } else { + appTabsDynamicStartTime = GetTimes(line, signS); + LOGD("APPTabs line finish: (%s), appTabsDynamicStartTime: (%s)", + line.c_str(), std::to_string(appTabsDynamicStartTime).c_str()); + tabsFlag = true; + frameLossTabsTime = 0; + } + } + if (tabsFlag) { + GetRsHardWareRate(nowTabsFrameRate, line, SWIM_APPTABS); + if (upperScreenTabsFlag) { + if (line.find("|H:Present Fence ") != std::string::npos) { + fenceIdTabs = GetFenceId(line); + } + std::string waitFenceId = "|H:Waiting for Present Fence " + std::to_string(fenceIdTabs); + if (line.find(waitFenceId) != std::string::npos) { + nowTabsTime = SPUtilesTye::StringToSometype(GetOnScreenTimeStart(line)); + GetFrameLossTime(nowTabsTime, lastTabsTime, roundTabsTime, frameLossTabsTime); + lastTabsTime = nowTabsTime; + upperScreenTabsFlag = false; + } + } + } +} + +double StallingRateTrace::GetFrameRate(const std::string &line) const +{ + double rate = 0; + std::string delimiter = "rate: "; + if (line.find("now:") != std::string::npos && line.find("rate:") != std::string::npos) { + std::string delimiter1 = ", now:"; + size_t pos1 = line.find(delimiter); + std::string result1 = line.substr(pos1 + delimiter.length()); + size_t pos2 = line.find(delimiter1); + std::string result2 = result1.substr(0, pos2); + rate = SPUtilesTye::StringToSometype(result2.c_str()); + } + if (line.find("rate:") != std::string::npos) { + size_t pos = line.find(delimiter); + std::string result = line.substr(pos + delimiter.length()); + rate = SPUtilesTye::StringToSometype(result.c_str()); + } + return rate; +} + +int StallingRateTrace::GetFenceId(const std::string &line) const +{ + std::string delimiter = "H:Present Fence "; + size_t pos = line.find(delimiter); + std::string result = line.substr(pos + delimiter.length()); + return SPUtilesTye::StringToSometype(result.c_str()); +} + +std::string StallingRateTrace::GetOnScreenTimeStart(const std::string &line) const +{ + size_t subNum = 7; + size_t positionFirst = line.find("...."); + size_t positionSecond = line.find(":"); + return line.substr(positionFirst + subNum, positionSecond - positionFirst - subNum); +} + +double StallingRateTrace::GetTimes(const std::string &line, const std::string &sign) const +{ + size_t positionFirst = line.find("...."); + size_t positionSecond = line.find(":"); + if (positionFirst != std::string::npos && positionSecond != std::string::npos) { + if (line.find(sign) != std::string::npos) { + size_t subNum = 7; + return SPUtilesTye::StringToSometype(line.substr( + positionFirst + subNum, positionSecond - positionFirst - subNum)); + } + } + return 0.0; +} +bool StallingRateTrace::IsAppLaunchPatternMatched(const std::string &line) +{ + static const std::unordered_set appLaunchPatterns = { + "H:LAUNCHER_APP_LAUNCH_FROM_ICON,", + "H:APP_LIST_FLING,", + "H:WEB_LIST_FLING", + "H:ABILITY_OR_PAGE_SWITCH,", + "H:APP_TRANSITION_TO_OTHER_APP,", + "H:LAUNCHER_APP_LAUNCH_FROM_DOCK,", + "H:LAUNCHER_APP_LAUNCH_FROM_APPCENTER,", + "H:APP_SWIPER_NO_ANIMATION_SWITCH", + "H:APP_SWITCH_FRAME_ANIMATION", + "H:APP_SWIPER_SCROLL,", + "H:APP_SWIPER_FLING,", + "H:APP_TABS_NO_ANIMATION_SWITCH", + "H:APP_TABS_FRAME_ANIMATION", + "H:APP_TABS_SCROLL," + }; + for (const auto &keyWords : appLaunchPatterns) { + size_t pos = line.find(keyWords); + if (pos != std::string::npos) { + if (pos > 0 && isspace(line[pos - 1])) { + continue; + } + if (pos + keyWords.length() < line.length() && !isspace(line[pos + keyWords.length()]) && + line[pos + keyWords.length()] != ',') { + continue; + } + if (pos + keyWords.length() < line.length() && (line[pos + keyWords.length()] == ',')) { + return false; + } + LOGD("StallingRateTrace::IsAppLaunchPatternMatched: (%s)", keyWords.c_str()); + return true; + } + } + return false; +} +} +}