• 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 FPS_H
16 #define FPS_H
17 #include <vector>
18 #include <queue>
19 #include "sp_profiler.h"
20 namespace OHOS {
21 namespace SmartPerf {
22 struct FpsInfo {
23     int fps;
24     std::vector<long long> jitters;
25     std::vector<long long> currTimeStamps;
26     std::vector<long long> currDumpTimeStamps;
27     int curTime;
28     long long currTimeDiff;
29     long long currTimeDump;
ClearFpsInfo30     void Clear()
31     {
32         fps = 0;
33         curTime = 0;
34         currTimeDiff = 0;
35         jitters.clear();
36     }
37     bool operator == (const FpsInfo &other) const
38     {
39         if (fps != other.fps) {
40             return false;
41         }
42         if (jitters.size() != other.jitters.size()) {
43             return false;
44         }
45         for (size_t i = 0; i < jitters.size(); i++) {
46             if (jitters[i] != other.jitters[i]) {
47                 return false;
48             }
49         }
50         return true;
51     }
FpsInfoFpsInfo52     FpsInfo()
53     {
54         fps = 0;
55         curTime = 0;
56         currTimeDiff = 0;
57         currTimeDump = 0;
58     }
59 };
60 struct FpsCurrentFpsTime {
61     int fps = 0;
62     long long currentFpsTime = 0;
63 };
64 
65 class FPS : public SpProfiler {
66 public:
67     void SetPackageName(const std::string& pName);
68     void SetLayerName(const std::string& sName);
69     FpsInfo GetFpsInfo();
70     FpsInfo GetDiffLayersFpsInfo(const std::string &sName);
71     FpsInfo GetChangedLayerFps();
72     bool CalcFpsAndJitters(bool isBreak);
73     long long CalculateJitter() const;
74     FpsInfo fpsInfo;
75     FpsInfo fpsInfoData;
76     FpsInfo prevResultFpsInfo;
GetInstance()77     static FPS &GetInstance()
78     {
79         static FPS instance;
80         return instance;
81     }
82     std::map<std::string, std::string> ItemData() override;
83     void StartExecutionOnce(bool isPause) override;
84     void SetFpsCurrentFpsTime(FpsInfo fpsInfoResult);
85     FpsCurrentFpsTime GetFpsCurrentFpsTime();
86     void ReadDataFromPipe(int fd);
87     void SetProcessId(const std::string &pid);
88     void SetRkFlag();
89     std::string FindFpsRefreshrate();
90     std::string GetHardenRefreshrate(std::string &screenInfo) const;
91     void CalcJitters();
92     static inline bool isGameApp = false;
93     static inline bool isNeedDump = false;
94     static inline bool isPreset = false;
95     static inline bool isLowCurFps = false;
96     static inline bool isHistoryHap = false;
97     bool SetOtherDeviceFlag();
98     bool hapLowFpsFlag = false;
99     bool hapNeedCatonInfo = false;
100     int catonNum = 0;
101     void CalcFatalCaton(std::vector<long long>& jitters);
102     void GetGameScenStatus();
103     FpsInfo GetFpsInfoByDump(const std::string& name);
104     FpsInfo GetFpsInfoByRs(const std::string& name);
105     std::map<std::string, std::string> GetFpsAndJitters(FpsInfo &fpsInfoResult,
106         std::map<std::string, std::string> &result);
107     void SetTraceCatch();
108     std::string GetGameLayer();
109     std::string GetLayerName(std::string &gameLayer, uint64_t &nodeId, const std::string& line, size_t &endPos);
110     std::string GetSurfaceId(std::string &gameLayer, uint64_t &nodeId, const std::string &surfaceId,
111         const std::string& line, size_t &endPos);
112     FpsInfo GetAppFps(std::string &uniteLayer);
113 
114     // sections
115     void GetOhFps(std::vector<std::string>& v);
116     void GetTimeDiff();
117     void GetResultFPS(int sectionsNum);
118     void GetSectionsFps(FpsInfo &fpsInfoResult, int nums) const;
119     void PrintSections(int msCount, long long currTimeLast, long long currTimeStart, long long currLastTime) const;
120     void GetSectionsPrint(int printCount, long long msStartTime, int numb, long long harTime) const;
121     void GetFPS(std::vector<std::string>& v);
122 private:
FPS()123     FPS() {};
124     FPS(const FPS &);
125     FPS &operator = (const FPS &);
126 
127     std::string pkgName;
128     std::string surfaceViewName;
129     bool refresh = false;
130     long long mod = 1e9;
131     long long curScreenTimestamp = 0;
132     long long prevScreenTimestamp = -1;
133     long long prevlastScreenTimestamp = 0;
134     int fpsNum = 0;
135     FpsInfo GetSurfaceFrame(const std::string& name);
136     int fifty = 50;
137     int hundred = 100;
138     FpsCurrentFpsTime ffTime;
139     bool processFlag = false;
140     bool rkFlag = false;
141     const std::string screenPath = "/sys/class/graphics/fb0/lcd_fps_scence";
142     std::string processId = "";
143     std::string gameLayerName;
144     bool isOtherDevice = false;
145     int inGameSceneNum = 0;
146     int eleven = 11;
147 
148     int num = 1;
149     int number = 2;
150     bool ohFlag = false;
151     int four = 4;
152     int ten = 10;
153     long long lastCurrTime = 0;
154     long long msClear = 1000000000;
155     long oneSec = 1000000;
156     long long oneThousand = 1000;
157     long long currRealTime = 0;
158     unsigned long sleepTime = 950000;
159     unsigned long sleepNowTime = 10000;
160 
161     bool isSections = false;
162     int isCatchTrace = 0;
163     std::string nodeIdStr = "";
164 };
165 }
166 }
167 #endif
168