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