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