• 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 #ifndef PLUGNFPS_H
16 #define PLUGNFPS_H
17 #include <vector>
18 #include "sp_profiler.h"
19 #include <queue>
20 namespace OHOS {
21 namespace SmartPerf {
22 struct DumpEntityProfiler {
23     const std::string windowName;
24     const std::string displayId;
25     const std::string pid;
26     const std::string windId;
27     const std::string zOrd;
28 };
29 struct FpsInfoProfiler {
30     int fps;
31     int preFps;
32     std::vector<long long> jitters;
33     std::queue<long long> timeStampQ;
34     long long lastFrameReadyTime;
35     long long currentFpsTime;
36     std::vector<long long> currTimeStamps;
ClearFpsInfoProfiler37     void Clear()
38     {
39         fps = 0;
40         jitters.clear();
41     }
42     bool operator==(const FpsInfoProfiler& other) const
43     {
44         if (fps != other.fps) {
45             return false;
46         }
47         if (jitters.size() != other.jitters.size()) {
48             return false;
49         }
50         for (size_t i = 0; i < jitters.size(); i++) {
51             if (jitters[i] != other.jitters[i]) {
52                 return false;
53             }
54         }
55         return true;
56     }
FpsInfoProfilerFpsInfoProfiler57     FpsInfoProfiler()
58     {
59         fps = 0;
60         preFps = 0;
61         lastFrameReadyTime = 0;
62         currentFpsTime = 0;
63     }
64 };
65 class ProfilerFPS {
66 public:
67     void GetSectionsFps(FpsInfoProfiler &fpsInfo);
68     void GetSectionsPrint(int printCount, long long msStartTime);
69     void GetTimeDiff();
70     std::string CutLayerName(std::string layerName);
71     FpsInfoProfiler GetFpsInfo();
72     FpsInfoProfiler GetFpsInfoMax();
73     FpsInfoProfiler GetFpsInfoResult(FpsInfoProfiler &fpsInfo, long long &lastLineTime);
74     void GetLastFpsInfo(FpsInfoProfiler &fpsInfo);
75     void GetPrevFpsInfo(FpsInfoProfiler &fpsInfo);
76     void InitParams(FpsInfoProfiler &fpsInfo, long long &lastLineTime);
77     void GetResultFPS(int sectionsNum);
78     std::string GetSurface();
79     std::string GetLayer();
80     FpsInfoProfiler fpsInfo;
81     FpsInfoProfiler fpsInfoMax;
82     FpsInfoProfiler uniteFpsInfo;
83     FpsInfoProfiler mFpsInfo;
84     FpsInfoProfiler cntFpsInfo;
85     FpsInfoProfiler lastFlagFpsInfo;
86     FpsInfoProfiler prevFlagFpsInfo;
87     void GetFPS(int argc, std::vector<std::string> v);
88 private:
89     std::string pkgName;
90     std::string surfaceViewName;
91     std::string curLayerName;
92     bool jump = false;
93     bool refresh = false;
94     int cnt = 0;
95     int zeroNum = 0;
96     int fpsGb = 0;
97     long long mod = 1e9;
98     long long lastReadyTime = -1;
99     long long frameReadyTime = 0;
100     long long lastFrame = -1;
101     long long currTimeDiff;
102     long long currRealTime;
103     const int paramFourteen = 14;
104     const int paramTwentyFour = 24;
105     const int paramThree = 3;
106     const int windowNameIndex = 0;
107     const int windowIdIndex = 3;
108     const int focusNameIndex = 2;
109     long long lastCurrTime = 0;
110     int num = 1;
111     int number = 2;
112     int four = 4;
113     unsigned long oneSec = 1000000;
114     long long msClear = 1000000000;
115     long long oneThousand = 1000;
116     int ten = 10;
117     FpsInfoProfiler GetSurfaceFrame(std::string name);
118 };
119 }
120 }
121 #endif