• 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 #include <thread>
17 #include <iostream>
18 #include <fstream>
19 #include <string>
20 #include <vector>
21 #include <cstdio>
22 #include <sstream>
23 #include <iomanip>
24 #include "include/parse_start_trace_noh.h"
25 
26 namespace OHOS {
27     namespace SmartPerf {
ParseStartTraceNohe(std::string file)28         double StartTraceNoh::ParseStartTraceNohe(std::string file)
29         {
30             double codeTime = -1.0;
31             infile.open(file);
32             if (infile.fail()) {
33                 std::cout << "file open fail:" << file << std::endl;
34                 return codeTime;
35             } else {
36                 codeTime = SmartPerf::StartTraceNoh::CalculateTime();
37             }
38             return codeTime;
39         }
CalculateTime()40         double StartTraceNoh::CalculateTime()
41         {
42             std::string startLine = "";
43             std::string endLine = "";
44             bool findTouch = false;
45             std::string line;
46             while (getline(infile, line)) {
47                 if (line.find("H:touchEventDispatch") != std::string::npos) {
48                     startLine = line;
49                     findTouch = true;
50                 } else if (findTouch && line.find("H:RSUniRender::Process:[leashWindow") != std::string::npos) {
51                     std::string tmpStr = Split(line, "H:RSUniRender::Process:[leashWindow")[1];
52                     std::string numsStr = CutString(tmpStr, "(", ")", 1);
53                     std::vector<std::string> nums = Split(numsStr, ",");
54                     std::string alpha = Split(tmpStr, "Alpha:")[1];
55                     bool full = stof(nums[0]) == 0 && stof(nums[1]) == 0 && stof(nums[2]) == 1344 && stof(nums[3]) == 2772  ? true : false;
56                     if (full && stof(alpha) == 1) {
57                         endLine = line;
58                         break;
59                     }
60                 }
61             }
62             if (startLine.compare("") == 0) {
63                 std::cout << "can not find start point {H:touchEventDispatch}" << std::endl;
64             } else if (endLine.compare("") == 0) {
65                 std::cout << "can not find complete point {H:RSMainThread::leashWindow}" << std::endl;
66             } else {
67                 double startTime = std::stod(SmartPerf::StartTraceNoh::GetLineTime(startLine));
68                 double endTime = std::stod(SmartPerf::StartTraceNoh::GetLineTime(endLine));
69                 return endTime - startTime;
70             }
71             return -1.0;
72         }
GetLineTime(std::string line)73         std::string StartTraceNoh::GetLineTime(std::string line)
74         {
75             size_t num = 7;
76             size_t position1 = line.find("....");
77             size_t position2 = line.find(":");
78             return line.substr(position1 + num, position2 - position1 - num);
79         }
CutString(std::string line,std::string start,std::string end,size_t offset)80         std::string StartTraceNoh::CutString(std::string line, std::string start, std::string end, size_t offset)
81         {
82             size_t position1 = line.find(start);
83             size_t position2 = line.find(end);
84             return line.substr(position1 + offset, position2 - position1 - offset);
85         }
Split(std::string str,std::string pattern)86         std::vector<std::string> StartTraceNoh::Split(std::string str, std::string pattern)
87         {
88             std::string::size_type pos;
89             std::vector<std::string> result;
90             str += pattern;
91             size_t size = str.size();
92             for (size_t i = 0; i < size; i++) {
93                 pos = str.find(pattern, i);
94                 if (pos < size) {
95                     std::string s = str.substr(i, pos - i);
96                     result.push_back(s);
97                     i = pos + pattern.size() - 1;
98                 }
99             }
100             return result;
101         }
102     }
103 }