• 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 #include "include/sp_log.h"
26 namespace OHOS {
27 namespace SmartPerf {
ParseResponseTrace(std::string fileNamePath)28 double ParseClickResponseTrace::ParseResponseTrace(std::string fileNamePath)
29 {
30     int conversion = 1000;
31     char realPath[PATH_MAX] = {0x00};
32     if ((realpath(fileNamePath.c_str(), realPath) == nullptr)) {
33         std::cout << "" << std::endl;
34     }
35     infile.open(realPath);
36     if (infile.fail()) {
37         LOGE("ParseClickResponseTrace open file(%s) fialed ", fileNamePath.c_str());
38         return 0;
39     }
40     completeTime = SmartPerf::ParseClickResponseTrace::GetLineTime();
41     infile.close();
42     return completeTime * conversion;
43 }
GetLineTime()44 double ParseClickResponseTrace::GetLineTime()
45 {
46     std::string line;
47     std::string startTime = "0";
48     std::string endTime = "0";
49     std::string appPid = "0";
50     std::string::size_type doComposition;
51     size_t subNum = 5;
52     while (getline(infile, line)) {
53         appPid = ParseClickResponseTrace::GetPid(line, "pid", appPid);
54         startTime = ParseClickResponseTrace::GetStartTime(line, startTime);
55         doComposition = line.find("H:RSMainThread::DoComposition");
56         if (doComposition != std::string::npos) {
57             size_t position1 = line.find("....");
58             size_t position2 = line.find(":");
59             endTime = line.substr(position1 + subNum, position2 - position1 - subNum);
60             if (SPUtilesTye::StringToSometype<float>(startTime) == 0) {
61             } else {
62                 break;
63             }
64         }
65     }
66     completeTime = ParseClickResponseTrace::GetTime(startTime, endTime);
67     return completeTime;
68 }
GetTime(std::string startTime,std::string endTime)69 double ParseClickResponseTrace::GetTime(std::string startTime, std::string endTime)
70 {
71     size_t point = endTime.find(".");
72     float subNum = 2;
73     endTime = endTime.substr(point - subNum);
74     startTime = startTime.substr(point - subNum);
75     if (SPUtilesTye::StringToSometype<float>(endTime) == 0 || SPUtilesTye::StringToSometype<float>(startTime) == 0) {
76     } else {
77         double displayTime = 0.032;
78         completeTime = SPUtilesTye::StringToSometype<float>(endTime) -
79                         SPUtilesTye::StringToSometype<float>(startTime) + displayTime;
80     }
81     return completeTime;
82 }
GetPid(std::string line,const std::string & pn,const std::string & pb)83 std::string ParseClickResponseTrace::GetPid(std::string line, const std::string &pn, const std::string &pb)
84 {
85     std::string appPid;
86     if (appPidnum == 0) {
87         size_t packageNameNumSize = 5;
88         std::string::size_type positionPackgeName;
89         if (pn.length() < packageNameNumSize) {
90             std::string::size_type positionAppspawn;
91             positionPackgeName = line.find("task_newtask: pid=");
92             positionAppspawn = line.find("comm=appspawn");
93             if (positionPackgeName != std::string::npos && positionAppspawn != std::string::npos) {
94                 size_t subNum = 4;
95                 size_t position1 = line.find("pid=");
96                 size_t position2 = line.find(" comm=appspawn");
97                 appPid = line.substr(position1 + subNum, position2 - position1 - subNum);
98                 appPidnum++;
99             } else {
100                 appPid = pb;
101             }
102         } else {
103             positionPackgeName = line.find(pn);
104             if (positionPackgeName != std::string::npos) {
105                 size_t p1 = line.find(pn);
106                 size_t p2 = line.find(" prio");
107                 appPid = line.substr(p1 + pn.length(), p2 - p1 - pn.length());
108                 appPidnum++;
109             } else {
110                 appPid = pb;
111             }
112         }
113     }
114     return appPid;
115 }
GetStartTime(std::string line,const std::string & startTimeBefore)116 std::string ParseClickResponseTrace::GetStartTime(std::string line, const std::string &startTimeBefore)
117 {
118     std::string startTime;
119     std::string::size_type te = line.find("H:touchEventDispatch");
120     std::string::size_type td = line.find("H:TouchEventDispatch");
121     std::string::size_type pd = line.find("H:PointerEventDispatch");
122     std::string::size_type kd = line.find("H:KeyEventDispatch");
123     std::string::size_type nop = std::string::npos;
124     if (te != nop || td != nop || pd != nop || kd != nop) {
125         int touchNum = 3;
126         if (flagTouch <= touchNum) {
127             size_t position1 = line.find("....");
128             size_t position2 = line.find(":");
129             size_t subNum = 5;
130             startTime = line.substr(position1 + subNum, position2 - position1 - subNum);
131             flagTime = "0";
132             flagTouch++;
133         } else {
134             startTime = startTimeBefore;
135         }
136     } else {
137         startTime = startTimeBefore;
138     }
139     return startTime;
140 }
141 }
142 }