• 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 #include <thread>
16 #include <iostream>
17 #include <fstream>
18 #include <string>
19 #include <vector>
20 #include <cstdio>
21 #include <sstream>
22 #include <iomanip>
23 #include "include/parse_click_response_trace.h"
24 #include "include/sp_utils.h"
25 namespace OHOS {
26     namespace SmartPerf {
ParseResponseTrace(std::string fileNamePath)27         float ParseClickResponseTrace::ParseResponseTrace(std::string fileNamePath)
28         {
29             int conversion = 1000;
30             infile.open(fileNamePath);
31             if (infile.fail()) {
32                 std::cout << "File " << "open fail" << std::endl;
33                 return 0;
34             } else {
35                 completeTime = SmartPerf::ParseClickResponseTrace::GetLineTime();
36             }
37             infile.close();
38             return completeTime * conversion;
39         }
GetLineTime()40         float ParseClickResponseTrace::GetLineTime()
41         {
42             std::string line;
43             std::string startTime = "0";
44             std::string endTime = "0";
45             std::string appPid = "0";
46             std::string::size_type doComposition;
47             size_t subNum = 5;
48             while (getline(infile, line)) {
49                 appPid = SmartPerf::ParseClickResponseTrace::GetPid(line, "pid", appPid);
50                 startTime = SmartPerf::ParseClickResponseTrace::GetStartTime(line, startTime);
51                 doComposition = line.find("H:RSMainThread::DoComposition");
52                 if (doComposition != std::string::npos) {
53                     size_t position1 = line.find("....");
54                     size_t position2 = line.find(":");
55                     endTime = line.substr(position1 + subNum, position2 - position1 - subNum);
56                     if (std::stof(startTime) == 0) {
57                     } else {
58                         break;
59                     }
60                 }
61             }
62             completeTime = SmartPerf::ParseClickResponseTrace::GetTime(startTime, endTime);
63             return completeTime;
64         }
GetTime(std::string startTime,std::string endTime)65         float  ParseClickResponseTrace::GetTime(std::string startTime, std::string endTime)
66         {
67                 size_t point = endTime.find(".");
68                 float subNum = 2;
69                 endTime = endTime.substr(point - subNum);
70                 startTime = startTime.substr(point - subNum);
71                 if (std::stof(endTime) == 0 || std::stof(startTime) == 0) {
72                 } else {
73                     float displayTime = 0.032;
74                     completeTime = std::stof(endTime) - std::stof(startTime) + displayTime;
75                 }
76                 return completeTime;
77         }
GetPid(std::string line,const std::string & pn,const std::string & pb)78         std::string  ParseClickResponseTrace::GetPid(std::string line, const std::string &pn, const std::string &pb)
79         {
80             std::string appPid;
81             if (appPidnum == 0) {
82                 size_t packageNameNumSize = 5;
83                 std::string::size_type positionPackgeName;
84             if (pn.length() < packageNameNumSize) {
85                 std::string::size_type positionAppspawn;
86                 positionPackgeName = line.find("task_newtask: pid=");
87                 positionAppspawn = line.find("comm=appspawn");
88                 if (positionPackgeName != std::string::npos && positionAppspawn != std::string::npos) {
89                     size_t subNum = 4;
90                     size_t position1 = line.find("pid=");
91                     size_t position2 = line.find(" comm=appspawn");
92                     appPid = line.substr(position1 + subNum, position2 - position1 - subNum);
93                     appPidnum++;
94                 } else {
95                     appPid = pb;
96                 }
97             } else {
98                 positionPackgeName = line.find(pn);
99                 if (positionPackgeName != std::string::npos) {
100                     size_t p1 = line.find(pn);
101                     size_t p2 = line.find(" prio");
102                     appPid = line.substr(p1 + pn.length(), p2 - p1 - pn.length());
103                     appPidnum++;
104                 } else {
105                     appPid = pb;
106                 }
107             }
108             }
109             return appPid;
110         }
GetStartTime(std::string line,const std::string & startTimeBefore)111         std::string  ParseClickResponseTrace::GetStartTime(std::string line, const std::string &startTimeBefore)
112         {
113             std::string::size_type mTouchEventDisPos;
114             std::string::size_type touchEventDisPos;
115             std::string startTime;
116             touchEventDisPos = line.find("H:touchEventDispatch");
117             mTouchEventDisPos = line.find("H:TouchEventDispatch");
118             if (mTouchEventDisPos != std::string::npos || touchEventDisPos != std::string::npos) {
119                 int touchNum = 3;
120                 if (flagTouch <= touchNum) {
121                 size_t position1 = line.find("....");
122                 size_t position2 = line.find(":");
123                 size_t subNum = 5;
124                 startTime = line.substr(position1 + subNum, position2 - position1 - subNum);
125                 flagTime = "0";
126                 flagTouch++;
127                 } else {
128                     startTime = startTimeBefore;
129                 }
130             } else {
131                 startTime = startTimeBefore;
132             }
133             return startTime;
134         }
135     }
136 }