• 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     int curTime;
27     long long currTimeDump;
ClearFpsInfo28     void Clear()
29     {
30         fps = 0;
31         curTime = 0;
32         jitters.clear();
33     }
34     bool operator == (const FpsInfo &other) const
35     {
36         if (fps != other.fps) {
37             return false;
38         }
39         if (jitters.size() != other.jitters.size()) {
40             return false;
41         }
42         for (size_t i = 0; i < jitters.size(); i++) {
43             if (jitters[i] != other.jitters[i]) {
44                 return false;
45             }
46         }
47         return true;
48     }
FpsInfoFpsInfo49     FpsInfo()
50     {
51         fps = 0;
52         curTime = 0;
53         currTimeDump = 0;
54     }
55 };
56 struct FpsCurrentFpsTime {
57     int fps = 0;
58     long long currentFpsTime = 0;
59 };
60 
61 class FPS : public SpProfiler {
62 public:
63     void SetPackageName(std::string pName);
64     void SetLayerName(std::string sName);
65     FpsInfo GetFpsInfo();
66     FpsInfo GetDiffLayersFpsInfo(const std::string &sName);
67     FpsInfo GetChangedLayerFps();
68     bool CalcFpsAndJitters(bool isBreak);
69     long long CalculateJitter() const;
70     FpsInfo fpsInfo;
71     FpsInfo fpsInfoMax;
72     FpsInfo prevResultFpsInfo;
GetInstance()73     static FPS &GetInstance()
74     {
75         static FPS instance;
76         return instance;
77     }
78     std::map<std::string, std::string> ItemData() override;
79     void SetFpsCurrentFpsTime(FpsInfo fpsInfoResult);
80     FpsCurrentFpsTime GetFpsCurrentFpsTime();
81     void ReadDataFromPipe(int fd);
82     void SetProcessId(const std::string &pid);
83     void SetRkFlag();
84     std::string FindFpsRefreshrate();
85     std::string GetHardenRefreshrate(std::string &screenInfo) const;
86     void CalcJitters();
87     static inline bool firstDump = false;
88     static inline bool isGameApp = false;
89     bool SetOtherDeviceFlag();
90 private:
FPS()91     FPS() {};
92     FPS(const FPS &);
93     FPS &operator = (const FPS &);
94 
95     std::string pkgName;
96     std::string surfaceViewName;
97     bool refresh = false;
98     long long mod = 1e9;
99     long long curScreenTimestamp = 0;
100     long long prevScreenTimestamp = -1;
101     long long prevlastScreenTimestamp = 0;
102     int fpsNum = 0;
103     FpsInfo GetSurfaceFrame(std::string name);
104     int fifty = 50;
105     FpsCurrentFpsTime ffTime;
106     bool processFlag = false;
107     bool rkFlag = false;
108     const std::string screenPath = "/sys/class/graphics/fb0/lcd_fps_scence";
109     std::string processId = "";
110     std::string gameLayerName;
111     bool isOtherDevice = false;
112 };
113 }
114 }
115 #endif
116