• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) Huawei Technologies Co., Ltd. 2023. All rights reserved.
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 FpsInfoProfiler {
23     int fps;
24     std::vector<long long> jitters;
25     std::vector<long long> currTimeStamps;
26     int curTime;
27     long long currTimeDiff;
28     long long currTimeDump;
ClearFpsInfoProfiler29     void Clear()
30     {
31         fps = 0;
32         jitters.clear();
33         currTimeDiff = 0;
34         currTimeDump = 0;
35     }
36     bool operator == (const FpsInfoProfiler &other) const
37     {
38         if (fps != other.fps) {
39             return false;
40         }
41         if (jitters.size() != other.jitters.size()) {
42             return false;
43         }
44         for (size_t i = 0; i < jitters.size(); i++) {
45             if (jitters[i] != other.jitters[i]) {
46                 return false;
47             }
48         }
49         return true;
50     }
FpsInfoProfilerFpsInfoProfiler51     FpsInfoProfiler()
52     {
53         fps = 0;
54         curTime = 0;
55         currTimeDiff = 0;
56         currTimeDump = 0;
57     }
58 };
59 class ProfilerFPS : public SpProfiler {
60 public:
61     void SetTraceCatch();
62     void SetPackageName(std::string pName);
63     void GetFPS(std::vector<std::string> v);
64     void GetResultFPS(int sectionsNum);
65     FpsInfoProfiler GetFpsInfo();
66     bool IsForeGround();
67     bool IsFindForeGround(std::string line) const;
68     void GetSameTimeNums();
69     FpsInfoProfiler GetSurfaceFrame(std::string name);
70     void GetSectionsFps(FpsInfoProfiler &fpsInfoResult) const;
71     void GetSectionsPrint(int printCount, long long msStartTime) const;
72     void GetTimeDiff();
73     void GetCurrentTime(int sleepNum);
74     FpsInfoProfiler fpsInfo;
75     FpsInfoProfiler fpsInfoMax;
76     FpsInfoProfiler lastFpsInfoResult;
GetInstance()77     static ProfilerFPS &GetInstance()
78     {
79         static ProfilerFPS instance;
80         return instance;
81     }
82     std::map<std::string, std::string> ItemData() override;
83 
84 private:
ProfilerFPS()85     ProfilerFPS() {};
86     ProfilerFPS(const ProfilerFPS &);
87     ProfilerFPS &operator = (const ProfilerFPS &);
88 
89     std::string pkgName;
90     int num = 1;
91     int number = 2;
92     bool refresh = false;
93     long long mod = 1e9;
94     long long lastReadyTime = -1;
95     long long frameReadyTime = 0;
96     long long lastTime = -1;
97     long long lastFrameReadyTime = 0;
98     int fpsNum = 0;
99     bool isFirstResult = false;
100     long oneSec = 1000000;
101     unsigned long sleepTime = 950000;
102     unsigned long sleepNowTime = 10000;
103     int ten = 10;
104     int four = 4;
105     int fifty = 50;
106     long long lastCurrTime = 0;
107     long long oneThousand = 1000;
108     long long msClear = 1000000000;
109     long long currRealTime = 0;
110     bool isFoundAppName = false;
111     bool isFoundBundleName = false;
112     int isCatchTrace = 0;
113 };
114 }
115 }
116 #endif