• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifdef RS_PROFILER_ENABLED
20 
21 #include <map>
22 #include <string>
23 
24 #include "common/rs_vector4.h"
25 #include "common/rs_occlusion_region.h"
26 #include "pipeline/rs_render_node.h"
27 #include "params/rs_display_render_params.h"
28 #include "recording/draw_cmd_list.h"
29 
30 #define RS_PROFILER_INIT(renderSevice) RSProfiler::Init(renderSevice)
31 #define RS_PROFILER_ON_FRAME_BEGIN(syncTime) RSProfiler::OnFrameBegin(syncTime)
32 #define RS_PROFILER_ON_FRAME_END() RSProfiler::OnFrameEnd()
33 #define RS_PROFILER_ON_RENDER_BEGIN() RSProfiler::OnRenderBegin()
34 #define RS_PROFILER_ON_RENDER_END() RSProfiler::OnRenderEnd()
35 #define RS_PROFILER_ON_PROCESS_COMMAND() RSProfiler::OnProcessCommand()
36 #define RS_PROFILER_ON_CREATE_CONNECTION(pid) RSProfiler::OnCreateConnection(pid)
37 #define RS_PROFILER_ON_REMOTE_REQUEST(connection, code, data, reply, option) \
38     RSProfiler::OnRemoteRequest(connection, code, data, reply, option)
39 #define RS_PROFILER_ON_PARCEL_RECEIVE(parcel, data) RSProfiler::OnRecvParcel(parcel, data)
40 #define RS_PROFILER_COPY_PARCEL(parcel) RSProfiler::CopyParcel(parcel)
41 #define RS_PROFILER_PATCH_NODE_ID(parcel, id) id = RSProfiler::PatchNodeId(parcel, id)
42 #define RS_PROFILER_PATCH_TYPEFACE_GLOBALID(parcel, id) id = RSProfiler::PatchNodeId(parcel, id)
43 #define RS_PROFILER_PATCH_PID(parcel, pid) pid = RSProfiler::PatchPid(parcel, pid)
44 #define RS_PROFILER_PATCH_TIME(time) time = RSProfiler::PatchTime(time)
45 #define RS_PROFILER_PATCH_TRANSACTION_TIME(parcel, time) time = RSProfiler::PatchTransactionTime(parcel, time)
46 #define RS_PROFILER_PATCH_COMMAND(parcel, command) RSProfiler::PatchCommand(parcel, command)
47 #define RS_PROFILER_PUSH_OFFSET(commandOffsets, offset) RSProfiler::PushOffset(commandOffsets, offset)
48 #define RS_PROFILER_PUSH_OFFSETS(parcel, parcelNumber, commandOffsets) \
49     RSProfiler::PushOffsets(parcel, parcelNumber, commandOffsets)
50 #define RS_PROFILER_EXECUTE_COMMAND(command) RSProfiler::ExecuteCommand(command)
51 #define RS_PROFILER_MARSHAL_PIXELMAP(parcel, map) RSProfiler::MarshalPixelMap(parcel, map)
52 #define RS_PROFILER_UNMARSHAL_PIXELMAP(parcel, readSafeFdFunc) RSProfiler::UnmarshalPixelMap(parcel, readSafeFdFunc)
53 #define RS_PROFILER_SKIP_PIXELMAP(parcel) RSProfiler::SkipPixelMap(parcel)
54 #define RS_PROFILER_MARSHAL_DRAWINGIMAGE(image, compressData) RSProfiler::MarshalDrawingImage(image, compressData)
55 #define RS_PROFILER_SET_DIRTY_REGION(dirtyRegion) RSProfiler::SetDirtyRegion(dirtyRegion)
56 #define RS_PROFILER_WRITE_PARCEL_DATA(parcel) RSProfiler::WriteParcelData(parcel)
57 #define RS_PROFILER_READ_PARCEL_DATA(parcel, size, isMalloc) RSProfiler::ReadParcelData(parcel, size, isMalloc)
58 #define RS_PROFILER_SKIP_PARCEL_DATA(parcel, size) RSProfiler::SkipParcelData(parcel, size)
59 #define RS_PROFILER_GET_FRAME_NUMBER() RSProfiler::GetFrameNumber()
60 #define RS_PROFILER_ON_PARALLEL_RENDER_BEGIN() RSProfiler::OnParallelRenderBegin()
61 #define RS_PROFILER_ON_PARALLEL_RENDER_END(renderFrameNumber) RSProfiler::OnParallelRenderEnd(renderFrameNumber)
62 #define RS_PROFILER_SHOULD_BLOCK_HWCNODE() RSProfiler::ShouldBlockHWCNode()
63 #define RS_PROFILER_ANIME_SET_START_TIME(id, time) RSProfiler::AnimeSetStartTime(id, time)
64 #define RS_PROFILER_REPLAY_FIX_TRINDEX(curIndex, lastIndex) RSProfiler::ReplayFixTrIndex(curIndex, lastIndex)
65 #define RS_PROFILER_PATCH_TYPEFACE_ID(parcel, val) RSProfiler::PatchTypefaceId(parcel, val)
66 #define RS_PROFILER_DRAWING_NODE_ADD_CLEAROP(drawCmdList) RSProfiler::DrawingNodeAddClearOp(drawCmdList)
67 #define RS_PROFILER_PROCESS_ADD_CHILD(parent, child, index) RSProfiler::ProcessAddChild(parent, child, index)
68 #define RS_PROFILER_TEST_LOAD_FILE_SUB_TREE(nodeId, path) RSProfiler::TestLoadFileSubTree(nodeId, path)
69 #else
70 #define RS_PROFILER_INIT(renderSevice)
71 #define RS_PROFILER_ON_FRAME_BEGIN(syncTime)
72 #define RS_PROFILER_ON_FRAME_END()
73 #define RS_PROFILER_ON_RENDER_BEGIN()
74 #define RS_PROFILER_ON_RENDER_END()
75 #define RS_PROFILER_ON_PROCESS_COMMAND()
76 #define RS_PROFILER_ON_CREATE_CONNECTION(pid)
77 #define RS_PROFILER_ON_REMOTE_REQUEST(connection, code, data, reply, option) 0
78 #define RS_PROFILER_ON_PARCEL_RECEIVE(parcel, data)
79 #define RS_PROFILER_COPY_PARCEL(parcel) std::make_shared<MessageParcel>()
80 #define RS_PROFILER_PATCH_NODE_ID(parcel, id)
81 #define RS_PROFILER_PATCH_TYPEFACE_GLOBALID(parcel, id)
82 #define RS_PROFILER_PATCH_PID(parcel, pid)
83 #define RS_PROFILER_PATCH_TIME(time)
84 #define RS_PROFILER_PATCH_TRANSACTION_TIME(parcel, time)
85 #define RS_PROFILER_PATCH_COMMAND(parcel, command)
86 #define RS_PROFILER_PUSH_OFFSET(commandOffsets, offset)
87 #define RS_PROFILER_PUSH_OFFSETS(parcel, parcelNumber, commandOffsets)
88 #define RS_PROFILER_EXECUTE_COMMAND(command)
89 #define RS_PROFILER_MARSHAL_PIXELMAP(parcel, map) (map)->Marshalling(parcel)
90 #define RS_PROFILER_UNMARSHAL_PIXELMAP(parcel, readSafeFdFunc) Media::PixelMap::Unmarshalling(parcel, readSafeFdFunc)
91 #define RS_PROFILER_SKIP_PIXELMAP(parcel) false
92 #define RS_PROFILER_MARSHAL_DRAWINGIMAGE(image, compressData)
93 #define RS_PROFILER_SET_DIRTY_REGION(dirtyRegion)
94 #define RS_PROFILER_WRITE_PARCEL_DATA(parcel)
95 #define RS_PROFILER_READ_PARCEL_DATA(parcel, size, isMalloc) RSMarshallingHelper::ReadFromAshmem(parcel, size, isMalloc)
96 #define RS_PROFILER_SKIP_PARCEL_DATA(parcel, size) false
97 #define RS_PROFILER_GET_FRAME_NUMBER() 0
98 #define RS_PROFILER_ON_PARALLEL_RENDER_BEGIN()
99 #define RS_PROFILER_ON_PARALLEL_RENDER_END(renderFrameNumber)
100 #define RS_PROFILER_SHOULD_BLOCK_HWCNODE() false
101 #define RS_PROFILER_ANIME_SET_START_TIME(id, time) time
102 #define RS_PROFILER_REPLAY_FIX_TRINDEX(curIndex, lastIndex)
103 #define RS_PROFILER_PATCH_TYPEFACE_ID(parcel, val)
104 #define RS_PROFILER_DRAWING_NODE_ADD_CLEAROP(drawCmdList) (drawCmdList)->ClearOp()
105 #define RS_PROFILER_PROCESS_ADD_CHILD(parent, child, index) false
106 #define RS_PROFILER_TEST_LOAD_FILE_SUB_TREE(nodeId, path)
107 #endif
108 
109 #ifdef RS_PROFILER_ENABLED
110 
111 namespace OHOS {
112 class Parcel;
113 class MessageParcel;
114 class MessageOption;
115 
116 } // namespace OHOS
117 
118 namespace OHOS::Media {
119 class PixelMap;
120 } // namespace OHOS::Media
121 
122 namespace OHOS::Rosen {
123 
124 class RSRenderService;
125 class RSMainThread;
126 class RSIRenderServiceConnection;
127 class RSRenderServiceConnection;
128 class RSTransactionData;
129 class RSRenderNode;
130 class RSRenderModifier;
131 class RSProperties;
132 class RSContext;
133 class RSDisplayRenderNode;
134 class RSRenderNodeMap;
135 class RSAnimationManager;
136 class RSRenderAnimation;
137 class RSCommand;
138 class ArgList;
139 class JsonWriter;
140 class RSFile;
141 
142 enum class Mode : uint32_t { NONE = 0, READ = 1, WRITE = 2, READ_EMUL = 3, WRITE_EMUL = 4, SAVING = 5 };
143 
144 class RSProfiler final {
145 public:
146     static void Init(RSRenderService* renderService);
147     static void StartNetworkThread();
148 
149     // see RSMainThread::Init
150     static void OnFrameBegin(uint64_t syncTime = 0);
151     static void OnFrameEnd();
152     static void OnRenderBegin();
153     static void OnRenderEnd();
154     static void OnParallelRenderBegin();
155     static void OnParallelRenderEnd(uint32_t frameNumber);
156     static void OnProcessCommand();
157 
158     // see RSRenderService::CreateConnection
159     static void OnCreateConnection(pid_t pid);
160 
161     // see RenderServiceConnection::OnRemoteRequest
162     static uint64_t OnRemoteRequest(RSIRenderServiceConnection* connection, uint32_t code, MessageParcel& parcel,
163         MessageParcel& reply, MessageOption& option);
164     static uint64_t WriteRemoteRequest(pid_t pid, uint32_t code, MessageParcel& parcel, MessageOption& option);
165 
166     // see UnmarshalThread::RecvParcel
167     static void OnRecvParcel(const MessageParcel* parcel, RSTransactionData* data);
168 
169     RSB_EXPORT static std::shared_ptr<MessageParcel> CopyParcel(const MessageParcel& parcel);
170     RSB_EXPORT static uint64_t PatchTime(uint64_t time);
171     RSB_EXPORT static uint64_t PatchTransactionTime(const Parcel& parcel, uint64_t timeAtRecordProcess);
172 
173     RSB_EXPORT static void PatchTypefaceId(const Parcel& parcel, std::shared_ptr<Drawing::DrawCmdList>& val);
174 
175     template<typename T>
PatchNodeId(const Parcel & parcel,T id)176     static T PatchNodeId(const Parcel& parcel, T id)
177     {
178         return static_cast<T>(PatchPlainNodeId(parcel, static_cast<NodeId>(id)));
179     }
180 
181     template<typename T>
PatchPid(const Parcel & parcel,T pid)182     static T PatchPid(const Parcel& parcel, T pid)
183     {
184         return static_cast<T>(PatchPlainPid(parcel, static_cast<pid_t>(pid)));
185     }
186 
187     RSB_EXPORT static bool ProcessAddChild(RSRenderNode* parent, RSRenderNode::SharedPtr child, int index);
188     RSB_EXPORT static void PatchCommand(const Parcel& parcel, RSCommand* command);
189     RSB_EXPORT static void PushOffset(std::vector<uint32_t>& commandOffsets, uint32_t offset);
190     RSB_EXPORT static void PushOffsets(
191         const Parcel& parcel, uint32_t parcelNumber, std::vector<uint32_t>& commandOffsets);
192     RSB_EXPORT static void ExecuteCommand(const RSCommand* command);
193     RSB_EXPORT static bool MarshalPixelMap(Parcel& parcel, const std::shared_ptr<Media::PixelMap>& map);
194     RSB_EXPORT static Media::PixelMap* UnmarshalPixelMap(Parcel& parcel,
195         std::function<int(Parcel& parcel, std::function<int(Parcel&)> readFdDefaultFunc)> readSafeFdFunc = nullptr);
196     RSB_EXPORT static bool SkipPixelMap(Parcel& parcel);
197     RSB_EXPORT static void MarshalDrawingImage(std::shared_ptr<Drawing::Image>& image,
198         std::shared_ptr<Drawing::Data>& compressData);
199     RSB_EXPORT static void SetDirtyRegion(const Occlusion::Region& dirtyRegion);
200 
201     RSB_EXPORT static void WriteParcelData(Parcel& parcel);
202     RSB_EXPORT static const void* ReadParcelData(Parcel& parcel, size_t size, bool& isMalloc);
203     RSB_EXPORT static bool SkipParcelData(Parcel& parcel, size_t size);
204     RSB_EXPORT static uint32_t GetFrameNumber();
205     RSB_EXPORT static bool ShouldBlockHWCNode();
206 
207     RSB_EXPORT static void AnimeGetStartTimesFromFile(
208         std::unordered_map<AnimationId, std::vector<int64_t>>& animeMap);
209     RSB_EXPORT static std::unordered_map<AnimationId, std::vector<int64_t>> &AnimeGetStartTimes();
210     RSB_EXPORT static std::vector<std::pair<uint64_t, int64_t>> AnimeGetStartTimesFlattened(double recordStartTime);
211     RSB_EXPORT static int64_t AnimeSetStartTime(AnimationId id, int64_t nanoTime);
212     RSB_EXPORT static std::string SendMessageBase();
213     RSB_EXPORT static void SendMessageBase(const std::string& msg);
214     RSB_EXPORT static void ReplayFixTrIndex(uint64_t curIndex, uint64_t& lastIndex);
215 
216     RSB_EXPORT static std::vector<RSRenderNode::WeakPtr>& GetChildOfDisplayNodesPostponed();
217     RSB_EXPORT static void TestLoadFileSubTree(NodeId nodeId, const std::string &filePath);
218 public:
219     RSB_EXPORT static bool IsParcelMock(const Parcel& parcel);
220     RSB_EXPORT static bool IsSharedMemoryEnabled();
221     RSB_EXPORT static bool IsBetaRecordEnabled();
222     RSB_EXPORT static bool IsBetaRecordEnabledWithMetrics();
223 
224     RSB_EXPORT static Mode GetMode();
225     RSB_EXPORT static bool IsNoneMode();
226     RSB_EXPORT static bool IsReadMode();
227     RSB_EXPORT static bool IsReadEmulationMode();
228     RSB_EXPORT static bool IsWriteMode();
229     RSB_EXPORT static bool IsWriteEmulationMode();
230     RSB_EXPORT static bool IsSavingMode();
231 
232     RSB_EXPORT static void DrawingNodeAddClearOp(const std::shared_ptr<Drawing::DrawCmdList>& drawCmdList);
233     RSB_EXPORT static void SetDrawingCanvasNodeRedraw(bool enable);
234 
235 private:
236     static const char* GetProcessNameByPid(int pid);
237 
238     RSB_EXPORT static void EnableSharedMemory();
239     RSB_EXPORT static void DisableSharedMemory();
240 
241     RSB_EXPORT static bool BaseSetPlaybackSpeed(double speed);
242     RSB_EXPORT static double BaseGetPlaybackSpeed();
243 
244     // Beta record
245     RSB_EXPORT static void EnableBetaRecord();
246     RSB_EXPORT static bool IsBetaRecordSavingTriggered();
247     static void StartBetaRecord();
248     static void StopBetaRecord();
249     static bool IsBetaRecordStarted();
250     static void UpdateBetaRecord(const RSContext& context);
251     static void SaveBetaRecord();
252     static bool IsBetaRecordInactive();
253     static void RequestVSyncOnBetaRecordInactivity();
254     static void LaunchBetaRecordNotificationThread();
255     static void LaunchBetaRecordMetricsUpdateThread();
256     static void LaunchBetaRecordFileSplitThread();
257     static bool OpenBetaRecordFile(RSFile& file);
258     static bool SaveBetaRecordFile(RSFile& file);
259     static void WriteBetaRecordMetrics(RSFile& file, double time);
260     static void UpdateDirtyRegionBetaRecord(double currentFrameDirtyRegion);
261     static void BetaRecordSetLastParcelTime();
262 
263     RSB_EXPORT static void SetMode(Mode mode);
264     RSB_EXPORT static bool IsEnabled();
265 
266     RSB_EXPORT static uint32_t GetCommandCount();
267     RSB_EXPORT static uint32_t GetCommandExecuteCount();
268     RSB_EXPORT static std::string GetParcelCommandList();
269 
270     RSB_EXPORT static const std::vector<pid_t>& GetPids();
271     RSB_EXPORT static NodeId GetParentNode();
272     RSB_EXPORT static void SetSubstitutingPid(const std::vector<pid_t>& pids, pid_t pid, NodeId parent);
273     RSB_EXPORT static pid_t GetSubstitutingPid();
274 
275     RSB_EXPORT static void BetaRecordOnFrameBegin();
276     RSB_EXPORT static void BetaRecordOnFrameEnd();
277 
278 private:
279     RSB_EXPORT static void SetTransactionTimeCorrection(double replayStartTime, double recordStartTime);
280     RSB_EXPORT static void TimePauseAt(uint64_t curTime, uint64_t newPauseAfterTime, bool immediate);
281     RSB_EXPORT static void TimePauseResume(uint64_t curTime);
282     RSB_EXPORT static void TimePauseClear();
283     RSB_EXPORT static uint64_t TimePauseGet();
284 
285     RSB_EXPORT static std::shared_ptr<RSDisplayRenderNode> GetDisplayNode(const RSContext& context);
286     RSB_EXPORT static Vector4f GetScreenRect(const RSContext& context);
287 
288     // RSRenderNodeMap
289     RSB_EXPORT static void FilterForPlayback(RSContext& context, pid_t pid);
290     RSB_EXPORT static void FilterMockNode(RSContext& context);
291 
292     RSB_EXPORT static void GetSurfacesTrees(
293         const RSContext& context, std::map<std::string, std::tuple<NodeId, std::string>>& list);
294     RSB_EXPORT static void GetSurfacesTrees(const RSContext& context, pid_t pid, std::map<NodeId, std::string>& list);
295     RSB_EXPORT static size_t GetRenderNodeCount(const RSContext& context);
296     RSB_EXPORT static NodeId GetRandomSurfaceNode(const RSContext& context);
297 
298     RSB_EXPORT static void MarshalNodes(const RSContext& context, std::stringstream& data, uint32_t fileVersion);
299     RSB_EXPORT static void MarshalTree(const RSRenderNode& node, std::stringstream& data, uint32_t fileVersion);
300     RSB_EXPORT static void MarshalNode(const RSRenderNode& node, std::stringstream& data, uint32_t fileVersion);
301     RSB_EXPORT static void MarshalNodeModifiers(
302         const RSRenderNode& node, std::stringstream& data, uint32_t fileVersion);
303 
304     RSB_EXPORT static std::string UnmarshalNodes(RSContext& context, std::stringstream& data, uint32_t fileVersion);
305     RSB_EXPORT static std::string UnmarshalTree(RSContext& context, std::stringstream& data, uint32_t fileVersion);
306     RSB_EXPORT static std::string UnmarshalNode(RSContext& context, std::stringstream& data, uint32_t fileVersion);
307     RSB_EXPORT static std::string UnmarshalNode(
308         RSContext& context, std::stringstream& data, NodeId nodeId, uint32_t fileVersion);
309     RSB_EXPORT static std::string UnmarshalNodeModifiers(
310         RSRenderNode& node, std::stringstream& data, uint32_t fileVersion);
311 
312     RSB_EXPORT static void MarshalSubTree(RSContext& context, std::stringstream& data,
313         const RSRenderNode& node, uint32_t fileVersion, bool clearImageCache = true);
314     RSB_EXPORT static void MarshalSubTreeLo(RSContext& context, std::stringstream& data,
315         const RSRenderNode& node, uint32_t fileVersion);
316     RSB_EXPORT static std::string UnmarshalSubTree(RSContext& context, std::stringstream& data,
317         RSRenderNode& attachNode, uint32_t fileVersion, bool clearImageCache = true);
318     RSB_EXPORT static std::string UnmarshalSubTreeLo(RSContext& context, std::stringstream& data,
319         RSRenderNode& attachNode, uint32_t fileVersion);
320 
321     RSB_EXPORT static NodeId AdjustNodeId(NodeId nodeId, bool clearMockFlag);
322 
323     // RSRenderNode
324     RSB_EXPORT static std::string DumpRenderProperties(const RSRenderNode& node);
325     RSB_EXPORT static std::string DumpModifiers(const RSRenderNode& node);
326     RSB_EXPORT static std::string DumpSurfaceNode(const RSRenderNode& node);
327 
328     // JSON
329     static void RenderServiceTreeDump(JsonWriter& out, pid_t pid);
330     RSB_EXPORT static void DumpNode(const RSRenderNode& node, JsonWriter& out,
331         bool clearMockFlag = false, bool absRoot = false);
332     RSB_EXPORT static void DumpNodeAbsoluteProperties(const RSRenderNode& node, JsonWriter& out);
333     RSB_EXPORT static void DumpNodeAnimations(const RSAnimationManager& animationManager, JsonWriter& out);
334     RSB_EXPORT static void DumpNodeAnimation(const RSRenderAnimation& animation, JsonWriter& out);
335     RSB_EXPORT static void DumpNodeBaseInfo(const RSRenderNode& node, JsonWriter& out, bool clearMockFlag);
336     RSB_EXPORT static void DumpNodeSubsurfaces(const RSRenderNode& node, JsonWriter& out);
337     RSB_EXPORT static void DumpNodeSubClassNode(const RSRenderNode& node, JsonWriter& out);
338     RSB_EXPORT static void DumpNodeOptionalFlags(const RSRenderNode& node, JsonWriter& out);
339     RSB_EXPORT static void DumpNodeDrawCmdModifiers(const RSRenderNode& node, JsonWriter& out);
340     RSB_EXPORT static void DumpNodeDrawCmdModifier(
341         const RSRenderNode& node, JsonWriter& out, int type, RSRenderModifier& modifier);
342     RSB_EXPORT static void DumpNodeProperties(const RSProperties& properties, JsonWriter& out);
343     RSB_EXPORT static void DumpNodePropertiesClip(const RSProperties& properties, JsonWriter& out);
344     RSB_EXPORT static void DumpNodePropertiesTransform(const RSProperties& properties, JsonWriter& out);
345     RSB_EXPORT static void DumpNodePropertiesNonSpatial(const RSProperties& properties, JsonWriter& out);
346     RSB_EXPORT static void DumpNodePropertiesDecoration(const RSProperties& properties, JsonWriter& out);
347     RSB_EXPORT static void DumpNodePropertiesEffects(const RSProperties& properties, JsonWriter& out);
348     RSB_EXPORT static void DumpNodePropertiesShadow(const RSProperties& properties, JsonWriter& out);
349     RSB_EXPORT static void DumpNodePropertiesColor(const RSProperties& properties, JsonWriter& out);
350     RSB_EXPORT static void DumpNodeChildrenListUpdate(const RSRenderNode& node, JsonWriter& out);
351 
352     // RSAnimationManager
353     RSB_EXPORT static void FilterAnimationForPlayback(RSAnimationManager& manager);
354 
355     RSB_EXPORT static NodeId PatchPlainNodeId(const Parcel& parcel, NodeId id);
356     RSB_EXPORT static pid_t PatchPlainPid(const Parcel& parcel, pid_t pid);
357 
358     RSB_EXPORT static uint32_t PerfTreeFlatten(
359         std::shared_ptr<RSRenderNode> node, std::vector<std::pair<NodeId, uint32_t>>& nodeSet,
360         std::unordered_map<NodeId, uint32_t>& mapNode2Count, uint32_t depth);
361     RSB_EXPORT static uint32_t CalcNodeCmdListCount(RSRenderNode& node);
362     RSB_EXPORT static void CalcPerfNodePrepare(NodeId nodeId, uint32_t timeCount, bool excludeDown);
363     RSB_EXPORT static void CalcPerfNodePrepareLo(const std::shared_ptr<RSRenderNode>& node, bool forceExcludeNode);
364     static void PrintNodeCacheLo(const std::shared_ptr<RSRenderNode>& node);
365 
366     static uint64_t RawNowNano();
367     static uint64_t NowNano();
368     static double Now();
369 
370     static bool IsRecording();
371     static bool IsPlaying();
372 
373     static bool IsLoadSaveFirstScreenInProgress();
374     static std::string FirstFrameMarshalling(uint32_t fileVersion);
375     static std::string FirstFrameUnmarshalling(const std::string& data, uint32_t fileVersion);
376     static void HiddenSpaceTurnOff();
377     static void HiddenSpaceTurnOn();
378 
379     static void ScheduleTask(std::function<void()>&& task);
380     static void RequestNextVSync();
381     static void AwakeRenderServiceThread();
382     static void ResetAnimationStamp();
383 
384     static void CreateMockConnection(pid_t pid);
385     static RSRenderServiceConnection* GetConnection(pid_t pid);
386     static pid_t GetConnectionPid(RSIRenderServiceConnection* connection);
387     static std::vector<pid_t> GetConnectionsPids();
388 
389     static std::shared_ptr<RSRenderNode> GetRenderNode(uint64_t id);
390     static void ProcessSendingRdc();
391 
392     static void BlinkNodeUpdate();
393     static void CalcPerfNodeUpdate();
394     static void CalcPerfNodeAllStep();
395     static void CalcNodeWeigthOnFrameEnd(uint64_t frameLength);
396 
397     RSB_EXPORT static uint32_t GetNodeDepth(const std::shared_ptr<RSRenderNode> node);
398 
399     static void TypefaceMarshalling(std::stringstream& stream, uint32_t fileVersion);
400     static std::string TypefaceUnmarshalling(std::stringstream& stream, uint32_t fileVersion);
401 
402     // Network interface
403     static void Invoke(const std::vector<std::string>& line);
404     static void ProcessPauseMessage();
405     static void ProcessCommands();
406     // Deprecated: Use SendMessage instead
407     static void Respond(const std::string& message);
408     static void SendMessage(const char* format, ...) __attribute__((__format__(printf, 1, 2)));
409     static void SetSystemParameter(const ArgList& args);
410     static void GetSystemParameter(const ArgList& args);
411     static void Reset(const ArgList& args);
412     static void DumpSystemParameters(const ArgList& args);
413     static void DumpNodeModifiers(const ArgList& args);
414     static void DumpConnections(const ArgList& args);
415     static void DumpNodeProperties(const ArgList& args);
416     static void DumpTree(const ArgList& args);
417     static void DumpTreeToJson(const ArgList& args);
418     static void DumpSurfaces(const ArgList& args);
419     static void DumpNodeSurface(const ArgList& args);
420     static void ClearFilter(const ArgList& args);
421     static void PrintNodeCache(const ArgList& args);
422     static void PrintNodeCacheAll(const ArgList& args);
423     static void PatchNode(const ArgList& args);
424     static void KillNode(const ArgList& args);
425     static void BlinkNode(const ArgList& args);
426     static void AttachChild(const ArgList& args);
427     static void KillPid(const ArgList& args);
428     static void GetRoot(const ArgList& args);
429     static void GetDeviceInfo(const ArgList& args);
430     static void GetDeviceFrequency(const ArgList& args);
431     static void FixDeviceEnv(const ArgList& args);
432     static void GetPerfTree(const ArgList& args);
433     static void CalcPerfNode(const ArgList& args);
434     static void CalcPerfNodeAll(const ArgList& args);
435     static void SocketShutdown(const ArgList& args);
436     static void DumpDrawingCanvasNodes(const ArgList& args);
437 
438     static void Version(const ArgList& args);
439     static void FileVersion(const ArgList& args);
440 
441     static void SaveSkp(const ArgList& args);
442     static void SaveRdc(const ArgList& args);
443     static void DrawingCanvasRedrawEnable(const ArgList& args);
444     static void PlaybackSetSpeed(const ArgList& args);
445     static void PlaybackSetImmediate(const ArgList& args);
446 
447     static void RecordStart(const ArgList& args);
448     static void RecordStop(const ArgList& args);
449     static void RecordUpdate();
450     static void RecordSave();
451     RSB_EXPORT static void RequestRecordAbort();
452     RSB_EXPORT static bool IsRecordAbortRequested();
453 
454     static void PlaybackStart(const ArgList& args);
455     static void PlaybackStop(const ArgList& args);
456     static double PlaybackUpdate(double deltaTime);
457     static double PlaybackDeltaTime();
458 
459     static void RecordSendBinary(const ArgList& args);
460 
461     static void PlaybackPrepare(const ArgList& args);
462     static void PlaybackPrepareFirstFrame(const ArgList& args);
463     static void PlaybackPause(const ArgList& args);
464     static void PlaybackPauseAt(const ArgList& args);
465     static void PlaybackPauseClear(const ArgList& args);
466     static void PlaybackResume(const ArgList& args);
467 
468     static void TestSaveFrame(const ArgList& args);
469     static void TestLoadFrame(const ArgList& args);
470     static void TestSwitch(const ArgList& args);
471 
472     static void OnFlagChangedCallback(const char *key, const char *value, void *context);
473     static void OnWorkModeChanged();
474     static void ProcessSignalFlag();
475 
476     static void TestSaveSubTree(const ArgList& args);
477     static void TestLoadSubTree(const ArgList& args);
478 private:
479     using CommandRegistry = std::map<std::string, void (*)(const ArgList&)>;
480     static const CommandRegistry COMMANDS;
481     // set to true in DT only
482     RSB_EXPORT static bool testing_;
483 
484     // flag for enabling profiler
485     RSB_EXPORT static bool enabled_;
486     RSB_EXPORT static std::atomic_uint32_t mode_;
487     // flag for enabling profiler beta recording feature
488     RSB_EXPORT static bool betaRecordingEnabled_;
489     // flag to start network thread
490     RSB_EXPORT static int8_t signalFlagChanged_;
491 
492     inline static const char SYS_KEY_ENABLED[] = "persist.graphic.profiler.enabled";
493     inline static const char SYS_KEY_BETARECORDING[] = "persist.graphic.profiler.betarecording";
494     // flag for enabling DRAWING_CANVAS_NODE redrawing
495     RSB_EXPORT static std::atomic_bool dcnRedraw_;
496     RSB_EXPORT static std::atomic_bool recordAbortRequested_;
497 };
498 
499 } // namespace OHOS::Rosen
500 
501 #endif // RS_PROFILER_ENABLED
502 
503 #endif // RENDER_SERVICE_PROFILER_H