• 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 <iostream>
17 #include <fstream>
18 #include <string>
19 #include <cstring>
20 #include <vector>
21 #include <cstdio>
22 #include <sstream>
23 #include <iomanip>
24 #include <regex>
25 #include <cmath>
26 #include "include/parse_radar.h"
27 #include "include/sp_utils.h"
28 namespace OHOS {
29 namespace SmartPerf {
ParseRadarAppStrart(const std::string & string) const30 std::string ParseRadar::ParseRadarAppStrart(const std::string &string) const
31 {
32     std::ostringstream stream;
33     std::ostringstream streamComplete;
34     std::string animationCompleteTime = ExtractString(string, "\"ANIMATION_LATENCY\":");
35     double completeTime = ParseRadarDelayTime(string, targetComplete, delayTimeComplete);
36     streamComplete << completeTime;
37     double responseTime = ParseRadarDelayTime(string, targetResponse, delayTimeResponse);
38     stream << responseTime;
39     std::string firstFrameDrawnTime = ExtractString(string, "\"FIRST_FRAEM_DRAWN_LATENCY\":");
40     std::string result = "ResponseTime:" + stream.str() +
41         "ms\n"
42         "FirstFrameDrawnTime:" +
43         firstFrameDrawnTime +
44         "ms\n"
45         "AnimationCompleteTime:" +
46         animationCompleteTime +
47         "ms\n"
48         "CompleteTime:" +
49         streamComplete.str() + "ms\n";
50     return result;
51 }
ParseRadarResponse(const std::string & string) const52 double ParseRadar::ParseRadarResponse(const std::string &string) const
53 {
54     double time = -1;
55     time = ParseRadarDelayTime(string, targetResponse, delayTimeResponse);
56     return time;
57 }
58 
ParseRadarDelayTime(const std::string & string,const std::string & target,const int & delayTime) const59 double ParseRadar::ParseRadarDelayTime(const std::string &string, const std::string &target, const int &delayTime) const
60 {
61     std::stringstream ss(string);
62     std::string segment;
63     int maxDelayTime = -1;
64     std::vector<std::string> delayTimeVec;
65     while (getline(ss, segment, '}')) {
66         if (segment.empty()) {
67             continue;
68         }
69         std::string segments = segment.substr(1);
70         std::stringstream ss2(segments);
71         std::string pair;
72         while (getline(ss2, pair, ',')) {
73             std::string key = pair.substr(0, pair.find(':'));
74             std::string value = pair.substr(pair.find(':') + 1);
75             if (key == target) {
76                 delayTimeVec.push_back(value);
77                 maxDelayTime = GetMaxDelayTime(delayTime, delayTimeVec);
78             }
79         }
80     }
81     return static_cast<double>(maxDelayTime);
82 }
GetMaxDelayTime(const int & delayTime,std::vector<std::string> & delayTimeVec) const83 int ParseRadar::GetMaxDelayTime(const int &delayTime, std::vector<std::string> &delayTimeVec) const
84 {
85     int maxNum = -1;
86     for (size_t i = 0; i < delayTimeVec.size(); i++) {
87         int num = SPUtilesTye::StringToSometype<int>(delayTimeVec[i]);
88         if (num < delayTime && num > maxNum) {
89             maxNum = num;
90         }
91     }
92     return maxNum;
93 }
ParseRadarComplete(const std::string & string) const94 double ParseRadar::ParseRadarComplete(const std::string &string) const
95 {
96     double time = -1;
97     time = ParseRadarDelayTime(string, targetComplete, delayTimeComplete);
98     return time;
99 }
ParseRadarMaxFrame(const std::string & string) const100 std::string ParseRadar::ParseRadarMaxFrame(const std::string &string) const
101 {
102     std::string maxRenderSeqMissedFrames = ExtractString(string, "\"MAX_RENDER_SEQ_MISSED_FRAMES\":");
103     std::string result = "MAX_RENDER_SEQ_MISSED_FRAMES:" + maxRenderSeqMissedFrames;
104     return result;
105 }
ParseRadarFrame(const std::string & string) const106 std::string ParseRadar::ParseRadarFrame(const std::string &string) const
107 {
108     std::string budleName = ExtractString(string, "\"BUNDLE_NAME_EX\":");
109     std::cout << "BUNDLE_NAME:" << budleName << std::endl;
110     std::string sceneId = ExtractString(string, "\"SCENE_ID\":");
111     std::cout << "SCENE_ID:" << sceneId << std::endl;
112     std::string totalAppFrames = ExtractString(string, "\"TOTAL_APP_FRAMES\":");
113     std::cout << "TOTAL_APP_FRAMES:" << totalAppFrames << std::endl;
114     std::string totalAppMissedFrames = ExtractString(string, "\"TOTAL_APP_MISSED_FRAMES\":");
115     std::cout << "TOTAL_APP_MISSED_FRAMES:" << totalAppMissedFrames << std::endl;
116     std::string maxAppFramsestime = ExtractString(string, "\"MAX_APP_FRAMETIME\":");
117     std::cout << "MAX_APP_FRAMETIME:" << maxAppFramsestime << "ms" << std::endl;
118     std::string maxAppSeqMissedFrames = ExtractString(string, "\"MAX_APP_SEQ_MISSED_FRAMES\":");
119     std::cout << "MAX_APP_SEQ_MISSED_FRAMES:" << maxAppSeqMissedFrames << std::endl;
120     std::string totalRenderFrames = ExtractString(string, "\"TOTAL_RENDER_FRAMES\":");
121     std::cout << "TOTAL_RENDER_FRAMES:" << totalRenderFrames << std::endl;
122     std::string totalRenderMissedFrames = ExtractString(string, "\"TOTAL_RENDER_MISSED_FRAMES\":");
123     std::cout << "TOTAL_RENDER_MISSED_FRAMES:" << totalRenderMissedFrames << std::endl;
124     std::string maxRenderFrametime = ExtractString(string, "\"MAX_RENDER_FRAMETIME\":");
125     std::cout << "MAX_RENDER_FRAMETIME:" << maxRenderFrametime << "ms" << std::endl;
126     std::string averageRenderFrametime = ExtractString(string, "\"AVERAGE_RENDER_FRAMETIME\":");
127     std::cout << "AVERAGE_RENDER_FRAMETIME:" << averageRenderFrametime << "ms" << std::endl;
128     std::string maxRenderSeqMissedFrames = ExtractString(string, "\"MAX_RENDER_SEQ_MISSED_FRAMES\":");
129     std::cout << "MAX_RENDER_SEQ_MISSED_FRAMES:" << maxRenderSeqMissedFrames << std::endl;
130     std::string result = "";
131     return result;
132 }
ExtractString(const std::string & str,const std::string & target) const133 std::string ParseRadar::ExtractString(const std::string &str, const std::string &target) const
134 {
135     size_t pos = str.find(target);
136     if (pos != std::string::npos) {
137         pos += target.length();
138         size_t commaPos = str.find(",", pos);
139         if (commaPos != std::string::npos) {
140             std::string result = str.substr(pos, commaPos - pos);
141             return result;
142         }
143     }
144 
145     return "-1";
146 }
147 }
148 }