• 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 <cstring>
21 #include <vector>
22 #include <cstdio>
23 #include <sstream>
24 #include <iomanip>
25 #include <regex>
26 #include "include/parse_radar.h"
27 namespace OHOS {
28     namespace SmartPerf {
ParseRadarStart(std::string str)29         double Radar::ParseRadarStart(std::string str)
30         {
31             double time = -1;
32             std::string target = "\"E2E_LATENCY\":";
33             time = std::stod(extract_string(str, target));
34             return time;
35         }
ParseRadarStartResponse(std::string string)36         double Radar::ParseRadarStartResponse(std::string string)
37         {
38             double time = -1;
39             std::string target = "\"RESPONSE_LATENCY\":";
40             time = std::stod(extract_string(string, target));
41             return time;
42         }
ParseRadarAppStrart(std::string string)43         std::string Radar::ParseRadarAppStrart(std::string string)
44         {
45             std::string animationCompleteTime = extract_string(string, "\"ANIMATION_LATENCY\":");
46             std::string completeTime = extract_string(string, "\"E2E_LATENCY\":");
47             std::string responseTime = extract_string(string, "\"RESPONSE_LATENCY\":");
48             std::string firstFrameDrawnTime = extract_string(string, "\"FIRST_FRAEM_DRAWN_LATENCY\":");
49             std::string result = "ResponseTime:" + responseTime + "ms\n"
50             "FirstFrameDrawnTime:" + firstFrameDrawnTime + "ms\n"
51             "AnimationCompleteTime:" + animationCompleteTime + "ms\n"
52             "CompleteTime:" + completeTime + "ms\n";
53             return result;
54         }
ParseRadarResponse(std::string string)55         double Radar::ParseRadarResponse(std::string string)
56         {
57             double time = -1;
58             std::string target = "\"RESPONSE_LATENCY\":";
59             time = std::stod(extract_string(string, target));
60             return time;
61         }
ParseRadarComplete(std::string string)62         double Radar::ParseRadarComplete(std::string string)
63         {
64             double time = -1;
65             std::string target = "\"E2E_LATENCY\":";
66             time = std::stod(extract_string(string, target));
67             return time;
68         }
ParseRadarFrame(std::string string)69         std::string Radar::ParseRadarFrame(std::string string)
70         {
71             std::string budleName = extract_string(string, "\"BUNDLE_NAME_EX\":");
72             std::cout << "BUNDLE_NAME:" << budleName << std::endl;
73             std::string sceneId = extract_string(string, "\"SCENE_ID\":");
74             std::cout << "SCENE_ID:" << sceneId << std::endl;
75             std::string totalAppFrames = extract_string(string, "\"TOTAL_APP_FRAMES\":");
76             std::cout << "TOTAL_APP_FRAMES:" << totalAppFrames << std::endl;
77             std::string totalAppMissedFrames = extract_string(string, "\"TOTAL_APP_MISSED_FRAMES\":");
78             std::cout << "TOTAL_APP_MISSED_FRAMES:" << totalAppMissedFrames << std::endl;
79             std::string maxAppFramsestime = extract_string(string, "\"MAX_APP_FRAMETIME\":");
80             std::cout << "MAX_APP_FRAMETIME:" << maxAppFramsestime << "ms" << std::endl;
81             std::string maxAppSeqMissedFrames = extract_string(string, "\"MAX_APP_SEQ_MISSED_FRAMES\":");
82             std::cout << "MAX_APP_SEQ_MISSED_FRAMES:" << maxAppSeqMissedFrames << std::endl;
83             std::string totalRenderFrames = extract_string(string, "\"TOTAL_RENDER_FRAMES\":");
84             std::cout << "TOTAL_RENDER_FRAMES:" << totalRenderFrames << std::endl;
85             std::string totalRenderMissedFrames = extract_string(string, "\"TOTAL_RENDER_MISSED_FRAMES\":");
86             std::cout << "TOTAL_RENDER_MISSED_FRAMES:" << totalRenderMissedFrames << std::endl;
87             std::string maxRenderFrametime = extract_string(string, "\"MAX_RENDER_FRAMETIME\":");
88             std::cout << "MAX_RENDER_FRAMETIME:" << maxRenderFrametime << "ms" << std::endl;
89             std::string averageRenderFrametime = extract_string(string, "\"AVERAGE_RENDER_FRAMETIME\":");
90             std::cout << "AVERAGE_RENDER_FRAMETIME:" << averageRenderFrametime << "ms" << std::endl;
91             std::string maxRenderSeqMissedFrames = extract_string(string, "\"MAX_RENDER_SEQ_MISSED_FRAMES\":");
92             std::cout << "MAX_RENDER_SEQ_MISSED_FRAMES:" << maxRenderSeqMissedFrames << std::endl;
93             std::string result = "";
94             return result;
95         }
extract_string(const std::string & str,const std::string & target)96         std::string Radar::extract_string(const std::string& str, const std::string& target)
97         {
98             size_t pos = str.find(target);
99             if (pos != std::string::npos) {
100                 pos += target.length();
101                 size_t comma_pos = str.find(",", pos);
102                 if (comma_pos != std::string::npos) {
103                     std::string result = str.substr(pos,comma_pos - pos);
104                     return result;
105                 }
106             }
107 
108             return "-1";
109         }
110     }
111 }