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 #include "rs_profiler.h"
17 #include "rs_profiler_command.h"
18
19 namespace OHOS::Rosen {
20
21 const RSProfiler::CommandRegistry RSProfiler::COMMANDS = {
22 { "rstree_contains", DumpTree },
23 { "rstree_fix", PatchNode },
24 { "rstree_kill_node", KillNode },
25 { "rstree_setparent", AttachChild },
26 { "rstree_getroot", GetRoot },
27 { "rstree_node_mod", DumpNodeModifiers },
28 { "rstree_node_prop", DumpNodeProperties },
29 { "rstree_pid", DumpSurfaces },
30 { "rstree_kill_pid", KillPid },
31 { "rstree_prepare_replay", PlaybackPrepare },
32 { "rstree_save_frame", TestSaveFrame },
33 { "rstree_load_frame", TestLoadFrame },
34 { "rstree_switch", TestSwitch },
35 { "rstree_dump_json", DumpTreeToJson },
36 { "rstree_clear_filter", ClearFilter },
37 { "rstree_blink_node", BlinkNode },
38 { "rstree_node_cache", PrintNodeCache },
39 { "rstree_node_cache_all", PrintNodeCacheAll },
40 { "rsrecord_start", RecordStart },
41 { "rsrecord_stop", RecordStop },
42 { "rsrecord_replay_prepare", PlaybackPrepareFirstFrame },
43 { "rsrecord_replay", PlaybackStart },
44 { "rsrecord_replay_stop", PlaybackStop },
45 { "rsrecord_pause_now", PlaybackPause },
46 { "rsrecord_pause_at", PlaybackPauseAt },
47 { "rsrecord_pause_resume", PlaybackResume },
48 { "rsrecord_pause_clear", PlaybackPauseClear },
49 { "rsrecord_sendbinary", RecordSendBinary },
50 { "rssurface_pid", DumpNodeSurface },
51 { "rscon_print", DumpConnections },
52 { "save_rdc", SaveRdc },
53 { "save_skp", SaveSkp },
54 { "info", GetDeviceInfo },
55 { "freq", GetDeviceFrequency },
56 { "fixenv", FixDeviceEnv },
57 { "set", SetSystemParameter },
58 { "get", GetSystemParameter },
59 { "params", DumpSystemParameters },
60 { "get_perf_tree", GetPerfTree },
61 { "calc_perf_node", CalcPerfNode },
62 { "calc_perf_node_all", CalcPerfNodeAll },
63 { "socket_shutdown", SocketShutdown },
64 { "version", Version },
65 { "file_version", FileVersion },
66 { "reset", Reset },
67 { "drawing_canvas", DumpDrawingCanvasNodes },
68 { "drawing_canvas_enable", DrawingCanvasRedrawEnable },
69 };
70
Invoke(const std::vector<std::string>& line)71 void RSProfiler::Invoke(const std::vector<std::string>& line)
72 {
73 if (line.empty() || line[0].empty()) {
74 return;
75 }
76
77 const auto delegate = COMMANDS.find(line[0]);
78 if (delegate == COMMANDS.end()) {
79 Respond("Command has not been found: " + line[0]);
80 return;
81 }
82
83 const ArgList args = (line.size() > 1) ? ArgList({ line.begin() + 1, line.end() }) : ArgList();
84 delegate->second(args);
85 }
86
87 } // namespace OHOS::Rosen
88