• 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     GET_CPU_NUM,
23     GET_CPU_FREQ_LOAD,
24     SET_PKG_NAME,
25     SET_PROCESS_ID,
26     GET_FPS_AND_JITTERS,
27     GET_GPU_FREQ,
28     GET_GPU_LOAD,
29     GET_DDR_FREQ,
30     GET_RAM_INFO,
31     GET_MEMORY_INFO,
32     GET_TEMPERATURE,
33     GET_POWER,
34     GET_CAPTURE,
35     CATCH_TRACE_CONFIG,
36     CATCH_TRACE_CMD,
37     SET_DUBAI_DB,
38     START_DUBAI_DB,
39     CATCH_NETWORK_TRAFFIC,
40     GET_NETWORK_TRAFFIC, // 获取网络流量信息
41     BACK_TO_DESKTOP,
42     GET_CUR_FPS,
43     SET_GAME_VIEW,
44     GET_APP_TYPE,
45     CHECK_UDP_STATUS,
46     GET_LOG,
47     GET_DAEMON_VERSION,
48     GET_PROCESS_THREADS,
49     GET_PROCESS_FDS,
50 };
51 
52 const std::unordered_map<MessageType, std::string> MESSAGE_MAP = {
53     { MessageType::GET_CPU_NUM, std::string("get_cpu_num") },
54     { MessageType::GET_CPU_FREQ_LOAD, std::string("get_cpu_freq_load") },
55     { MessageType::SET_PKG_NAME, std::string("set_pkgName") },
56     { MessageType::SET_PROCESS_ID, std::string("set_pid") },
57     { MessageType::GET_FPS_AND_JITTERS, std::string("get_fps_and_jitters") },
58     { MessageType::GET_GPU_FREQ, std::string("get_gpu_freq") },
59     { MessageType::GET_GPU_LOAD, std::string("get_gpu_load") },
60     { MessageType::GET_DDR_FREQ, std::string("get_ddr_freq") },
61     { MessageType::GET_RAM_INFO, std::string("get_ram_info") },
62     { MessageType::GET_TEMPERATURE, std::string("get_temperature") },
63     { MessageType::GET_POWER, std::string("get_power") },
64     { MessageType::GET_CAPTURE, std::string("get_capture") },
65     { MessageType::GET_MEMORY_INFO, std::string("get_memory") },
66     { MessageType::CATCH_TRACE_CONFIG, std::string("catch_trace_config") },
67     { MessageType::CATCH_TRACE_CMD, std::string("catch_trace_cmd") },
68     { MessageType::SET_DUBAI_DB, std::string("set_dubai_db") },
69     { MessageType::START_DUBAI_DB, std::string("start_dubai_db") },
70     { MessageType::CATCH_NETWORK_TRAFFIC, std::string("catch_network_traffic") },
71     { MessageType::GET_NETWORK_TRAFFIC, std::string("get_network_traffic") },
72     { MessageType::BACK_TO_DESKTOP, std::string("back_to_desk") },
73     { MessageType::GET_CUR_FPS, std::string("get_cur_fps") },
74     { MessageType::SET_GAME_VIEW, std::string("set_game_view") },
75     { MessageType::GET_APP_TYPE, std::string("get_app_type") },
76     { MessageType::CHECK_UDP_STATUS, std::string("check_udp_status") },
77     { MessageType::GET_LOG, std::string("get_log") },
78     { MessageType::GET_DAEMON_VERSION, std::string("get_daemon_version") },
79     { MessageType::GET_PROCESS_THREADS, std::string("get_process_threads") },
80     { MessageType::GET_PROCESS_FDS, std::string("get_process_fds") },
81 };
82 
83 enum class CommandType {
84     CT_N,
85     CT_PKG,
86     CT_PID,
87     CT_OUT,
88     CT_C,
89     CT_G,
90     CT_D,
91     CT_F,
92     CT_FDS,
93     CT_T,
94     CT_P,
95     CT_PRINT,
96     CT_R,
97     CT_TTRACE,
98     CT_THREADS,
99     CT_SNAPSHOT,
100     CT_HW,
101     CT_SESSIONID,
102     CT_INTERVAL,
103     CT_NET,
104     CT_VIEW,
105     CT_FL,      //帧率限制值
106     CT_FTL,     //帧间隔限制值,单位ms
107     CT_GC,
108     CT_NAV,
109     CT_O,
110     CT_LF,
111     CT_AS,
112 };
113 enum class CommandHelp {
114     HELP,
115     VERSION,
116     SCREEN,
117     CLEAR,
118     SERVER,
119     EDITORSERVER,
120 };
121 
122 const std::unordered_map<std::string, CommandType> COMMAND_MAP = {
123     { std::string("-N"), CommandType::CT_N },
124     { std::string("-PKG"), CommandType::CT_PKG },
125     { std::string("-PID"), CommandType::CT_PID },
126     { std::string("-OUT"), CommandType::CT_OUT },
127     { std::string("-c"), CommandType::CT_C },
128     { std::string("-g"), CommandType::CT_G },
129     { std::string("-f"), CommandType::CT_F },
130     { std::string("-fds"), CommandType::CT_FDS },
131     { std::string("-t"), CommandType::CT_T },
132     { std::string("-p"), CommandType::CT_P },
133     { std::string("-print"), CommandType::CT_PRINT },
134     { std::string("-r"), CommandType::CT_R },
135     { std::string("-trace"), CommandType::CT_TTRACE },
136     { std::string("-threads"), CommandType::CT_THREADS },
137     { std::string("-snapshot"), CommandType::CT_SNAPSHOT },
138     { std::string("-hw"), CommandType::CT_HW },
139     { std::string("-d"), CommandType::CT_D },
140     { std::string("-INTERVAL"), CommandType::CT_INTERVAL },
141     { std::string("-SESSIONID"), CommandType::CT_SESSIONID },
142     { std::string("-net"), CommandType::CT_NET },
143     { std::string("-VIEW"), CommandType::CT_VIEW },
144     { std::string("-fl"), CommandType::CT_FL },
145     { std::string("-ftl"), CommandType::CT_FTL },
146     { std::string("-gc"), CommandType::CT_GC },
147     { std::string("-nav"), CommandType::CT_NAV },
148     { std::string("-o"), CommandType::CT_O },
149     { std::string("-lockfreq"), CommandType::CT_LF },
150     { std::string("-aischedule"), CommandType::CT_AS },
151 };
152 
153 const std::unordered_map<CommandType, std::string> COMMAND_MAP_REVERSE = {
154     { CommandType::CT_N, std::string("-N") },
155     { CommandType::CT_PKG, std::string("-PKG") },
156     { CommandType::CT_PID, std::string("-PID") },
157     { CommandType::CT_OUT, std::string("-OUT") },
158     { CommandType::CT_C, std::string("-c") },
159     { CommandType::CT_G, std::string("-g") },
160     { CommandType::CT_F, std::string("-f") },
161     { CommandType::CT_FDS, std::string("-fds") },
162     { CommandType::CT_T, std::string("-t") },
163     { CommandType::CT_P, std::string("-p") },
164     { CommandType::CT_PRINT, std::string("-print") },
165     { CommandType::CT_R, std::string("-r") },
166     { CommandType::CT_TTRACE, std::string("-trace") },
167     { CommandType::CT_THREADS, std::string("-threads") },
168     { CommandType::CT_SNAPSHOT, std::string("-snapshot") },
169     { CommandType::CT_HW, std::string("-hw") },
170     { CommandType::CT_D, std::string("-d") },
171     { CommandType::CT_INTERVAL, std::string("-INTERVAL") },
172     { CommandType::CT_SESSIONID, std::string("-SESSIONID") },
173     { CommandType::CT_NET, std::string("-net") },
174     { CommandType::CT_VIEW, std::string("-VIEW") },
175     { CommandType::CT_FL, std::string("-fl") },
176     { CommandType::CT_FTL, std::string("-ftl") },
177     { CommandType::CT_GC, std::string("-gc") },
178     { CommandType::CT_NAV, std::string("-nav") },
179     { CommandType::CT_O, std::string("-o") },
180     { CommandType::CT_LF, std::string("-lockfreq") },
181     { CommandType::CT_AS, std::string("-aischedule") },
182 };
183 
184 
185 const std::unordered_map<CommandHelp, std::string> COMMAND_HELP_MAP = {
186     { CommandHelp::HELP, std::string("--help") },
187     { CommandHelp::VERSION, std::string("--version") },
188     { CommandHelp::SCREEN, std::string("-screen") },
189     { CommandHelp::CLEAR, std::string("-clear") },
190     { CommandHelp::SERVER, std::string("-server") },
191     { CommandHelp::EDITORSERVER, std::string("-editorServer") },
192 };
193 
194 enum class TraceStatus {
195     TRACE_START,
196     TRACE_FINISH,
197     TRACE_NO
198 };
199 
200 enum class CmdCommand {
201     HITRACE_1024,
202     HITRACE_2048,
203     HITRACE_CMD,
204     CREAT_DIR,
205     SNAPSHOT,
206     SERVER,
207     OHTESTFPS,
208     RM_FILE,
209     TASKSET,
210     PROC_STAT,
211     HIPROFILER,
212     PERF,
213     HIPROFILER_CMD,
214     HIPROFILER_PID,
215     KILL_CMD,
216     PIDOF_SP,
217     SERVER_GREP,
218     EDITOR_SERVER_GREP,
219     UINPUT_BACK,
220     TIMESTAMPS,
221     USER_PERMISSIONS,
222     REMOVE,
223     CP,
224     TAR,
225     GET_HILOG,
226 };
227 
228 const std::unordered_map<CmdCommand, std::string> CMD_COMMAND_MAP = {
229     { CmdCommand::HITRACE_1024, std::string(
230         "hitrace --trace_clock mono -t 10 -b 102400 --overwrite idle ace app ohos ability graphic "
231         "nweb sched freq sync workq multimodalinput > ") },
232     { CmdCommand::HITRACE_2048, std::string(
233         "hitrace --trace_clock mono -t 10 -b 204800 --overwrite idle ace app ohos ability graphic "
234         "nweb sched freq sync workq multimodalinput > ") },
235     { CmdCommand::HITRACE_CMD, std::string("ps -ef |grep hitrace |grep -v grep") },
236     { CmdCommand::CREAT_DIR, std::string("mkdir -m 777 ") },
237     { CmdCommand::SNAPSHOT, std::string("snapshot_display -f ") },
238     { CmdCommand::SERVER, std::string("SP_daemon -server") },
239     { CmdCommand::OHTESTFPS, std::string("SP_daemon -ohtestfps 10") },
240     { CmdCommand::RM_FILE, std::string("rm -rfv /data/local/tmp/") },
241     { CmdCommand::TASKSET, std::string("taskset -p f ") },
242     { CmdCommand::PROC_STAT, std::string("chmod o+r /proc/stat") },
243     { CmdCommand::HIPROFILER, std::string("rm -f /data/local/tmp/hiprofiler_[0-9]*.htrace") },
244     { CmdCommand::PERF, std::string("rm -f /data/local/tmp/perf_[0-9]*.data") },
245     { CmdCommand::HIPROFILER_CMD, std::string("ps -ef |grep hiprofiler_cmd |grep -v grep") },
246     { CmdCommand::HIPROFILER_PID, std::string("pidof hiprofiler_cmd") },
247     { CmdCommand::KILL_CMD, std::string("kill ") },
248     { CmdCommand::PIDOF_SP, std::string("pidof SP_daemon") },
249     { CmdCommand::SERVER_GREP, std::string("ps -ef | grep -v grep | grep 'SP_daemon -server'") },
250     { CmdCommand::EDITOR_SERVER_GREP, std::string("ps -ef | grep -v grep | grep 'SP_daemon -editorServer'") },
251     { CmdCommand::UINPUT_BACK, std::string("uinput -K -d 2076 -d 2020 -u 2076 -u 2020") },
252     { CmdCommand::TIMESTAMPS, std::string("timestamps") },
253     { CmdCommand::USER_PERMISSIONS, std::string("whoami") },
254     { CmdCommand::REMOVE, std::string("rm -rf ") },
255     { CmdCommand::CP, std::string("cp ") },
256     { CmdCommand::TAR, std::string("tar -czf ") },
257     { CmdCommand::GET_HILOG, std::string("timeout 1s hilog > ") },
258 };
259 
260 enum class DeviceCmd {
261     SN,
262     DEVICET_NAME,
263     BRAND,
264     VERSION,
265     ABILIST,
266     NAME,
267     MODEL,
268     FULL_NAME,
269 };
270 const std::unordered_map<DeviceCmd, std::string> DEVICE_CMD_MAP = {
271     { DeviceCmd::SN, std::string("param get ohos.boot.sn") },
272     { DeviceCmd::DEVICET_NAME, std::string("param get ohos.boot.hardware") },
273     { DeviceCmd::BRAND, std::string("param get const.product.brand") },
274     { DeviceCmd::VERSION, std::string("param get const.product.software.version") },
275     { DeviceCmd::ABILIST, std::string("param get const.product.cpu.abilist") },
276     { DeviceCmd::NAME, std::string("param get const.product.name") },
277     { DeviceCmd::MODEL, std::string("param get const.product.model") },
278     { DeviceCmd::FULL_NAME, std::string("param get const.ohos.fullname") },
279 };
280 
281 enum class HidumperCmd {
282     DUMPER_DUBAI_B,
283     DUMPER_DUBAI_F,
284     DUMPER_SURFACE,
285     DUMPER_HEAD,
286     DUMPER_SCREEN,
287     DUMPER_A_A,
288     DUMPER_NAV,
289     DUMPER_MEM,
290 };
291 const std::unordered_map<HidumperCmd, std::string> HIDUMPER_CMD_MAP = {
292     { HidumperCmd::DUMPER_DUBAI_B, std::string("hidumper -s 1213 -a '-b'") },
293     { HidumperCmd::DUMPER_DUBAI_F, std::string("hidumper -s 1213 -a '-f'") },
294     { HidumperCmd::DUMPER_SURFACE, std::string("hidumper -s 10 -a surface | grep surface") },
295     { HidumperCmd::DUMPER_HEAD, std::string(
296         "hidumper -s AbilityManagerService -a '-a' | grep 'bundle name' | head -n 1") },
297     { HidumperCmd::DUMPER_SCREEN, std::string("hidumper -s 10 -a screen") },
298     { HidumperCmd::DUMPER_A_A, std::string("hidumper -s WindowManagerService -a '-a'") },
299     { HidumperCmd::DUMPER_NAV, std::string("hidumper -s WindowManagerService -a '-w ") },
300     { HidumperCmd::DUMPER_MEM, std::string("hidumper --mem ") },
301 };
302 
303 enum class HisyseventCmd {
304     HISYS_APP_START,
305     HISYS_JANK,
306     HISYS_RESPONSE,
307     HISYS_COMPLETED,
308     HISYSEVENT,
309     HISYS_PID,
310 };
311 const std::unordered_map<HisyseventCmd, std::string> HISYSEVENT_CMD_MAP = {
312     { HisyseventCmd::HISYS_APP_START, std::string("hisysevent -r -o PERFORMANCE -n APP_START") },
313     { HisyseventCmd::HISYS_JANK, std::string("hisysevent -r -o PERFORMANCE -n INTERACTION_JANK") },
314     { HisyseventCmd::HISYS_RESPONSE, std::string("hisysevent -r -n INTERACTION_RESPONSE_LATENCY") },
315     { HisyseventCmd::HISYS_COMPLETED, std::string("hisysevent -r -n INTERACTION_COMPLETED_LATENCY") },
316     { HisyseventCmd::HISYSEVENT, std::string("ps -ef |grep hisysevent") },
317     { HisyseventCmd::HISYS_PID, std::string("pidof hisysevent") },
318 };
319 }
320 }
321 #endif