• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) Huawei Technologies Co., Ltd. 2023. All rights reserved.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #include <string>
16 #include <iostream>
17 #include <regex>
18 #include "include/parse_slide_fps_trace.h"
19 #include "include/sp_log.h"
20 #include "include/sp_utils.h"
21 
22 namespace OHOS {
23 namespace SmartPerf {
ParseSlideFpsTraceNoh(const std::string & file)24 double ParseSlideFpsTrace::ParseSlideFpsTraceNoh(const std::string& file)
25 {
26     double fps = -1.0;
27     char realPath[PATH_MAX] = {0x00};
28     if ((realpath(file.c_str(), realPath) == nullptr)) {
29         std::cout << "" << std::endl;
30     }
31     infile.open(realPath);
32     if (infile.fail()) {
33         LOGE("ParseSlideFpsTrace open file(%s) fialed ", file.c_str());
34         return fps;
35     }
36     fps = SmartPerf::ParseSlideFpsTrace::CalculateTime();
37     infile.close();
38     return fps;
39 }
40 
CalculateTime()41 double ParseSlideFpsTrace::CalculateTime()
42 {
43     std::string line;
44     int two = 2;
45     while (getline(infile, line)) {
46         if (line.find("H:touchEventDispatch") != std::string::npos) {
47             count++;
48             if (count == four) {
49                 needTime = true;
50                 frameNow = 0;
51                 touchTime = SPUtilesTye::StringToSometype<double>(ParseSlideFpsTrace::GetLineTime(line));
52                 LOGD("ParseSlideFpsTrace::touchTime: (%s)", std::to_string(touchTime).c_str());
53                 swiperFlingFlag = 0;
54             }
55         } else if (line.find("H:RSMainThread::DoComposition") != std::string::npos) {
56             frameNow++;
57             doCompositionTime = SPUtilesTye::StringToSometype<double>(ParseSlideFpsTrace::GetLineTime(line));
58             LOGD("ParseSlideFpsTrace::doCompositionTime: (%s)", std::to_string(doCompositionTime).c_str());
59         } else if (line.find("H:WEB_LIST_FLING") != std::string::npos ||
60             line.find("H:APP_LIST_FLING,") != std::string::npos) {
61             listFlag++;
62             if (listFlag == two) {
63                 completeTime = doCompositionTime;
64                 frameNum = frameNow;
65                 LOGD("ParseSlideFpsTrace::completeTime: (%s), ParseSlideFpsTrace::frameNum: (%d)",
66                     std::to_string(completeTime).c_str(), frameNum);
67                 break;
68             }
69         }
70         AppSwiperScroll(line);
71     }
72     if (completeTime == 0 || responseTime == 0) {
73         return -1;
74     } else {
75         double fps = 0;
76         if ((completeTime - responseTime) > 0) {
77             fps = (frameNum - 1) / (completeTime - responseTime);
78         } else {
79             fps = 0;
80         }
81         double flagNum = 120;
82         double flagNumb = 121;
83         if (fps > flagNum && fps < flagNumb) {
84             fps = flagNum;
85         }
86         return fps;
87     }
88     return -1.0;
89 }
90 
AppSwiperScroll(const std::string & line)91 void ParseSlideFpsTrace::AppSwiperScroll(const std::string& line)
92 {
93     if (line.find("H:APP_SWIPER_SCROLL,") != std::string::npos) {
94         if (swiperScrollFlag == 0) {
95             touchTime = SPUtilesTye::StringToSometype<double>(ParseSlideFpsTrace::GetLineTime(line));
96             LOGD("AppSwiperScroll.touchTime: (%s)", std::to_string(touchTime).c_str());
97             needTime = true;
98             swiperScrollFlag = 1;
99         }
100     }
101     if (line.find("H:APP_SWIPER_FLING,") != std::string::npos) {
102         if (swiperFlingFlag == 1) {
103             completeTime = doCompositionTime;
104             frameNum = frameNow;
105             LOGD("AppSwiperScroll.completeTime: (%s), AppSwiperScroll.frameNum: (%d)",
106                 std::to_string(completeTime).c_str(), frameNum);
107         }
108         swiperFlingFlag++;
109     }
110     if (touchTime != 0 && (doCompositionTime - touchTime) > completionTime && needTime) {
111         frameNow = 1;
112         needTime = false;
113         responseTime = doCompositionTime;
114         LOGD("AppSwiperScroll.responseTime: (%s)", std::to_string(responseTime).c_str());
115     }
116 }
117 
GetLineTime(const std::string & lineStr) const118 std::string ParseSlideFpsTrace::GetLineTime(const std::string& lineStr) const
119 {
120     size_t num = 7;
121     size_t position1 = lineStr.find("....");
122     size_t position2 = lineStr.find(":");
123     return lineStr.substr(position1 + num, position2 - position1 - num);
124 }
CutString(const std::string & lineStr,const std::string & start,const std::string & end,size_t offset) const125 std::string ParseSlideFpsTrace::CutString(const std::string& lineStr, const std::string &start,
126     const std::string &end, size_t offset) const
127 {
128     size_t position1 = lineStr.find(start);
129     size_t position2 = lineStr.find(end);
130     return lineStr.substr(position1 + offset, position2 - position1 - offset);
131 }
132 }
133 }
134