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 bool IsForeGround(); 68 bool IsFindForeGround(std::string line) const; 69 void GetSameTimeNums(); 70 void GetCurrentTime(); 71 std::string GetScreenInfo() const; 72 FpsInfo fpsInfo; 73 FpsInfo fpsInfoMax; 74 FpsInfo prevResultFpsInfo; GetInstance()75 static FPS &GetInstance() 76 { 77 static FPS instance; 78 return instance; 79 } 80 std::map<std::string, std::string> ItemData() override; 81 void SetFpsCurrentFpsTime(FpsInfo fpsInfoResult); 82 FpsCurrentFpsTime GetFpsCurrentFpsTime(); 83 84 private: FPS()85 FPS() {}; 86 FPS(const FPS &); 87 FPS &operator = (const FPS &); 88 89 std::string pkgName; 90 std::string surfaceViewName; 91 bool refresh = false; 92 long long mod = 1e9; 93 long long lastReadyTime = -1; 94 long long frameReadyTime = 0; 95 long long lastTime = -1; 96 long long lastFrameReadyTime = 0; 97 int fpsNum = 0; 98 FpsInfo GetSurfaceFrame(std::string name); 99 unsigned long sleepNowTime = 10000; 100 bool isFoundAppName = false; 101 bool isFoundBundleName = false; 102 int fifty = 50; 103 FpsCurrentFpsTime ffTime; 104 }; 105 } 106 } 107 #endif 108