• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 Huawei Device Co., Ltd.
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 
16 
17 #include <fstream>
18 #include <string>
19 #include "include/parse_page_fps_trace.h"
20 namespace OHOS {
21     namespace SmartPerf {
ParsePageFpsTrace(std::string file)22         double PageFpsTrace::ParsePageFpsTrace(std::string file)
23         {
24             double fps = -1.0;
25             infile.open(file);
26             if (infile.fail()) {
27                 std::cout << "file open fail:" << file << std::endl;
28                 return fps;
29             } else {
30                 fps = SmartPerf::PageFpsTrace::CalculateTime();
31             }
32             return fps;
33         }
CalculateTime()34         double PageFpsTrace::CalculateTime()
35         {
36             std::string line;
37             while (getline(infile, line)) {
38                 if (line.find("H:touchEventDispatch") != std::string::npos) {
39                     startLine = line;
40                     needUpdateResponseLine = true;
41                     frameNum = 0;
42                 } else if (line.find("H:RSMainThread::DoComposition") != std::string::npos) {
43                     updateCount = true;
44                     count = 0;
45                     pid = SmartPerf::PageFpsTrace::CutString(line, "B|", "|H:RSMainThread::DoComposition", 2);
46                     frameNum++;
47                     if(needUpdateResponseLine) {
48                         responseLine = line;
49                         needUpdateResponseLine = false;
50                     }
51                     frameStartTime = std::stod(SmartPerf::PageFpsTrace::getLineTime(line));
52                 }
53                 if (updateCount) {
54                     if (line.find("B|" + pid + "|") != std::string::npos && line.find("-" + pid) != std::string::npos) {
55                         count++;
56                     } else if (line.find("E|" + pid + "|") != std::string::npos && line.find("-" + pid) != std::string::npos) {
57                         count--;
58                     }
59                     if (count == 0) {
60                         completeLine = line;
61                         frameStartInterval = frameEndTime;
62                         frameStartInterval = 0;
63                         frameEndTime = std::stod(SmartPerf::PageFpsTrace::getLineTime(completeLine));
64                         updateCount = false;
65                     }
66                 }
67                 if (frameStartInterval != 0) {
68                     double frameInterval = frameStartTime - frameStartInterval;
69                     if (frameInterval > 0.05) {
70                         std::cout<<"NO."<< frameNum <<"fps Time: "<< frameInterval << "s" <<std::endl;
71                     }
72                 }
73             }
74             if (startLine.compare("") == 0) {
75                 std::cout << "can not find start point {H:touchEventDispatch}" << std::endl;
76             } else if (completeLine.compare("") == 0) {
77                 std::cout << "can not find response and complete point {H:RSMainThread::DoComposition}" << std::endl;
78             } else {
79                 double responseTime = std::stod(SmartPerf::PageFpsTrace::getLineTime(responseLine));
80                 double completeTime = std::stod(SmartPerf::PageFpsTrace::getLineTime(completeLine));
81                 return frameNum / (completeTime - responseTime);
82             }
83             return -1.0;
84         }
getLineTime(std::string line)85         std::string PageFpsTrace::getLineTime(std::string line)
86         {
87             size_t num = 7;
88             size_t position1 = line.find("....");
89             size_t position2 = line.find(":");
90             return line.substr(position1 + num, position2 - position1 -num);
91         }
CutString(std::string line,std::string start,std::string end,size_t offset)92         std::string PageFpsTrace::CutString(std::string line, std::string start, std::string end, size_t offset)
93         {
94             size_t position1 = line.find(start);
95             size_t position2 = line.find(end);
96             return line.substr(position1 + offset, position2 - position1 -offset);
97         }
98     }
99 }