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