1 /* 2 * Copyright (c) 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 RENDER_SERVICE_PROFILER_H 17 #define RENDER_SERVICE_PROFILER_H 18 19 #include <memory> 20 #include <unordered_map> 21 22 #include "rs_profiler_test_tree.h" 23 24 #include "common/rs_macros.h" 25 #include "transaction/rs_hrp_service.h" 26 27 #ifdef RS_PROFILER_ENABLED 28 29 #include <map> 30 #include <string> 31 32 #include "recording/draw_cmd_list.h" 33 #include "rs_profiler_capturedata.h" 34 35 #include "common/rs_occlusion_region.h" 36 #include "pipeline/rs_render_node.h" 37 #include "params/rs_screen_render_params.h" 38 #include "recording/draw_cmd_list.h" 39 40 #define RS_PROFILER_INIT(renderSevice) RSProfiler::Init(renderSevice) 41 #define RS_PROFILER_ON_FRAME_BEGIN(syncTime) RSProfiler::OnFrameBegin(syncTime) 42 #define RS_PROFILER_ON_FRAME_END() RSProfiler::OnFrameEnd() 43 #define RS_PROFILER_ON_RENDER_BEGIN() RSProfiler::OnRenderBegin() 44 #define RS_PROFILER_ON_RENDER_END() RSProfiler::OnRenderEnd() 45 #define RS_PROFILER_ON_PROCESS_COMMAND() RSProfiler::OnProcessCommand() 46 #define RS_PROFILER_ON_CREATE_CONNECTION(pid) RSProfiler::OnCreateConnection(pid) 47 #define RS_PROFILER_ON_REMOTE_REQUEST(connection, code, data, reply, option) \ 48 RSProfiler::OnRemoteRequest(connection, code, data, reply, option) 49 #define RS_PROFILER_ON_PARCEL_RECEIVE(parcel, data) RSProfiler::OnRecvParcel(parcel, data) 50 #define RS_PROFILER_COPY_PARCEL(parcel) RSProfiler::CopyParcel(parcel) 51 #define RS_PROFILER_IS_PARCEL_MOCK(parcel) RSProfiler::IsPlaybackParcel(parcel) 52 #define RS_PROFILER_PATCH_NODE_ID(parcel, id) id = RSProfiler::PatchNodeId(parcel, id) 53 #define RS_PROFILER_PATCH_TYPEFACE_GLOBALID(parcel, id) id = RSProfiler::PatchNodeId(parcel, id) 54 #define RS_PROFILER_PATCH_PID(parcel, pid) pid = RSProfiler::PatchPid(parcel, pid) 55 #define RS_PROFILER_PATCH_TIME(time) time = RSProfiler::PatchTime(time) 56 #define RS_PROFILER_PATCH_TRANSACTION_TIME(parcel, time) time = RSProfiler::PatchTransactionTime(parcel, time) 57 #define RS_PROFILER_PATCH_COMMAND(parcel, command) RSProfiler::PatchCommand(parcel, command) 58 #define RS_PROFILER_PUSH_OFFSET(commandOffsets, offset) RSProfiler::PushOffset(commandOffsets, offset) 59 #define RS_PROFILER_PUSH_OFFSETS(parcel, parcelNumber, commandOffsets) \ 60 RSProfiler::PushOffsets(parcel, parcelNumber, commandOffsets) 61 #define RS_PROFILER_EXECUTE_COMMAND(command) RSProfiler::ExecuteCommand(command) 62 #define RS_PROFILER_MARSHAL_PIXELMAP(parcel, map) RSProfiler::MarshalPixelMap(parcel, map) 63 #define RS_PROFILER_UNMARSHAL_PIXELMAP(parcel, readSafeFdFunc) RSProfiler::UnmarshalPixelMap(parcel, readSafeFdFunc) 64 #define RS_PROFILER_SKIP_PIXELMAP(parcel) RSProfiler::SkipPixelMap(parcel) 65 #define RS_PROFILER_MARSHAL_DRAWINGIMAGE(image, compressData) RSProfiler::MarshalDrawingImage(image, compressData) 66 #define RS_PROFILER_SET_DIRTY_REGION(dirtyRegion) RSProfiler::SetDirtyRegion(dirtyRegion) 67 #define RS_PROFILER_WRITE_PARCEL_DATA(parcel) RSProfiler::WriteParcelData(parcel) 68 #define RS_PROFILER_READ_PARCEL_DATA(parcel, size, isMalloc) RSProfiler::ReadParcelData(parcel, size, isMalloc) 69 #define RS_PROFILER_SKIP_PARCEL_DATA(parcel, size) RSProfiler::SkipParcelData(parcel, size) 70 #define RS_PROFILER_GET_FRAME_NUMBER() RSProfiler::GetFrameNumber() 71 #define RS_PROFILER_ON_PARALLEL_RENDER_BEGIN() RSProfiler::OnParallelRenderBegin() 72 #define RS_PROFILER_ON_PARALLEL_RENDER_END(renderFrameNumber) RSProfiler::OnParallelRenderEnd(renderFrameNumber) 73 #define RS_PROFILER_SHOULD_BLOCK_HWCNODE() RSProfiler::ShouldBlockHWCNode() 74 #define RS_PROFILER_ANIME_SET_START_TIME(id, time) RSProfiler::AnimeSetStartTime(id, time) 75 #define RS_PROFILER_REPLAY_FIX_TRINDEX(curIndex, lastIndex) RSProfiler::ReplayFixTrIndex(curIndex, lastIndex) 76 #define RS_PROFILER_PATCH_TYPEFACE_ID(parcel, val) RSProfiler::PatchTypefaceId(parcel, val) 77 #define RS_PROFILER_DRAWING_NODE_ADD_CLEAROP(drawCmdList) RSProfiler::DrawingNodeAddClearOp(drawCmdList) 78 #define RS_PROFILER_KEEP_DRAW_CMD(drawCmdListNeedSync) RSProfiler::KeepDrawCmd(drawCmdListNeedSync) 79 #define RS_PROFILER_PROCESS_ADD_CHILD(parent, child, index) RSProfiler::ProcessAddChild(parent, child, index) 80 #define RS_PROFILER_IF_NEED_TO_SKIP_DRAWCMD_SURFACE(parcel, skipBytes) \ 81 RSProfiler::IfNeedToSkipDuringReplay(parcel, skipBytes) 82 #define RS_PROFILER_RSLOGEOUTPUT(format, argptr) RSProfiler::RSLogOutput(RSProfilerLogType::ERROR, format, argptr) 83 #define RS_PROFILER_RSLOGWOUTPUT(format, argptr) RSProfiler::RSLogOutput(RSProfilerLogType::WARNING, format, argptr) 84 #define RS_PROFILER_RSLOGDOUTPUT(format, argptr) RSProfiler::RSLogOutput(RSProfilerLogType::WARNING, format, argptr) 85 #define RS_PROFILER_RENDERNODE_INC(isOnTree) RSProfiler::MetricRenderNodeInc(isOnTree) 86 #define RS_PROFILER_RENDERNODE_DEC(isOnTree) RSProfiler::MetricRenderNodeDec(isOnTree) 87 #define RS_PROFILER_RENDERNODE_CHANGE(isOnTree) RSProfiler::MetricRenderNodeChange(isOnTree) 88 #define RS_PROFILER_ADD_LIGHT_BLUR_METRICS(area) RSProfiler::AddLightBlursMetrics(area) 89 #define RS_PROFILER_ADD_HPS_BLUR_METRICS(area) RSProfiler::AddHPSBlursMetrics(area) 90 #define RS_PROFILER_ADD_KAWASE_BLUR_METRICS(area) RSProfiler::AddKawaseBlursMetrics(area) 91 #define RS_PROFILER_ADD_MESA_BLUR_METRICS(area) RSProfiler::AddMESABlursMetrics(area) 92 #define RS_PROFILER_LOG_SHADER_CALL(shaderType, srcImage, dstRect, outImage) \ 93 RSProfiler::LogShaderCall(shaderType, srcImage, dstRect, outImage) 94 #define RS_PROFILER_IS_RECORDING_MODE() RSProfiler::IsRecordingMode() 95 #define RS_PROFILER_TRANSACTION_UNMARSHALLING_START(parcel, parcelNumber) \ 96 RSProfiler::TransactionUnmarshallingStart(parcel, parcelNumber) 97 #define RS_PROFILER_ANIMATION_NODE(type, pixels) RSProfiler::AddAnimationNodeMetrics(type, pixels) 98 #define RS_PROFILER_ANIMATION_DURATION_START(id, timestamp_ns) RSProfiler::AddAnimationStart(id, timestamp_ns) 99 #define RS_PROFILER_ANIMATION_DURATION_STOP(id, timestamp_ns) RSProfiler::AddAnimationFinish(id, timestamp_ns) 100 #define RS_PROFILER_SURFACE_ON_DRAW_MATCH_OPTIMIZE(useNodeMatchOptimize) \ 101 RSProfiler::SurfaceOnDrawMatchOptimize(useNodeMatchOptimize) 102 #else 103 #define RS_PROFILER_INIT(renderSevice) 104 #define RS_PROFILER_ON_FRAME_BEGIN(syncTime) 105 #define RS_PROFILER_ON_FRAME_END() 106 #define RS_PROFILER_ON_RENDER_BEGIN() 107 #define RS_PROFILER_ON_RENDER_END() 108 #define RS_PROFILER_ON_PROCESS_COMMAND() 109 #define RS_PROFILER_ON_CREATE_CONNECTION(pid) 110 #define RS_PROFILER_ON_REMOTE_REQUEST(connection, code, data, reply, option) 0 111 #define RS_PROFILER_ON_PARCEL_RECEIVE(parcel, data) 112 #define RS_PROFILER_COPY_PARCEL(parcel) std::make_shared<MessageParcel>() 113 #define RS_PROFILER_IS_PARCEL_MOCK(parcel) false 114 #define RS_PROFILER_PATCH_NODE_ID(parcel, id) 115 #define RS_PROFILER_PATCH_TYPEFACE_GLOBALID(parcel, id) 116 #define RS_PROFILER_PATCH_PID(parcel, pid) 117 #define RS_PROFILER_PATCH_TIME(time) 118 #define RS_PROFILER_PATCH_TRANSACTION_TIME(parcel, time) 119 #define RS_PROFILER_PATCH_COMMAND(parcel, command) 120 #define RS_PROFILER_PUSH_OFFSET(commandOffsets, offset) 121 #define RS_PROFILER_PUSH_OFFSETS(parcel, parcelNumber, commandOffsets) 122 #define RS_PROFILER_EXECUTE_COMMAND(command) 123 #define RS_PROFILER_MARSHAL_PIXELMAP(parcel, map) (map)->Marshalling(parcel) 124 #define RS_PROFILER_UNMARSHAL_PIXELMAP(parcel, readSafeFdFunc) \ 125 Media::PixelMap::UnmarshallingWithIsDisplay(parcel, readSafeFdFunc, true) 126 #define RS_PROFILER_SKIP_PIXELMAP(parcel) false 127 #define RS_PROFILER_MARSHAL_DRAWINGIMAGE(image, compressData) 128 #define RS_PROFILER_SET_DIRTY_REGION(dirtyRegion) 129 #define RS_PROFILER_WRITE_PARCEL_DATA(parcel) 130 #define RS_PROFILER_READ_PARCEL_DATA(parcel, size, isMalloc) RSMarshallingHelper::ReadFromAshmem(parcel, size, isMalloc) 131 #define RS_PROFILER_SKIP_PARCEL_DATA(parcel, size) false 132 #define RS_PROFILER_GET_FRAME_NUMBER() 0 133 #define RS_PROFILER_ON_PARALLEL_RENDER_BEGIN() 134 #define RS_PROFILER_ON_PARALLEL_RENDER_END(renderFrameNumber) 135 #define RS_PROFILER_SHOULD_BLOCK_HWCNODE() false 136 #define RS_PROFILER_ANIME_SET_START_TIME(id, time) time 137 #define RS_PROFILER_REPLAY_FIX_TRINDEX(curIndex, lastIndex) 138 #define RS_PROFILER_PATCH_TYPEFACE_ID(parcel, val) 139 #define RS_PROFILER_DRAWING_NODE_ADD_CLEAROP(drawCmdList) (drawCmdList)->ClearOp() 140 #define RS_PROFILER_KEEP_DRAW_CMD(drawCmdListNeedSync) drawCmdListNeedSync = true 141 #define RS_PROFILER_PROCESS_ADD_CHILD(parent, child, index) false 142 #define RS_PROFILER_IF_NEED_TO_SKIP_DRAWCMD_SURFACE(parcel, skipBytes) false 143 #define RS_PROFILER_SURFACE_ON_DRAW_MATCH_OPTIMIZE(useNodeMatchOptimize) 144 #define RS_PROFILER_RSLOGEOUTPUT(format, argptr) 145 #define RS_PROFILER_RSLOGWOUTPUT(format, argptr) 146 #define RS_PROFILER_RSLOGDOUTPUT(format, argptr) 147 #define RS_PROFILER_RENDERNODE_INC(isOnTree) 148 #define RS_PROFILER_RENDERNODE_DEC(isOnTree) 149 #define RS_PROFILER_RENDERNODE_CHANGE(isOnTree) 150 #define RS_PROFILER_ADD_LIGHT_BLUR_METRICS(area) 151 #define RS_PROFILER_ADD_HPS_BLUR_METRICS(area) 152 #define RS_PROFILER_ADD_KAWASE_BLUR_METRICS(area) 153 #define RS_PROFILER_ADD_MESA_BLUR_METRICS(area) 154 #define RS_PROFILER_LOG_SHADER_CALL(shaderType, srcImage, dstRect, outImage) 155 #define RS_PROFILER_IS_RECORDING_MODE() false 156 #define RS_PROFILER_TRANSACTION_UNMARSHALLING_START(parcel, parcelNumber) 157 #define RS_PROFILER_ANIMATION_NODE(type, pixels) 158 #define RS_PROFILER_ANIMATION_DURATION_START(id, timestamp_ns) 159 #define RS_PROFILER_ANIMATION_DURATION_STOP(id, timestamp_ns) 160 161 #endif 162 163 #ifdef RS_PROFILER_ENABLED 164 165 namespace OHOS { 166 class Parcel; 167 class MessageParcel; 168 class MessageOption; 169 170 } // namespace OHOS 171 172 namespace OHOS::Media { 173 class PixelMap; 174 } // namespace OHOS::Media 175 176 namespace OHOS::Rosen { 177 178 class RSRenderService; 179 class RSMainThread; 180 class RSIRenderServiceConnection; 181 class RSRenderServiceConnection; 182 class RSTransactionData; 183 class RSRenderNode; 184 class RSRenderModifier; 185 class RSProperties; 186 class RSContext; 187 class RSScreenRenderNode; 188 class RSRenderNodeMap; 189 class RSAnimationManager; 190 class RSRenderAnimation; 191 class RSCommand; 192 class ArgList; 193 class JsonWriter; 194 class RSFile; 195 196 enum class Mode : uint32_t { NONE = 0, READ = 1, WRITE = 2, READ_EMUL = 3, WRITE_EMUL = 4, SAVING = 5 }; 197 198 enum class TextureRecordType : int { 199 ONE_PIXEL = 0, 200 JPEG = 1, 201 LZ4 = 2, 202 NO_COMPRESSION = 3, 203 }; 204 205 enum class RSProfilerLogType : int { 206 ERROR = 0, 207 WARNING = 1, 208 INFO = 2, 209 PIXELMAP = 3, 210 PARCEL_UNMARSHALLING_START = 4, 211 PARCEL_UNMARSHALLING_END = 5, 212 DEBUG = 6, 213 PIXELMAP_YUV = 7 214 }; 215 216 class RSProfilerLogMsg { 217 public: 218 RSProfilerLogType type_; 219 uint64_t time_; 220 std::string msg_; 221 RSProfilerLogMsg()222 RSProfilerLogMsg() : type_(RSProfilerLogType::ERROR), time_(0), msg_("") {} RSProfilerLogMsg(RSProfilerLogType type,uint64_t time,std::string msg)223 RSProfilerLogMsg(RSProfilerLogType type, uint64_t time, std::string msg) : type_(type), time_(time), msg_(msg) {} 224 }; 225 226 enum RSPROFILER_METRIC_ENUM { 227 RSPROFILER_METRIC_ONTREE_NODE_COUNT = 0, 228 RSPROFILER_METRIC_OFFTREE_NODE_COUNT = 1, 229 RSPROFILER_METRIC_BLUR_OPERATIONS = 2, 230 RSPROFILER_METRIC_BLUR_SHADER_CALLS = 3, 231 RSPROFILER_METRIC_BLUR_AREA_OPERATIONS = 4, 232 RSPROFILER_METRIC_BLUR_AREA_SHADER_CALLS = 5, 233 RSPROFILER_METRIC_MESA_BLUR_SHADER_CALLS = 6, 234 RSPROFILER_METRIC_MESA_BLUR_OPERATIONS = 7, 235 RSPROFILER_METRIC_KAWASE_BLUR_SHADER_CALLS = 8, 236 RSPROFILER_METRIC_KAWASE_BLUR_OPERATIONS = 9, 237 RSPROFILER_METRIC_AIBAR_BLUR_SHADER_CALLS = 10, 238 RSPROFILER_METRIC_GREY_BLUR_SHADER_CALLS = 11, 239 RSPROFILER_METRIC_LINEAR_GRADIENT_BLUR_SHADER_CALLS = 12, 240 RSPROFILER_METRIC_MAGNIFIER_SHADER_CALLS = 13, 241 RSPROFILER_METRIC_WATER_RIPPLE_BLUR_SHADER_CALLS = 14, 242 RSPROFILER_METRIC_LIGHT_BLUR_OPERATIONS = 15, 243 RSPROFILER_METRIC_HPS_BLUR_OPERATIONS = 16, 244 RSPROFILER_METRIC_ANIMATION_NODE = 17, 245 RSPROFILER_METRIC_ANIMATION_NODE_SIZE = 18, 246 RSPROFILER_METRIC_ANIMATION_DURATION = 19, 247 RSPROFILER_METRIC_ANIMATION_NODE_TYPE_CANVAS_NODE = 20, 248 RSPROFILER_METRIC_ANIMATION_NODE_TYPE_ROOT_NODE = 21, 249 RSPROFILER_METRIC_ANIMATION_NODE_TYPE_EFFECT_NODE = 22, 250 RSPROFILER_METRIC_ANIMATION_NODE_TYPE_SURFACE_NODE = 23, 251 RSPROFILER_METRIC_ANIMATION_NODE_TYPE_CANVAS_DRAWING_NODE = 24, 252 RSPROFILER_METRIC_ANIMATION_NODE_TYPE_PROXY_NODE = 25, 253 RSPROFILER_METRIC_COUNT 254 }; 255 256 class RSProfilerCustomMetricsParam { 257 public: 258 uint32_t kind; 259 int32_t value; 260 float fvalue; 261 std::string type; 262 std::string name; 263 bool manualReset; 264 265 RSProfilerCustomMetricsParam(uint32_t kind, std::string type, std::string name, bool manualReset = false) kind(kind)266 : kind(kind), type(std::move(type)), name(std::move(name)), manualReset(manualReset) 267 {} 268 }; 269 270 class RSProfilerCustomMetrics { 271 private: 272 std::vector<RSProfilerCustomMetricsParam> param; 273 274 public: RSProfilerCustomMetrics()275 RSProfilerCustomMetrics() 276 { 277 param.reserve(RSPROFILER_METRIC_COUNT); 278 param.emplace_back(RSPROFILER_METRIC_ONTREE_NODE_COUNT, "val", "On-tree Node Count", true); 279 param.emplace_back(RSPROFILER_METRIC_OFFTREE_NODE_COUNT, "val", "Off-tree Node Count", true); 280 param.emplace_back(RSPROFILER_METRIC_BLUR_OPERATIONS, "val", "Blur Operations"); 281 param.emplace_back(RSPROFILER_METRIC_BLUR_SHADER_CALLS, "val", "Blur Shader Calls"); 282 param.emplace_back(RSPROFILER_METRIC_BLUR_AREA_OPERATIONS, "fval", "Blur Area Operations"); 283 param.emplace_back(RSPROFILER_METRIC_BLUR_AREA_SHADER_CALLS, "fval", "Blur Area Shader Calls"); 284 param.emplace_back(RSPROFILER_METRIC_MESA_BLUR_SHADER_CALLS, "val", "MESA Blur Shader Calls"); 285 param.emplace_back(RSPROFILER_METRIC_MESA_BLUR_OPERATIONS, "val", "MESA Blur Operations"); 286 param.emplace_back(RSPROFILER_METRIC_KAWASE_BLUR_SHADER_CALLS, "val", "Kawase Blur Shader Calls"); 287 param.emplace_back(RSPROFILER_METRIC_KAWASE_BLUR_OPERATIONS, "val", "Kawase Blur Operations"); 288 param.emplace_back(RSPROFILER_METRIC_AIBAR_BLUR_SHADER_CALLS, "val", "AI Bar Blur Shader Calls"); 289 param.emplace_back(RSPROFILER_METRIC_GREY_BLUR_SHADER_CALLS, "val", "Grey Blur Shader Calls"); 290 param.emplace_back( 291 RSPROFILER_METRIC_LINEAR_GRADIENT_BLUR_SHADER_CALLS, "val", "Linear Gradient Blur Shader Calls"); 292 param.emplace_back(RSPROFILER_METRIC_MAGNIFIER_SHADER_CALLS, "val", "Magnifier Blur Shader Calls"); 293 param.emplace_back(RSPROFILER_METRIC_WATER_RIPPLE_BLUR_SHADER_CALLS, "val", "Water Ripple Blur Shader Calls"); 294 param.emplace_back(RSPROFILER_METRIC_LIGHT_BLUR_OPERATIONS, "val", "Light Blur Operations"); 295 param.emplace_back(RSPROFILER_METRIC_HPS_BLUR_OPERATIONS, "val", "HPS Blur Operations"); 296 param.emplace_back(RSPROFILER_METRIC_ANIMATION_NODE, "val", "Animation node count"); 297 param.emplace_back(RSPROFILER_METRIC_ANIMATION_NODE_SIZE, "fval", "Animation node size"); 298 param.emplace_back(RSPROFILER_METRIC_ANIMATION_DURATION, "fval", "Animation duration"); 299 param.emplace_back(RSPROFILER_METRIC_ANIMATION_NODE_TYPE_CANVAS_NODE, "val", "Animation canvas node"); 300 param.emplace_back(RSPROFILER_METRIC_ANIMATION_NODE_TYPE_ROOT_NODE, "val", "Animation root node"); 301 param.emplace_back(RSPROFILER_METRIC_ANIMATION_NODE_TYPE_EFFECT_NODE, "val", "Animation effect node"); 302 param.emplace_back(RSPROFILER_METRIC_ANIMATION_NODE_TYPE_SURFACE_NODE, "val", "Animation surface node"); 303 param.emplace_back( 304 RSPROFILER_METRIC_ANIMATION_NODE_TYPE_CANVAS_DRAWING_NODE, "val", "Animation canvas drawing node"); 305 param.emplace_back(RSPROFILER_METRIC_ANIMATION_NODE_TYPE_PROXY_NODE, "val", "Animation proxy node"); 306 } 307 GetCount()308 size_t GetCount() 309 { 310 return param.size(); 311 } 312 Reset()313 void Reset() 314 { 315 for (RSProfilerCustomMetricsParam& record : param) { 316 if (!record.manualReset) { 317 record.value = 0; 318 record.fvalue = 0; 319 } 320 } 321 } 322 AddInt(uint32_t kind,int32_t addon)323 void AddInt(uint32_t kind, int32_t addon) 324 { 325 if (kind >= param.size()) { 326 return; 327 } 328 param[kind].value += addon; 329 } 330 SubInt(uint32_t kind,int32_t sub)331 void SubInt(uint32_t kind, int32_t sub) 332 { 333 if (kind >= param.size()) { 334 return; 335 } 336 param[kind].value -= sub; 337 } 338 SetZero(uint32_t kind)339 void SetZero(uint32_t kind) 340 { 341 if (kind >= param.size()) { 342 return; 343 } 344 param[kind].value = 0; 345 } 346 AddFloat(uint32_t kind,float addon)347 void AddFloat(uint32_t kind, float addon) 348 { 349 if (kind >= param.size()) { 350 return; 351 } 352 param[kind].fvalue += addon; 353 } 354 MultiplyFloat(uint32_t kind,float k)355 void MultiplyFloat(uint32_t kind, float k) 356 { 357 if (kind >= param.size()) { 358 return; 359 } 360 param[kind].fvalue *= k; 361 } 362 Get(uint32_t kind)363 std::string Get(uint32_t kind) 364 { 365 if (kind >= param.size()) { 366 return ""; 367 } 368 if (param[kind].type == "val") { 369 return std::to_string(param[kind].value); 370 } else if (param[kind].type == "fval") { 371 return std::to_string(param[kind].fvalue); 372 } 373 return ""; 374 } 375 GetList()376 std::string GetList() 377 { 378 std::string retValue; 379 for (RSProfilerCustomMetricsParam& record : param) { 380 retValue += std::to_string(record.kind + 1) + "," + record.type + "," + record.name + ";"; 381 } 382 retValue.pop_back(); // remove last ';' 383 return retValue; 384 } 385 }; 386 387 class RSProfiler final { 388 public: 389 static void Init(RSRenderService* renderService); 390 static void StartNetworkThread(); 391 392 // see RSMainThread::Init 393 static void OnFrameBegin(uint64_t syncTime = 0); 394 static void OnFrameEnd(); 395 static void OnRenderBegin(); 396 static void OnRenderEnd(); 397 static void OnParallelRenderBegin(); 398 static void OnParallelRenderEnd(uint32_t frameNumber); 399 static void OnProcessCommand(); 400 401 // see RSRenderService::CreateConnection 402 static void OnCreateConnection(pid_t pid); 403 404 // see RenderServiceConnection::OnRemoteRequest 405 static uint64_t OnRemoteRequest(RSIRenderServiceConnection* connection, uint32_t code, MessageParcel& parcel, 406 MessageParcel& reply, MessageOption& option); 407 static uint64_t WriteRemoteRequest(pid_t pid, uint32_t code, MessageParcel& parcel, MessageOption& option); 408 409 // see UnmarshalThread::RecvParcel 410 static void OnRecvParcel(const MessageParcel* parcel, RSTransactionData* data); 411 412 RSB_EXPORT static std::shared_ptr<MessageParcel> CopyParcel(const MessageParcel& parcel); 413 RSB_EXPORT static uint64_t PatchTime(uint64_t time); 414 RSB_EXPORT static uint64_t PatchTransactionTime(const Parcel& parcel, uint64_t timeAtRecordProcess); 415 416 RSB_EXPORT static void PatchTypefaceId(const Parcel& parcel, std::shared_ptr<Drawing::DrawCmdList>& val); 417 418 template<typename T> PatchNodeId(const Parcel & parcel,T id)419 static T PatchNodeId(const Parcel& parcel, T id) 420 { 421 return static_cast<T>(PatchPlainNodeId(parcel, static_cast<NodeId>(id))); 422 } 423 424 template<typename T> PatchPid(const Parcel & parcel,T pid)425 static T PatchPid(const Parcel& parcel, T pid) 426 { 427 return static_cast<T>(PatchPlainPid(parcel, static_cast<pid_t>(pid))); 428 } 429 430 RSB_EXPORT static bool ProcessAddChild(RSRenderNode* parent, RSRenderNode::SharedPtr child, int index); 431 RSB_EXPORT static void PatchCommand(const Parcel& parcel, RSCommand* command); 432 RSB_EXPORT static void TransactionUnmarshallingStart(const Parcel& parcel, uint32_t parcelNumber); 433 RSB_EXPORT static void PushOffset(std::vector<uint32_t>& commandOffsets, uint32_t offset); 434 RSB_EXPORT static void PushOffsets( 435 const Parcel& parcel, uint32_t parcelNumber, std::vector<uint32_t>& commandOffsets); 436 RSB_EXPORT static void ExecuteCommand(const RSCommand* command); 437 RSB_EXPORT static bool MarshalPixelMap(Parcel& parcel, const std::shared_ptr<Media::PixelMap>& map); 438 RSB_EXPORT static Media::PixelMap* UnmarshalPixelMap(Parcel& parcel, 439 std::function<int(Parcel& parcel, std::function<int(Parcel&)> readFdDefaultFunc)> readSafeFdFunc = nullptr); 440 RSB_EXPORT static bool SkipPixelMap(Parcel& parcel); 441 RSB_EXPORT static void MarshalDrawingImage(std::shared_ptr<Drawing::Image>& image, 442 std::shared_ptr<Drawing::Data>& compressData); 443 RSB_EXPORT static void SetDirtyRegion(const Occlusion::Region& dirtyRegion); 444 445 RSB_EXPORT static void WriteParcelData(Parcel& parcel); 446 RSB_EXPORT static const void* ReadParcelData(Parcel& parcel, size_t size, bool& isMalloc); 447 RSB_EXPORT static bool SkipParcelData(Parcel& parcel, size_t size); 448 RSB_EXPORT static uint32_t GetFrameNumber(); 449 RSB_EXPORT static bool ShouldBlockHWCNode(); 450 451 RSB_EXPORT static void AnimeGetStartTimesFromFile( 452 std::unordered_map<AnimationId, std::vector<int64_t>>& animeMap); 453 RSB_EXPORT static std::unordered_map<AnimationId, std::vector<int64_t>> &AnimeGetStartTimes(); 454 RSB_EXPORT static std::vector<std::pair<uint64_t, int64_t>> AnimeGetStartTimesFlattened(double recordStartTime); 455 RSB_EXPORT static int64_t AnimeSetStartTime(AnimationId id, int64_t nanoTime); 456 RSB_EXPORT static void ReplayFixTrIndex(uint64_t curIndex, uint64_t& lastIndex); 457 458 RSB_EXPORT static std::vector<RSRenderNode::WeakPtr>& GetChildOfDisplayNodesPostponed(); 459 460 RSB_EXPORT static void SendMessageBase(const std::string& msg); 461 RSB_EXPORT static std::string ReceiveMessageBase(); 462 RSB_EXPORT static RSProfilerLogMsg ReceiveRSLogBase(); 463 RSB_EXPORT static void SendRSLogBase(RSProfilerLogType type, const std::string& msg); 464 RSB_EXPORT static void AddLightBlursMetrics(uint32_t areaBlurs); 465 RSB_EXPORT static void AddHPSBlursMetrics(uint32_t areaBlurs); 466 RSB_EXPORT static void AddKawaseBlursMetrics(uint32_t areaBlurs); 467 RSB_EXPORT static void AddMESABlursMetrics(uint32_t areaBlurs); 468 RSB_EXPORT static void LogShaderCall(const std::string& shaderType, const std::shared_ptr<Drawing::Image>& srcImage, 469 const Drawing::Rect& dstRect, const std::shared_ptr<Drawing::Image>& outImage); 470 471 RSB_EXPORT static void AddAnimationNodeMetrics(RSRenderNodeType type, int32_t size); 472 RSB_EXPORT static void AddAnimationStart(AnimationId id, int64_t timestamp_ns); 473 RSB_EXPORT static void AddAnimationFinish(AnimationId id, int64_t timestamp_ns); 474 475 RSB_EXPORT static RetCodeHrpService HrpServiceOpenFile(const HrpServiceDirInfo& dirInfo, 476 const std::string& fileName, int32_t flags, int& outFd); 477 RSB_EXPORT static RetCodeHrpService HrpServicePopulateFiles(const HrpServiceDirInfo& dirInfo, 478 uint32_t firstFileIndex, std::vector<HrpServiceFileInfo>& outFiles); 479 480 public: 481 RSB_EXPORT static bool IsParcelMock(const Parcel& parcel); 482 RSB_EXPORT static bool IsPlaybackParcel(const Parcel& parcel); 483 RSB_EXPORT static bool IsSharedMemoryEnabled(); 484 RSB_EXPORT static bool IsBetaRecordEnabled(); 485 RSB_EXPORT static bool IsBetaRecordEnabledWithMetrics(); 486 487 RSB_EXPORT static Mode GetMode(); 488 RSB_EXPORT static bool IsNoneMode(); 489 RSB_EXPORT static bool IsReadMode(); 490 RSB_EXPORT static bool IsReadEmulationMode(); 491 RSB_EXPORT static bool IsWriteMode(); 492 RSB_EXPORT static bool IsWriteEmulationMode(); 493 RSB_EXPORT static bool IsSavingMode(); 494 495 RSB_EXPORT static bool IsRecordingMode(); 496 497 RSB_EXPORT static TextureRecordType GetTextureRecordType(); 498 RSB_EXPORT static void SetTextureRecordType(TextureRecordType type); 499 500 RSB_EXPORT static void DrawingNodeAddClearOp(const std::shared_ptr<Drawing::DrawCmdList>& drawCmdList); 501 RSB_EXPORT static void SetDrawingCanvasNodeRedraw(bool enable); 502 RSB_EXPORT static void KeepDrawCmd(bool& drawCmdListNeedSync); 503 RSB_EXPORT static void SetRenderNodeKeepDrawCmd(bool enable); 504 RSB_EXPORT static bool IfNeedToSkipDuringReplay(Parcel& parcel, uint32_t skipBytes); 505 RSB_EXPORT static void SurfaceOnDrawMatchOptimize(bool& useNodeMatchOptimize); 506 507 RSB_EXPORT static void RsMetricClear(); 508 RSB_EXPORT static void RsMetricSet(std::string name, std::string value); 509 RSB_EXPORT static std::string RsMetricGetList(); 510 511 RSB_EXPORT static void RSLogOutput(RSProfilerLogType type, const char* format, va_list argptr); 512 513 RSB_EXPORT static void MetricRenderNodeInc(bool isOnTree); 514 RSB_EXPORT static void MetricRenderNodeDec(bool isOnTree); 515 RSB_EXPORT static void MetricRenderNodeChange(bool isOnTree); 516 RSB_EXPORT static void MetricRenderNodeInit(RSContext* context); 517 RSB_EXPORT static void ResetCustomMetrics(); 518 RSB_EXPORT static RSProfilerCustomMetrics& GetCustomMetrics(); 519 520 private: 521 static const char* GetProcessNameByPid(int pid); 522 523 RSB_EXPORT static void MarkReplayNodesDirty(RSContext& context); 524 525 RSB_EXPORT static void EnableSharedMemory(); 526 RSB_EXPORT static void DisableSharedMemory(); 527 528 RSB_EXPORT static bool BaseSetPlaybackSpeed(double speed); 529 RSB_EXPORT static double BaseGetPlaybackSpeed(); 530 RSB_EXPORT static Media::PixelMap* UnmarshalPixelMapNstd(Parcel& parcel, 531 std::function<int(Parcel& parcel, std::function<int(Parcel&)> readFdDefaultFunc)> readSafeFdFunc); 532 533 RSB_EXPORT static void LogYUVDataInfo(uint64_t id, const Media::YUVDataInfo& yuvInfo); 534 535 // Beta record 536 RSB_EXPORT static void EnableBetaRecord(); 537 RSB_EXPORT static bool IsBetaRecordSavingTriggered(); 538 static void StartBetaRecord(); 539 static void StopBetaRecord(); 540 static bool IsBetaRecordStarted(); 541 static void UpdateBetaRecord(const RSContext& context); 542 static void SaveBetaRecord(); 543 static bool IsBetaRecordInactive(); 544 static void RequestVSyncOnBetaRecordInactivity(); 545 static void LaunchBetaRecordNotificationThread(); 546 static void LaunchBetaRecordMetricsUpdateThread(); 547 static void LaunchBetaRecordFileSplitThread(); 548 static bool OpenBetaRecordFile(RSFile& file); 549 static bool SaveBetaRecordFile(RSFile& file); 550 static void WriteBetaRecordMetrics(RSFile& file, double time); 551 static void UpdateDirtyRegionBetaRecord(double currentFrameDirtyRegion); 552 static void BetaRecordSetLastParcelTime(); 553 554 RSB_EXPORT static void SetMode(Mode mode); 555 RSB_EXPORT static bool IsEnabled(); 556 RSB_EXPORT static bool IsHrpServiceEnabled(); 557 558 RSB_EXPORT static uint32_t GetCommandCount(); 559 RSB_EXPORT static uint32_t GetCommandExecuteCount(); 560 RSB_EXPORT static std::string GetParcelCommandList(); 561 562 RSB_EXPORT static const std::vector<pid_t>& GetPids(); 563 RSB_EXPORT static NodeId GetParentNode(); 564 RSB_EXPORT static void SetSubstitutingPid(const std::vector<pid_t>& pids, pid_t pid, NodeId parent); 565 RSB_EXPORT static pid_t GetSubstitutingPid(); 566 567 RSB_EXPORT static void BetaRecordOnFrameBegin(); 568 RSB_EXPORT static void BetaRecordOnFrameEnd(); 569 570 RSB_EXPORT static void SetTransactionTimeCorrection(double replayStartTime, double recordStartTime); 571 RSB_EXPORT static void TimePauseAt(uint64_t curTime, uint64_t newPauseAfterTime, bool immediate); 572 RSB_EXPORT static void TimePauseResume(uint64_t curTime); 573 RSB_EXPORT static void TimePauseClear(); 574 RSB_EXPORT static uint64_t TimePauseGet(); 575 576 RSB_EXPORT static bool IsSecureScreen(); 577 578 RSB_EXPORT static std::shared_ptr<RSScreenRenderNode> GetScreenNode(const RSContext& context); 579 RSB_EXPORT static Vector4f GetScreenRect(const RSContext& context); 580 581 // RSRenderNodeMap 582 RSB_EXPORT static void FilterForPlayback(RSContext& context, pid_t pid); 583 RSB_EXPORT static void FilterMockNode(RSContext& context); 584 585 RSB_EXPORT static void GetSurfacesTrees( 586 const RSContext& context, std::map<std::string, std::tuple<NodeId, std::string>>& list); 587 RSB_EXPORT static void GetSurfacesTrees(const RSContext& context, pid_t pid, std::map<NodeId, std::string>& list); 588 RSB_EXPORT static size_t GetRenderNodeCount(const RSContext& context); 589 RSB_EXPORT static NodeId GetRandomSurfaceNode(const RSContext& context); 590 591 RSB_EXPORT static void MarshalNodes(const RSContext& context, std::stringstream& data, uint32_t fileVersion); 592 RSB_EXPORT static void MarshalTree(const RSRenderNode& node, std::stringstream& data, uint32_t fileVersion); 593 RSB_EXPORT static void MarshalNode(const RSRenderNode& node, std::stringstream& data, uint32_t fileVersion); 594 RSB_EXPORT static void MarshalNodeModifiers( 595 const RSRenderNode& node, std::stringstream& data, uint32_t fileVersion); 596 597 RSB_EXPORT static std::string UnmarshalNodes(RSContext& context, std::stringstream& data, uint32_t fileVersion); 598 RSB_EXPORT static std::string UnmarshalTree(RSContext& context, std::stringstream& data, uint32_t fileVersion); 599 RSB_EXPORT static std::string UnmarshalNode(RSContext& context, std::stringstream& data, uint32_t fileVersion); 600 RSB_EXPORT static std::string UnmarshalNode( 601 RSContext& context, std::stringstream& data, NodeId nodeId, uint32_t fileVersion); 602 RSB_EXPORT static std::string UnmarshalNodeModifiers( 603 RSRenderNode& node, std::stringstream& data, uint32_t fileVersion); 604 605 RSB_EXPORT static void MarshalSubTree(RSContext& context, std::stringstream& data, const RSRenderNode& node, 606 uint32_t fileVersion, bool clearImageCache = true); 607 RSB_EXPORT static void MarshalSubTreeLo( 608 RSContext& context, std::stringstream& data, const RSRenderNode& node, uint32_t fileVersion); 609 RSB_EXPORT static std::string UnmarshalSubTree(RSContext& context, std::stringstream& data, 610 RSRenderNode& attachNode, uint32_t fileVersion, bool clearImageCache = true); 611 RSB_EXPORT static std::string UnmarshalSubTreeLo( 612 RSContext& context, std::stringstream& data, RSRenderNode& attachNode, uint32_t fileVersion); 613 614 RSB_EXPORT static NodeId AdjustNodeId(NodeId nodeId, bool clearMockFlag); 615 616 // RSRenderNode 617 RSB_EXPORT static std::string DumpRenderProperties(const RSRenderNode& node); 618 RSB_EXPORT static std::string DumpModifiers(const RSRenderNode& node); 619 RSB_EXPORT static std::string DumpSurfaceNode(const RSRenderNode& node); 620 621 // JSON 622 static void RenderServiceTreeDump(JsonWriter& out, pid_t pid); 623 RSB_EXPORT static void DumpOffscreen(RSContext& context, JsonWriter& rootOffscreen, bool useMockPid, pid_t pid); 624 RSB_EXPORT static void DumpNode(const RSRenderNode& node, JsonWriter& out, bool clearMockFlag = false, 625 bool absRoot = false, bool isSorted = true); 626 RSB_EXPORT static void DumpNodeAbsoluteProperties(const RSRenderNode& node, JsonWriter& out); 627 RSB_EXPORT static void DumpNodeAnimations(const RSAnimationManager& animationManager, JsonWriter& out); 628 RSB_EXPORT static void DumpNodeAnimation(const RSRenderAnimation& animation, JsonWriter& out); 629 RSB_EXPORT static void DumpNodeBaseInfo(const RSRenderNode& node, JsonWriter& out, bool clearMockFlag); 630 RSB_EXPORT static void DumpNodeSubsurfaces(const RSRenderNode& node, JsonWriter& out); 631 RSB_EXPORT static void DumpNodeSubClassNode(const RSRenderNode& node, JsonWriter& out); 632 RSB_EXPORT static void DumpNodeOptionalFlags(const RSRenderNode& node, JsonWriter& out); 633 RSB_EXPORT static void DumpNodeDrawCmdModifiers(const RSRenderNode& node, JsonWriter& out); 634 RSB_EXPORT static void DumpNodeDrawCmdModifier( 635 const RSRenderNode& node, JsonWriter& out, std::shared_ptr<ModifierNG::RSRenderModifier> modifier); 636 RSB_EXPORT static void DumpNodeProperties(const RSProperties& properties, JsonWriter& out); 637 RSB_EXPORT static void DumpNodePropertiesClip(const RSProperties& properties, JsonWriter& out); 638 RSB_EXPORT static void DumpNodePropertiesTransform(const RSProperties& properties, JsonWriter& out); 639 RSB_EXPORT static void DumpNodePropertiesNonSpatial(const RSProperties& properties, JsonWriter& out); 640 RSB_EXPORT static void DumpNodePropertiesDecoration(const RSProperties& properties, JsonWriter& out); 641 RSB_EXPORT static void DumpNodePropertiesEffects(const RSProperties& properties, JsonWriter& out); 642 RSB_EXPORT static void DumpNodePropertiesShadow(const RSProperties& properties, JsonWriter& out); 643 RSB_EXPORT static void DumpNodePropertiesColor(const RSProperties& properties, JsonWriter& out); 644 RSB_EXPORT static void DumpNodeChildrenListUpdate(const RSRenderNode& node, JsonWriter& out); 645 646 // RSAnimationManager 647 RSB_EXPORT static void FilterAnimationForPlayback(RSAnimationManager& manager); 648 649 RSB_EXPORT static NodeId PatchPlainNodeId(const Parcel& parcel, NodeId id); 650 RSB_EXPORT static pid_t PatchPlainPid(const Parcel& parcel, pid_t pid); 651 652 RSB_EXPORT static uint32_t PerfTreeFlatten(std::shared_ptr<RSRenderNode> node, 653 std::vector<std::pair<NodeId, uint32_t>>& nodeSet, std::unordered_map<NodeId, uint32_t>& mapNode2Count, 654 uint32_t depth); 655 RSB_EXPORT static uint32_t CalcNodeCmdListCount(RSRenderNode& node); 656 RSB_EXPORT static void CalcPerfNodePrepare(NodeId nodeId, uint32_t timeCount, bool excludeDown); 657 RSB_EXPORT static void CalcPerfNodePrepareLo(const std::shared_ptr<RSRenderNode>& node, bool forceExcludeNode); 658 static void PrintNodeCacheLo(const std::shared_ptr<RSRenderNode>& node); 659 660 static uint64_t RawNowNano(); 661 static uint64_t NowNano(); 662 static double Now(); 663 664 static bool IsRecording(); 665 static bool IsPlaying(); 666 667 static bool IsLoadSaveFirstScreenInProgress(); 668 static std::string FirstFrameMarshalling(uint32_t fileVersion); 669 static std::string FirstFrameUnmarshalling(const std::string& data, uint32_t fileVersion); 670 static void HiddenSpaceTurnOff(); 671 static void HiddenSpaceTurnOn(); 672 static std::shared_ptr<RSRenderNode> GetLogicalDisplay(); 673 674 static void ScheduleTask(std::function<void()>&& task); 675 static void RequestNextVSync(); 676 static void AwakeRenderServiceThread(); 677 static void ResetAnimationStamp(); 678 679 static void CreateMockConnection(pid_t pid); 680 static RSRenderServiceConnection* GetConnection(pid_t pid); 681 static pid_t GetConnectionPid(RSIRenderServiceConnection* connection); 682 static std::vector<pid_t> GetConnectionsPids(); 683 684 static std::shared_ptr<RSRenderNode> GetRenderNode(uint64_t id); 685 static void ProcessSendingRdc(); 686 687 static void BlinkNodeUpdate(); 688 static void CalcPerfNodeUpdate(); 689 static void CalcPerfNodeAllStep(); 690 static void CalcNodeWeigthOnFrameEnd(uint64_t frameLength); 691 692 RSB_EXPORT static uint32_t GetNodeDepth(const std::shared_ptr<RSRenderNode> node); 693 694 static void TypefaceMarshalling(std::stringstream& stream, uint32_t fileVersion); 695 static std::string TypefaceUnmarshalling(std::stringstream& stream, uint32_t fileVersion); 696 697 // Network interface 698 static void Invoke(const std::vector<std::string>& line); 699 static void ProcessPauseMessage(); 700 static void ProcessCommands(); 701 // Deprecated: Use SendMessage instead 702 static void Respond(const std::string& message); 703 static void SendMessage(const char* format, ...) __attribute__((__format__(printf, 1, 2))); 704 static void SetSystemParameter(const ArgList& args); 705 static void GetSystemParameter(const ArgList& args); 706 static void DumpSystemParameters(const ArgList& args); 707 static void DumpNodeModifiers(const ArgList& args); 708 static void DumpConnections(const ArgList& args); 709 static void DumpNodeProperties(const ArgList& args); 710 static void DumpTree(const ArgList& args); 711 static void DumpTreeToJson(const ArgList& args); 712 static void DumpNodeSurface(const ArgList& args); 713 static void ClearFilter(const ArgList& args); 714 static void PrintNodeCache(const ArgList& args); 715 static void PrintNodeCacheAll(const ArgList& args); 716 static void PatchNode(const ArgList& args); 717 static void KillNode(const ArgList& args); 718 static void BlinkNode(const ArgList& args); 719 static void AttachChild(const ArgList& args); 720 static void KillPid(const ArgList& args); 721 static void GetDeviceInfo(const ArgList& args); 722 static void GetDeviceFrequency(const ArgList& args); 723 static void FixDeviceEnv(const ArgList& args); 724 static void GetPerfTree(const ArgList& args); 725 static void CalcPerfNode(const ArgList& args); 726 static void CalcPerfNodeAll(const ArgList& args); 727 static void SocketShutdown(const ArgList& args); 728 static void DumpDrawingCanvasNodes(const ArgList& args); 729 730 static uint64_t GetDisplayArea(); 731 732 static void Version(const ArgList& args); 733 static void FileVersion(const ArgList& args); 734 735 static void SaveSkp(const ArgList& args); 736 static void SaveOffscreenSkp(const ArgList& args); 737 static void SaveComponentSkp(const ArgList& args); 738 static void SaveSkpImgCache(const ArgList& args); 739 static void SaveSkpOnCapture(const ArgList& args); 740 static void SaveSkpExtended(const ArgList& args); 741 static void SaveRdc(const ArgList& args); 742 static void DrawingCanvasRedrawEnable(const ArgList& args); 743 static void RenderNodeKeepDrawCmd(const ArgList& args); 744 static void PlaybackSetSpeed(const ArgList& args); 745 static void PlaybackSetImmediate(const ArgList& args); 746 747 static void WriteRSMetricsToRecordFile(double timeSinceRecordStart, double syncTime, uint64_t frameLen); 748 749 RSB_EXPORT static void RecordStart(const ArgList& args); 750 RSB_EXPORT static void RecordStop(const ArgList& args); 751 static void RecordCompression(const ArgList& args); 752 static void RecordMetrics(const ArgList& args); 753 static void RecordUpdate(); 754 static void RecordSave(); 755 RSB_EXPORT static void RequestRecordAbort(); 756 RSB_EXPORT static bool IsRecordAbortRequested(); 757 758 static void PlaybackStart(const ArgList& args); 759 static void PlaybackStop(const ArgList& args); 760 static double PlaybackUpdate(double deltaTime); 761 static double PlaybackDeltaTime(); 762 763 static void RecordSendBinary(const ArgList& args); 764 765 static void PlaybackPrepare(const ArgList& args); 766 static void PlaybackPrepareFirstFrame(const ArgList& args); 767 static void PlaybackPause(const ArgList& args); 768 static void PlaybackPauseAt(const ArgList& args); 769 static void PlaybackPauseClear(const ArgList& args); 770 static void PlaybackResume(const ArgList& args); 771 772 static void TestSaveFrame(const ArgList& args); 773 static void TestLoadFrame(const ArgList& args); 774 static void TestSwitch(const ArgList& args); 775 static void BuildTestTree(const ArgList& args); 776 static void ClearTestTree(const ArgList& args); 777 778 static void OnFlagChangedCallback(const char* key, const char* value, void* context); 779 static void OnWorkModeChanged(); 780 static void ProcessSignalFlag(); 781 782 RSB_EXPORT static bool LogEventStart(uint64_t curTime, RSCaptureData& captureData, double& timeSinceRecordStart); 783 static void LogEventFinish(RSCaptureData& captureData, double timeSinceRecordStart); 784 RSB_EXPORT static void LogEventVSync(uint64_t syncTime); 785 RSB_EXPORT static void LogEventMsg(uint64_t curTime, RSProfilerLogType type, const std::string& msg); 786 787 static void TestSaveSubTree(const ArgList& args); 788 static void TestLoadSubTree(const ArgList& args); 789 static void TestClearSubTree(const ArgList& args); 790 791 private: 792 using CommandRegistry = std::map<std::string, void (*)(const ArgList&)>; 793 static const CommandRegistry COMMANDS; 794 // set to true in DT only 795 RSB_EXPORT static bool testing_; 796 797 static RSContext* context_; 798 // flag for enabling profiler 799 RSB_EXPORT static bool enabled_; 800 RSB_EXPORT static bool hrpServiceEnabled_; 801 RSB_EXPORT static std::atomic_uint32_t mode_; 802 // flag for enabling profiler beta recording feature 803 RSB_EXPORT static bool betaRecordingEnabled_; 804 // flag to start network thread 805 RSB_EXPORT static std::atomic<int8_t> signalFlagChanged_; 806 807 inline static const char SYS_KEY_ENABLED[] = "persist.graphic.profiler.enabled"; 808 inline static const char SYS_KEY_BETARECORDING[] = "persist.graphic.profiler.betarecording"; 809 // flag for enabling DRAWING_CANVAS_NODE redrawing 810 RSB_EXPORT static std::atomic_bool dcnRedraw_; 811 RSB_EXPORT static std::atomic_bool renderNodeKeepDrawCmdList_; 812 RSB_EXPORT static std::atomic_bool recordAbortRequested_; 813 814 RSB_EXPORT static std::vector<std::shared_ptr<RSRenderNode>> testTree_; 815 RSB_EXPORT static std::unordered_map<AnimationId, int64_t> animationsTimes_; 816 817 friend class TestTreeBuilder; 818 friend class RSRenderServiceConnection; 819 }; 820 821 } // namespace OHOS::Rosen 822 823 #endif // RS_PROFILER_ENABLED 824 825 #endif // RENDER_SERVICE_PROFILER_H