1 /* 2 * Copyright (c) 2022-2024 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 16 #ifndef ROSEN_MODULE_RS_FRAME_REPORT_H 17 #define ROSEN_MODULE_RS_FRAME_REPORT_H 18 19 #include <mutex> 20 #include <string> 21 #include <unordered_map> 22 23 namespace OHOS { 24 namespace Rosen { 25 26 enum class FrameSchedEvent { 27 SCHED_EVENT_BASE = 0, 28 INIT = 1, 29 RS_RENDER_START = 10001, 30 RS_RENDER_END = 10002, 31 RS_UNI_RENDER_START = 10003, 32 RS_UNI_RENDER_END = 10004, 33 RS_HARDWARE_START = 10005, 34 RS_HARDWARE_END = 10006, 35 RS_HARDWARE_INFO = 10007, 36 RS_BUFFER_COUNT = 10008, 37 RS_FRAME_DEADLINE = 10009, 38 RS_UNBLOCK_MAINTHREAD = 10010, 39 RS_POST_AND_WAIT = 10011, 40 RS_BEGIN_FLUSH = 10012, 41 RS_BLUR_PREDICT = 10013, 42 RS_UNMARSHAL_DATA = 10014, 43 RS_DDGR_TASK = 10017, 44 GPU_SCB_SCENE_INFO = 40001, 45 SCHED_EVENT_MAX, 46 }; 47 48 using InitFunc = void (*)(); 49 using FrameGetEnableFunc = int (*)(); 50 using ReportSchedEventFunc = void (*)(FrameSchedEvent, const std::unordered_map<std::string, std::string>&); 51 using SendCommandsStartFunc = void(*)(); 52 using SetFrameParamFunc = void(*)(int, int, int, int); 53 54 class RsFrameReport final { 55 public: 56 static RsFrameReport& GetInstance(); 57 void Init(); 58 int GetEnable(); 59 void ReportSchedEvent(FrameSchedEvent event, const std::unordered_map<std::string, std::string> &payload); 60 void SendCommandsStart(); 61 void SetFrameParam(int requestId, int load, int schedFrameNum, int value); 62 void RenderStart(uint64_t timestamp, int skipFirstFrame = 0); 63 void RenderEnd(); 64 void DirectRenderEnd(); 65 void UniRenderStart(); 66 void UniRenderEnd(); 67 void CheckUnblockMainThreadPoint(); 68 void CheckPostAndWaitPoint(); 69 void CheckBeginFlushPoint(); 70 void ReportBufferCount(int count); 71 void ReportHardwareInfo(int tid); 72 void ReportFrameDeadline(int deadline, uint32_t currentRate); 73 void ReportUnmarshalData(int unmarshalTid, size_t dataSize); 74 void ReportDDGRTaskInfo(); 75 void ReportScbSceneInfo(const std::string& description, bool eventStatus); 76 77 private: 78 RsFrameReport(); 79 ~RsFrameReport(); 80 bool LoadLibrary(); 81 void CloseLibrary(); 82 void *LoadSymbol(const char *symName); 83 84 void *frameSchedHandle_ = nullptr; 85 bool frameSchedSoLoaded_ = false; 86 87 InitFunc initFunc_ = nullptr; 88 FrameGetEnableFunc frameGetEnableFunc_ = nullptr; 89 ReportSchedEventFunc reportSchedEventFunc_ = nullptr; 90 SendCommandsStartFunc sendCommandsStartFunc_ = nullptr; 91 SetFrameParamFunc setFrameParamFunc_ = nullptr; 92 93 std::mutex reportSchedEventFuncLock_; 94 95 int bufferCount_ = 0; 96 int hardwareTid_ = 0; 97 }; 98 } // namespace Rosen 99 } // namespace OHOS 100 #endif // ROSEN_MODULE_RS_FRAME_REPORT_H 101