• 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     int preFps;
25     std::vector<long long> jitters;
26     std::queue<long long> timeStampQ;
27     long long lastFrameReadyTime;
28     long long currentFpsTime;
ClearFpsInfo29     void Clear()
30     {
31         fps = 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         preFps = 0;
53         lastFrameReadyTime = 0;
54         currentFpsTime = 0;
55     }
56 };
57 class FPS : public SpProfiler {
58 public:
59     void SetPackageName(std::string pName);
60     void SetLayerName(std::string sName);
61     void SetCaptureOn();
62     void SetTraceCatch();
63     std::string CutLayerName(std::string layerName);
64     FpsInfo GetFpsInfo();
65     FpsInfo GetFpsInfoMax();
66     FpsInfo GetFpsInfoResult(FpsInfo &fpsInfo, long long &lastLineTime);
67     void GetLastFpsInfo(FpsInfo &fpsInfo);
68     void GetPrevFpsInfo(FpsInfo &fpsInfo);
69     void InitParams(FpsInfo &fpsInfo, long long &lastLineTime);
70     FpsInfo GetDiffLayersFpsInfo(std::string sName);
71     std::string GetSurface();
72     std::string GetLayer(std::string pkgSurface);
73     FpsInfo fpsInfo;
74     FpsInfo fpsInfoMax;
75     FpsInfo uniteFpsInfo;
76     FpsInfo mFpsInfo;
77     FpsInfo cntFpsInfo;
78     FpsInfo lastFlagFpsInfo; // ������һ��flag
79     FpsInfo prevFlagFpsInfo; // �����ڶ���flag
GetInstance()80     static FPS &GetInstance()
81     {
82         static FPS instance;
83         return instance;
84     }
85     std::map<std::string, std::string> ItemData() override;
86 private:
FPS()87     FPS() {};
88     FPS(const FPS &);
89     FPS &operator = (const FPS &);
90 
91     std::string pkgName;
92     std::string surfaceViewName;
93     std::string curLayerName;
94     bool jump = false;
95     bool refresh = false;
96     int cnt = 0;
97     int zeroNum = 0;
98     int fpsGb = 0;
99     long long mod = 1e9;
100     long long lastReadyTime = -1;
101     long long frameReadyTime = 0;
102     long long lastFrame = -1;
103     int isCatchTrace = 0;
104     int isCapture = 0;
105     FpsInfo GetSurfaceFrame(std::string name);
106 };
107 
108 struct DumpEntity {
109     const std::string windowName;
110     const std::string displayId;
111     const std::string pid;
112     const std::string windId;
113     const std::string zOrd;
114 };
115 
116 }
117 }
118 #endif
119