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 std::vector<long long> currDumpTimeStamps; 27 int curTime; 28 long long currTimeDiff; 29 long long currTimeDump; ClearFpsInfoProfiler30 void Clear() 31 { 32 fps = 0; 33 jitters.clear(); 34 currTimeDiff = 0; 35 currTimeDump = 0; 36 } 37 bool operator == (const FpsInfoProfiler &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 } FpsInfoProfilerFpsInfoProfiler52 FpsInfoProfiler() 53 { 54 fps = 0; 55 curTime = 0; 56 currTimeDiff = 0; 57 currTimeDump = 0; 58 } 59 }; 60 class ProfilerFPS : public SpProfiler { 61 public: 62 void SetTraceCatch(); 63 void SetGameLayer(std::string isGameView); 64 std::string GetGameLayer(); 65 std::string GetLayerName(std::string &gameLayer, uint64_t &nodeId, std::string &line, size_t &endPos); 66 void SetPackageName(std::string pName); 67 void GetFPS(std::vector<std::string> v); 68 void GetResultFPS(int sectionsNum); 69 FpsInfoProfiler GetFpsInfo(); 70 bool CalcFpsAndJitters(bool isBreak); 71 long long CalculateJitter(); 72 FpsInfoProfiler GetSurfaceFrame(const std::string& name); 73 FpsInfoProfiler GetFrameInfoFromMap(const std::string& name); 74 void ResetFpsInfo(); 75 void PrintSections(int msCount, long long currTimeLast, long long currTimeStart, long long currLastTime) const; 76 void GetSectionsFps(FpsInfoProfiler &fpsInfoResult, int nums) const; 77 void GetSectionsPrint(int printCount, long long msStartTime, int numb, long long harTime) const; 78 void GetTimeDiff(); 79 void GetOhFps(std::vector<std::string> v); 80 void SetRkFlag(); 81 std::string GetSurface(); 82 FpsInfoProfiler fpsInfo; 83 FpsInfoProfiler fpsInfoTime; 84 FpsInfoProfiler lastFpsInfoResult; 85 static inline bool firstDump = false; 86 static inline bool isGameApp = false; 87 FpsInfoProfiler GetChangedLayerFps(); 88 FpsInfoProfiler GetAppFps(std::string &uniteLayer); GetInstance()89 static ProfilerFPS &GetInstance() 90 { 91 static ProfilerFPS instance; 92 return instance; 93 } 94 std::map<std::string, std::string> ItemData() override; 95 void SetProcessId(const std::string &pid); 96 static inline bool isLowCurFps = false; 97 void CalcJitters(); 98 private: ProfilerFPS()99 ProfilerFPS() {}; 100 ProfilerFPS(const ProfilerFPS &); 101 ProfilerFPS &operator = (const ProfilerFPS &); 102 103 std::string pkgName; 104 int num = 1; 105 int number = 2; 106 bool refresh = false; 107 long long mod = 1e9; 108 long long prevlastScreenTimestamp = 0; 109 long long curScreenTimestamp = 0; 110 long long prevScreenTimestamp = -1; 111 int fpsNum = 0; 112 bool isFirstResult = false; 113 long oneSec = 1000000; 114 unsigned long sleepTime = 950000; 115 unsigned long sleepNowTime = 10000; 116 int ten = 10; 117 int four = 4; 118 int fifty = 50; 119 long long lastCurrTime = 0; 120 long long oneThousand = 1000; 121 long long msClear = 1000000000; 122 long long currRealTime = 0; 123 int isCatchTrace = 0; 124 std::string isGameLayer = ""; 125 bool processFlag = false; 126 bool ohFlag = false; 127 std::string processId = ""; 128 bool rkFlag = false; 129 std::string gameLayerName; 130 bool isSections = true; 131 }; 132 } 133 } 134 #endif