1 /* 2 * Copyright (c) 2025 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 RENDER_SERVICE_BASE_CORE_COMMON_RS_PERFMONIYOR_LREPORTER_H 16 #define RENDER_SERVICE_BASE_CORE_COMMON_RS_PERFMONIYOR_LREPORTER_H 17 18 #include "common/rs_common_def.h" 19 #include "common/rs_macros.h" 20 #include "pipeline/rs_context.h" 21 #include "utils/perfmonitor_reporter.h" 22 #include <chrono> 23 #include <ctime> 24 #include <mutex> 25 #include <map> 26 #include <queue> 27 28 using std::chrono::high_resolution_clock; 29 using std::chrono::microseconds; 30 using std::chrono::milliseconds; 31 32 namespace OHOS { 33 namespace Rosen { 34 35 enum BLUR_CLEAR_CACHE_REASON { 36 ROTATION_CHANGED = 0, 37 BLUR_REGION_CHANGED, 38 BLUR_CONTENT_CHANGED, 39 DIRTY_OVER_SIZE, 40 SKIP_FRAME_NO_VSYNC, 41 NODE_IS_OCCLUDED, 42 FORCE_CLEAR_CACHE, 43 }; 44 45 class RSB_EXPORT RSPerfMonitorReporter { 46 public: 47 RSB_EXPORT static RSPerfMonitorReporter& GetInstance(); 48 49 // change bundleName when focus changed 50 RSB_EXPORT void SetFocusAppInfo(const char* bundleName); 51 52 // report except event when this frame to be end 53 RSB_EXPORT void ReportAtRsFrameEnd(); 54 55 // record blur except event 56 void RecordBlurPerfEvent(NodeId nodeId, const std::string& nodeName, 57 uint16_t filterType, float blurRadius, int32_t width, int32_t height, 58 int64_t blurTime, bool isBlurType); 59 60 // record blur stats event time >= 1ms 61 void RecordBlurNode(const std::string& nodeName, int64_t duration, bool isBlurType); 62 63 // record blur cache clear reason 64 void RecordBlurCacheReason(const std::string& nodeName, BLUR_CLEAR_CACHE_REASON reason, 65 bool isBlurType); 66 67 void SetCurrentBundleName(const char* bundleName); 68 RSB_EXPORT std::string GetCurrentBundleName(); 69 static bool IsOpenPerf(); 70 71 RSB_EXPORT std::chrono::time_point<high_resolution_clock> StartRendergroupMonitor(); 72 RSB_EXPORT void EndRendergroupMonitor(std::chrono::time_point<high_resolution_clock>& startTime, 73 NodeId& nodeId, const std::shared_ptr<RSContext>& ctx, int updateTimes); 74 // clear rendergroup data map 75 RSB_EXPORT void ClearRendergroupDataMap(NodeId& nodeId); 76 77 protected: 78 // report blur event 79 void ReportBlurStatEvent(); 80 void ReportBlurPerfEvent(); 81 void ReportCacheReasonEvent(); 82 83 // report texture event 84 void ReportTextureStatEvent(); 85 void ReportTexturePerfEvent(); 86 87 // for rendergroup subhealth 88 void ProcessRendergroupSubhealth(NodeId& nodeId, const std::shared_ptr<RSContext>& ctx, int updateTimes, 89 int interval, std::chrono::time_point<high_resolution_clock>& startTime); 90 bool NeedReportSubHealth(NodeId& nodeId, int updateTimes, 91 std::chrono::time_point<high_resolution_clock>& startTime); 92 bool CheckAllDrawingCacheDurationTimeout(NodeId& nodeId); 93 bool MeetReportFrequencyControl(NodeId& nodeId, std::chrono::time_point<high_resolution_clock>& startTime); 94 std::string GetUpdateCacheTimeTaken(NodeId& nodeId); 95 std::string GetInstanceRootNodeName(NodeId& nodeId, const std::shared_ptr<RSContext>& ctx); 96 97 private: 98 std::map<std::string, std::vector<uint16_t>> statsBlur_; 99 std::map<std::string, Drawing::RsBlurEvent> eventBlur_; 100 std::map<std::string, std::vector<uint16_t>> statsReason_; 101 std::string currentBundleName_ = "invalid"; 102 std::mutex mtx_; 103 104 // for rendergroup subhealth 105 std::mutex drawingCacheTimeTakenMapMutex_; 106 std::unordered_map<NodeId, std::vector<int64_t>> drawingCacheTimeTakenMap_; 107 std::mutex drawingCacheLastTwoTimestampMapMutex_; 108 std::unordered_map<NodeId, 109 std::queue<std::chrono::time_point<high_resolution_clock>>> drawingCacheLastTwoTimestampMap_; 110 std::mutex drawingCacheLastReportTimeMapMutex_; 111 std::unordered_map<NodeId, 112 std::chrono::time_point<high_resolution_clock>> drawingCacheLastReportTimeMap_; 113 static inline const std::string RENDERGROUP_SUBHEALTH_EVENT_NAME = "RENDERGROUP_SUBHEALTH_EVENT"; 114 }; 115 116 } // namespace Rosen 117 } // namespace OHOS 118 119 #endif // RENDER_SERVICE_BASE_CORE_COMMON_RS_PERFMONIYOR_LREPORTER_H 120