• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 COMMON_H
16 #define COMMON_H
17 #include <unordered_map>
18 #include <string>
19 namespace OHOS {
20 namespace SmartPerf {
21 enum class MessageType {
22     APP_START_COLLECT,
23     APP_STOP_COLLECT,
24     APP_PAUSE_COLLECT,
25     APP_RESUME_COLLECT,
26     GET_CPU_NUM,
27     GET_CPU_FREQ_LOAD,
28     SET_PKG_NAME,
29     SET_PROCESS_ID,
30     GET_FPS_AND_JITTERS,
31     GET_GPU_FREQ,
32     GET_GPU_LOAD,
33     GET_DDR_FREQ,
34     GET_RAM_INFO,
35     GET_MEMORY_INFO,
36     GET_TEMPERATURE,
37     GET_POWER,
38     GET_CAPTURE,
39     CATCH_ONE_TRACE,
40     CATCH_TRACE_FINISH,
41     SET_DUBAI_DB,
42     START_DUBAI_DB,
43     CATCH_NETWORK_TRAFFIC,
44     GET_NETWORK_TRAFFIC, // 获取网络流量信息
45     BACK_TO_DESKTOP,
46     GET_CUR_FPS,
47     SET_GAME_VIEW,
48     GET_APP_TYPE,
49     CHECK_UDP_STATUS,
50     GET_LOG,
51     GET_DAEMON_VERSION,
52     GET_PROCESS_THREADS,
53     GET_PROCESS_FDS,
54     START_GPU_COUNTER,
55     SAVE_GPU_COUNTER,
56     APP_RECEIVE_DATA_ON,
57     APP_RECEIVE_DATA_OFF,
58     GET_INDEX_INFO
59 };
60 
61 const std::unordered_map<MessageType, std::string> MESSAGE_MAP = {
62     { MessageType::GET_CPU_NUM, std::string("get_cpu_num") },
63     { MessageType::GET_CPU_FREQ_LOAD, std::string("get_cpu_freq_load") },
64     { MessageType::SET_PKG_NAME, std::string("set_pkgName") },
65     { MessageType::SET_PROCESS_ID, std::string("set_pid") },
66     { MessageType::GET_FPS_AND_JITTERS, std::string("get_fps_and_jitters") },
67     { MessageType::GET_GPU_FREQ, std::string("get_gpu_freq") },
68     { MessageType::GET_GPU_LOAD, std::string("get_gpu_load") },
69     { MessageType::GET_DDR_FREQ, std::string("get_ddr_freq") },
70     { MessageType::GET_RAM_INFO, std::string("get_ram_info") },
71     { MessageType::GET_TEMPERATURE, std::string("get_temperature") },
72     { MessageType::GET_POWER, std::string("get_power") },
73     { MessageType::GET_CAPTURE, std::string("get_capture") },
74     { MessageType::GET_MEMORY_INFO, std::string("get_memory") },
75     { MessageType::CATCH_ONE_TRACE, std::string("catch_one_trace") },
76     { MessageType::CATCH_TRACE_FINISH, std::string("catch_trace_finish") },
77     { MessageType::SET_DUBAI_DB, std::string("set_dubai_db") },
78     { MessageType::START_DUBAI_DB, std::string("start_dubai_db") },
79     { MessageType::CATCH_NETWORK_TRAFFIC, std::string("catch_network_traffic") },
80     { MessageType::GET_NETWORK_TRAFFIC, std::string("get_network_traffic") },
81     { MessageType::BACK_TO_DESKTOP, std::string("back_to_desk") },
82     { MessageType::GET_CUR_FPS, std::string("get_cur_fps") },
83     { MessageType::SET_GAME_VIEW, std::string("set_game_view") },
84     { MessageType::GET_APP_TYPE, std::string("get_app_type") },
85     { MessageType::CHECK_UDP_STATUS, std::string("check_udp_status") },
86     { MessageType::GET_LOG, std::string("get_log") },
87     { MessageType::GET_DAEMON_VERSION, std::string("get_daemon_version") },
88     { MessageType::GET_PROCESS_THREADS, std::string("get_process_threads") },
89     { MessageType::GET_PROCESS_FDS, std::string("get_process_fds") },
90     { MessageType::START_GPU_COUNTER, std::string("start_gpu_counter") },
91     { MessageType::SAVE_GPU_COUNTER, std::string("save_gpu_counter") },
92     { MessageType::APP_START_COLLECT, std::string("app_start_collect") },
93     { MessageType::APP_STOP_COLLECT, std::string("app_stop_collect") },
94     { MessageType::APP_RECEIVE_DATA_ON, std::string("app_receive_data_on") },
95     { MessageType::APP_RECEIVE_DATA_OFF, std::string("app_receive_data_off") },
96     { MessageType::APP_PAUSE_COLLECT, std::string("app_pause_collect") },
97     { MessageType::APP_RESUME_COLLECT, std::string("app_resume_collect") },
98     { MessageType::GET_INDEX_INFO, std::string("get_index_info") },
99 };
100 
101 enum class CommandType {
102     CT_N,
103     CT_PKG,
104     CT_PID,
105     CT_OUT,
106     CT_C,
107     CT_G,
108     CT_D,
109     CT_F,
110     CT_FDS,
111     CT_T,
112     CT_P,
113     CT_PRINT,
114     CT_R,
115     CT_TRACE,
116     CT_THREADS,
117     CT_SNAPSHOT,
118     CT_SESSIONID,
119     CT_INTERVAL,
120     CT_NET,
121     CT_VIEW,
122     CT_FL,      //帧率限制值
123     CT_FTL,     //帧间隔限制值,单位ms
124     CT_GC,
125     CT_NAV,
126     CT_O,
127     CT_LF,
128     CT_AS,
129     CT_GE,
130     CT_CI,
131     CT_FC,
132     CT_HCI,
133 };
134 enum class CommandHelp {
135     HELP,
136     VERSION,
137     SCREEN,
138     CLEAR,
139     CLEARALL,
140     SERVER,
141     EDITORSERVER,
142     DEVICESERVER,
143 };
144 
145 const std::unordered_map<std::string, CommandType> COMMAND_MAP = {
146     { std::string("-N"), CommandType::CT_N },
147     { std::string("-PKG"), CommandType::CT_PKG },
148     { std::string("-PID"), CommandType::CT_PID },
149     { std::string("-OUT"), CommandType::CT_OUT },
150     { std::string("-c"), CommandType::CT_C },
151     { std::string("-CPU"), CommandType::CT_C },
152     { std::string("-g"), CommandType::CT_G },
153     { std::string("-GPU"), CommandType::CT_G },
154     { std::string("-f"), CommandType::CT_F },
155     { std::string("-FPS"), CommandType::CT_F },
156     { std::string("-LOW_POWER"), CommandType::CT_F },
157     { std::string("-fds"), CommandType::CT_FDS },
158     { std::string("-FDS"), CommandType::CT_FDS },
159     { std::string("-t"), CommandType::CT_T },
160     { std::string("-TEMP"), CommandType::CT_T },
161     { std::string("-p"), CommandType::CT_P },
162     { std::string("-POWER"), CommandType::CT_P },
163     { std::string("-print"), CommandType::CT_PRINT },
164     { std::string("-r"), CommandType::CT_R },
165     { std::string("-RAM"), CommandType::CT_R },
166     { std::string("-TRACE"), CommandType::CT_TRACE },
167     { std::string("-threads"), CommandType::CT_THREADS },
168     { std::string("-snapshot"), CommandType::CT_SNAPSHOT },
169     { std::string("-SCREEN"), CommandType::CT_SNAPSHOT },
170     { std::string("-d"), CommandType::CT_D },
171     { std::string("-DDR"), CommandType::CT_D },
172     { std::string("-INTERVAL"), CommandType::CT_INTERVAL },
173     { std::string("-SESSIONID"), CommandType::CT_SESSIONID },
174     { std::string("-net"), CommandType::CT_NET },
175     { std::string("-NET"), CommandType::CT_NET },
176     { std::string("-VIEW"), CommandType::CT_VIEW },
177     { std::string("-fl"), CommandType::CT_FL },
178     { std::string("-ftl"), CommandType::CT_FTL },
179     { std::string("-gc"), CommandType::CT_GC },
180     { std::string("-GPU_COUNTER"), CommandType::CT_GC },
181     { std::string("-nav"), CommandType::CT_NAV },
182     { std::string("-o"), CommandType::CT_O },
183     { std::string("-lockfreq"), CommandType::CT_LF },
184     { std::string("-aischedule"), CommandType::CT_AS },
185     { std::string("-ge"), CommandType::CT_GE },
186     { std::string("-ci"), CommandType::CT_CI },
187     { std::string("-fc"), CommandType::CT_FC },
188     { std::string("-HCI"), CommandType::CT_HCI },
189 };
190 
191 const std::unordered_map<CommandType, std::string> COMMAND_MAP_REVERSE = {
192     { CommandType::CT_N, std::string("-N") },
193     { CommandType::CT_PKG, std::string("-PKG") },
194     { CommandType::CT_PID, std::string("-PID") },
195     { CommandType::CT_OUT, std::string("-OUT") },
196     { CommandType::CT_C, std::string("-c") },
197     { CommandType::CT_G, std::string("-g") },
198     { CommandType::CT_F, std::string("-f") },
199     { CommandType::CT_FDS, std::string("-fds") },
200     { CommandType::CT_T, std::string("-t") },
201     { CommandType::CT_P, std::string("-p") },
202     { CommandType::CT_PRINT, std::string("-print") },
203     { CommandType::CT_R, std::string("-r") },
204     { CommandType::CT_TRACE, std::string("-TRACE") },
205     { CommandType::CT_THREADS, std::string("-threads") },
206     { CommandType::CT_SNAPSHOT, std::string("-snapshot") },
207     { CommandType::CT_D, std::string("-d") },
208     { CommandType::CT_INTERVAL, std::string("-INTERVAL") },
209     { CommandType::CT_SESSIONID, std::string("-SESSIONID") },
210     { CommandType::CT_NET, std::string("-net") },
211     { CommandType::CT_VIEW, std::string("-VIEW") },
212     { CommandType::CT_FL, std::string("-fl") },
213     { CommandType::CT_FTL, std::string("-ftl") },
214     { CommandType::CT_GC, std::string("-GPU_COUNTER") },
215     { CommandType::CT_NAV, std::string("-nav") },
216     { CommandType::CT_O, std::string("-o") },
217     { CommandType::CT_LF, std::string("-lockfreq") },
218     { CommandType::CT_AS, std::string("-aischedule") },
219     { CommandType::CT_GE, std::string("-ge") },
220     { CommandType::CT_CI, std::string("-ci") },
221     { CommandType::CT_FC, std::string("-fc") },
222     { CommandType::CT_HCI, std::string("-HCI") },
223 };
224 
225 const std::unordered_map<std::string, CommandType> COMMAND_SHELL_MAP = {
226     { std::string("-N"), CommandType::CT_N },
227     { std::string("-PKG"), CommandType::CT_PKG },
228     { std::string("-PID"), CommandType::CT_PID },
229     { std::string("-threads"), CommandType::CT_THREADS },
230     { std::string("-c"), CommandType::CT_C },
231     { std::string("-ci"), CommandType::CT_CI },
232     { std::string("-g"), CommandType::CT_G },
233     { std::string("-f"), CommandType::CT_F },
234     { std::string("-t"), CommandType::CT_T },
235     { std::string("-p"), CommandType::CT_P },
236     { std::string("-print"), CommandType::CT_PRINT },
237     { std::string("-r"), CommandType::CT_R },
238     { std::string("-snapshot"), CommandType::CT_SNAPSHOT },
239     { std::string("-net"), CommandType::CT_NET },
240     { std::string("-VIEW"), CommandType::CT_VIEW },
241     { std::string("-OUT"), CommandType::CT_OUT },
242     { std::string("-d"), CommandType::CT_D },
243     { std::string("-fl"), CommandType::CT_FL },
244     { std::string("-ftl"), CommandType::CT_FTL },
245 };
246 
247 const std::unordered_map<CommandHelp, std::string> COMMAND_HELP_MAP = {
248     { CommandHelp::HELP, std::string("--help") },
249     { CommandHelp::VERSION, std::string("--version") },
250     { CommandHelp::SCREEN, std::string("-screen") },
251     { CommandHelp::CLEAR, std::string("-clear") },
252     { CommandHelp::CLEARALL, std::string("-clearAll") },
253     { CommandHelp::SERVER, std::string("-server") },
254     { CommandHelp::EDITORSERVER, std::string("-editorServer") },
255     { CommandHelp::DEVICESERVER, std::string("-deviceServer") },
256 };
257 
258 enum class CmdCommand {
259     HITRACE_1024,
260     HITRACE_2048,
261     HITRACE_CMD,
262     CREAT_DIR,
263     SNAPSHOT,
264     SERVER,
265     OHTESTFPS,
266     RM_FILE,
267     TASKSET,
268     PROC_STAT,
269     HIPROFILER,
270     PERF,
271     HIPROFILER_CMD,
272     HIPROFILER_PID,
273     KILL_CMD,
274     PIDOF_SP,
275     SERVER_GREP,
276     EDITOR_SERVER_GREP,
277     UINPUT_BACK,
278     TIMESTAMPS,
279     USER_PERMISSIONS,
280     REMOVE,
281     CP,
282     TAR,
283     GET_HILOG,
284     CPU_FREQ,
285 };
286 
287 const std::unordered_map<CmdCommand, std::string> CMD_COMMAND_MAP = {
288     { CmdCommand::HITRACE_1024, std::string(
289         "hitrace --trace_clock mono -t 10 -b 102400 --overwrite idle ace app ohos ability graphic "
290         "nweb sched freq sync workq multimodalinput > ") },
291     { CmdCommand::HITRACE_2048, std::string(
292         "hitrace --trace_clock mono -t 10 -b 204800 --overwrite idle ace app ohos ability graphic "
293         "nweb sched freq sync workq multimodalinput > ") },
294     { CmdCommand::HITRACE_CMD, std::string("ps -ef |grep hitrace |grep -v grep") },
295     { CmdCommand::CREAT_DIR, std::string("mkdir -p -m 777 ") },
296     { CmdCommand::SNAPSHOT, std::string("snapshot_display -f ") },
297     { CmdCommand::SERVER, std::string("SP_daemon -server") },
298     { CmdCommand::OHTESTFPS, std::string("SP_daemon -ohtestfps 10") },
299     { CmdCommand::RM_FILE, std::string("rm -rfv /data/local/tmp/") },
300     { CmdCommand::TASKSET, std::string("taskset -p f ") },
301     { CmdCommand::PROC_STAT, std::string("chmod o+r /proc/stat") },
302     { CmdCommand::HIPROFILER, std::string("rm -f /data/local/tmp/hiprofiler_[0-9]*.htrace") },
303     { CmdCommand::PERF, std::string("rm -f /data/local/tmp/perf_[0-9]*.data") },
304     { CmdCommand::HIPROFILER_CMD, std::string("ps -ef |grep hiprofiler_cmd |grep -v grep") },
305     { CmdCommand::HIPROFILER_PID, std::string("pidof hiprofiler_cmd") },
306     { CmdCommand::KILL_CMD, std::string("kill ") },
307     { CmdCommand::PIDOF_SP, std::string("pidof SP_daemon") },
308     { CmdCommand::SERVER_GREP, std::string("ps -ef | grep -v grep | grep 'SP_daemon -server'") },
309     { CmdCommand::EDITOR_SERVER_GREP, std::string("ps -ef | grep -v grep | grep 'SP_daemon -editorServer'") },
310     { CmdCommand::UINPUT_BACK, std::string("uinput -K -d 2076 -d 2020 -u 2076 -u 2020") },
311     { CmdCommand::TIMESTAMPS, std::string("timestamps") },
312     { CmdCommand::USER_PERMISSIONS, std::string("whoami") },
313     { CmdCommand::REMOVE, std::string("rm -rf ") },
314     { CmdCommand::CP, std::string("cp ") },
315     { CmdCommand::TAR, std::string("tar -czf ") },
316     { CmdCommand::GET_HILOG, std::string("timeout 1s hilog > ") },
317     { CmdCommand::CPU_FREQ, std::string("/sys/devices/system/cpu/cpufreq/") },
318 };
319 
320 enum class DeviceCmd {
321     SN,
322     DEVICET_NAME,
323     BRAND,
324     VERSION,
325     ABILIST,
326     NAME,
327     MODEL,
328     FULL_NAME,
329 };
330 const std::unordered_map<DeviceCmd, std::string> DEVICE_CMD_MAP = {
331     { DeviceCmd::SN, std::string("ohos.boot.sn") },
332     { DeviceCmd::DEVICET_NAME, std::string("ohos.boot.hardware") },
333     { DeviceCmd::BRAND, std::string("const.product.brand") },
334     { DeviceCmd::VERSION, std::string("const.product.software.version") },
335     { DeviceCmd::ABILIST, std::string("const.product.cpu.abilist") },
336     { DeviceCmd::NAME, std::string("const.product.name") },
337     { DeviceCmd::MODEL, std::string("const.product.model") },
338     { DeviceCmd::FULL_NAME, std::string("const.ohos.fullname") },
339 };
340 
341 enum class HidumperCmd {
342     DUMPER_DUBAI_B,
343     DUMPER_DUBAI_F,
344     DUMPER_SURFACE,
345     DUMPER_HEAD,
346     DUMPER_SCREEN,
347     DUMPER_A_A,
348     DUMPER_NAV,
349     DUMPER_MEM,
350     DUMPER_RS_TREE,
351 };
352 const std::unordered_map<HidumperCmd, std::string> HIDUMPER_CMD_MAP = {
353     { HidumperCmd::DUMPER_DUBAI_B, std::string("hidumper -s 1213 -a '-b'") },
354     { HidumperCmd::DUMPER_DUBAI_F, std::string("hidumper -s 1213 -a '-f'") },
355     { HidumperCmd::DUMPER_SURFACE, std::string("hidumper -s 10 -a surface | grep surface") },
356     { HidumperCmd::DUMPER_HEAD, std::string(
357         "hidumper -s AbilityManagerService -a '-a' | grep 'bundle name' | head -n 1") },
358     { HidumperCmd::DUMPER_SCREEN, std::string("hidumper -s 10 -a screen") },
359     { HidumperCmd::DUMPER_A_A, std::string("hidumper -s WindowManagerService -a '-a'") },
360     { HidumperCmd::DUMPER_NAV, std::string("hidumper -s WindowManagerService -a '-w ") },
361     { HidumperCmd::DUMPER_MEM, std::string("hidumper --mem ") },
362     { HidumperCmd::DUMPER_RS_TREE, std::string("hidumper -s 10 -a RSTree | grep SURFACE_NODE") },
363 };
364 
365 enum class HisyseventCmd {
366     HISYS_APP_START,
367     HISYS_JANK,
368     HISYS_RESPONSE,
369     HISYS_COMPLETED,
370     HISYSEVENT,
371     HISYS_PID,
372     HISYS_SCROLL_ANIMATION,
373 };
374 const std::unordered_map<HisyseventCmd, std::string> HISYSEVENT_CMD_MAP = {
375     { HisyseventCmd::HISYS_APP_START, std::string("hisysevent -r -o PERFORMANCE -n APP_START") },
376     { HisyseventCmd::HISYS_JANK, std::string("hisysevent -r -o PERFORMANCE -n INTERACTION_JANK") },
377     { HisyseventCmd::HISYS_SCROLL_ANIMATION, std::string("hisysevent -r -o PERFORMANCE -n SCROLL_ANIMATION") },
378     { HisyseventCmd::HISYS_RESPONSE, std::string("hisysevent -r -n INTERACTION_RESPONSE_LATENCY") },
379     { HisyseventCmd::HISYS_COMPLETED, std::string("hisysevent -r -n INTERACTION_COMPLETED_LATENCY") },
380     { HisyseventCmd::HISYSEVENT, std::string("ps -ef |grep hisysevent") },
381     { HisyseventCmd::HISYS_PID, std::string("pidof hisysevent") },
382 };
383 }
384 }
385 #endif