1 /* 2 * Copyright (c) Huawei Technologies Co., Ltd. 2025. 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 16 #ifndef GrPerMonitorReporter_DEFINED 17 #define GrPerMonitorReporter_DEFINED 18 19 #include <ctime> 20 #include <map> 21 #include <set> 22 #include <vector> 23 #include <mutex> 24 25 #include "include/private/SkNoncopyable.h" 26 27 enum COUNTER_TYPE { 28 COUNTER_INVALID_TYPE= -1, 29 COUNTER_FIRST_TYPE, 30 COUNTER_SECOND_TYPE, 31 COUNTER_THIRD_TYPE, 32 COUNTER_FORTH_TYPE, 33 }; 34 enum COUNTER_TIME_LIMIT { 35 COUNTER_MS_FIRST_TYPE = 1000000, 36 COUNTER_MS_SECOND_TYPE = 3000000, 37 COUNTER_MS_THIRD_TYPE = 5000000, 38 COUNTER_MS_FORTH_TYPE = 8000000, 39 }; 40 41 struct TextureEvent { initEventTextureEvent42 void initEvent (int32_t pid, int32_t maxBytes, int32_t budgetedBytes, int64_t allocTime) { 43 fPid = pid; 44 fMaxBytes = maxBytes; 45 fBudgetedBytes = budgetedBytes; 46 fAllocTime = allocTime; 47 } 48 int32_t fPid {0}; 49 int32_t fMaxBytes {0}; 50 int32_t fBudgetedBytes {0}; 51 int64_t fAllocTime {0}; 52 bool fClearCache {false}; 53 }; 54 55 struct BlurEvent { initEventBlurEvent56 void initEvent (int32_t pid, uint16_t filterType, float blurRadius, int32_t width, 57 int32_t height, int64_t blurTime) { 58 fPid = pid; 59 fFilterType = filterType; 60 fBlurRadius = blurRadius; 61 fWidth = width; 62 fHeight = height; 63 fBlurTime = blurTime; 64 } 65 int32_t fPid {0}; 66 uint16_t fFilterType {0}; 67 float fBlurRadius {0.0}; 68 int32_t fWidth {0}; 69 int32_t fHeight {0}; 70 int64_t fBlurTime {0}; 71 }; 72 73 class GrPerfMonitorReporter { 74 public: 75 SK_API static GrPerfMonitorReporter& GetInstance(); 76 77 SK_API std::map<std::string, std::vector<uint16_t>> getTextureStatsData(); 78 79 SK_API std::map<std::string, std::vector<uint16_t>> getBlurStatsData(); 80 81 SK_API std::map<std::string, TextureEvent> getTexturePerfEventData(); 82 83 SK_API std::map<std::string, BlurEvent> getBlurPerfEventData(); 84 85 SK_API std::set<std::string> getStatsCacheData(); 86 87 SK_API void resetPerfEventData(); 88 89 SK_API void resetStatsData(); 90 91 void recordTexturePerfEvent(const std::string& nodeName, 92 int32_t pid, 93 int32_t maxBytes, 94 int32_t budgetedBytes, 95 int64_t allocTime); 96 void recordBlurPerfEvent(const std::string& nodeName, 97 int32_t pid, 98 uint16_t filterType, 99 float blurRadius, 100 int32_t width, 101 int32_t height, 102 int64_t blurTime); 103 104 void recordTextureNode(const std::string& nodeName, int64_t duration); 105 106 void recordBlurNode(const std::string& nodeName, int64_t duration); 107 108 void recordTextureCache(const std::string& nodeName); 109 110 SK_API static int64_t getCurrentTime(); 111 112 SK_API static int16_t getSplitRange(int64_t duration); 113 114 SK_API static bool isOpenPerf(); 115 116 private: 117 bool isClearCacheLastTime(const std::string& nodeName); 118 119 std::map<std::string, std::vector<uint16_t>> fStatsTexture; 120 121 std::map<std::string, std::vector<uint16_t>> fStatsBlur; 122 123 std::map<std::string, TextureEvent> fTextureEvent; 124 125 std::map<std::string, BlurEvent> fBlurEvent; 126 127 std::set<std::string> fStatsCache; 128 129 std::mutex mtx; 130 }; 131 #endif 132