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("-CPU"), CommandType::CT_C }, 150 { std::string("-GPU"), CommandType::CT_G }, 151 { std::string("-FPS"), CommandType::CT_F }, 152 { std::string("-LOW_POWER"), CommandType::CT_F }, 153 { std::string("-TEMP"), CommandType::CT_T }, 154 { std::string("-POWER"), CommandType::CT_P }, 155 { std::string("-RAM"), CommandType::CT_R }, 156 { std::string("-TRACE"), CommandType::CT_TRACE }, 157 { std::string("-SCREEN"), CommandType::CT_SNAPSHOT }, 158 { std::string("-DDR"), CommandType::CT_D }, 159 { std::string("-INTERVAL"), CommandType::CT_INTERVAL }, 160 { std::string("-SESSIONID"), CommandType::CT_SESSIONID }, 161 { std::string("-NET"), CommandType::CT_NET }, 162 { std::string("-GPU_COUNTER"), CommandType::CT_GC }, 163 { std::string("-o"), CommandType::CT_O }, 164 { std::string("-lockfreq"), CommandType::CT_LF }, 165 { std::string("-aischedule"), CommandType::CT_AS }, 166 { std::string("-ge"), CommandType::CT_GE }, 167 { std::string("-ci"), CommandType::CT_CI }, 168 { std::string("-fc"), CommandType::CT_FC }, 169 { std::string("-HCI"), CommandType::CT_HCI }, 170 }; 171 172 const std::unordered_map<CommandType, std::string> COMMAND_MAP_REVERSE = { 173 { CommandType::CT_N, std::string("-N") }, 174 { CommandType::CT_PKG, std::string("-PKG") }, 175 { CommandType::CT_PID, std::string("-PID") }, 176 { CommandType::CT_OUT, std::string("-OUT") }, 177 { CommandType::CT_C, std::string("-c") }, 178 { CommandType::CT_G, std::string("-g") }, 179 { CommandType::CT_F, std::string("-f") }, 180 { CommandType::CT_T, std::string("-t") }, 181 { CommandType::CT_P, std::string("-p") }, 182 { CommandType::CT_PRINT, std::string("-print") }, 183 { CommandType::CT_R, std::string("-r") }, 184 { CommandType::CT_TRACE, std::string("-TRACE") }, 185 { CommandType::CT_THREADS, std::string("-threads") }, 186 { CommandType::CT_SNAPSHOT, std::string("-snapshot") }, 187 { CommandType::CT_D, std::string("-d") }, 188 { CommandType::CT_INTERVAL, std::string("-INTERVAL") }, 189 { CommandType::CT_SESSIONID, std::string("-SESSIONID") }, 190 { CommandType::CT_NET, std::string("-net") }, 191 { CommandType::CT_VIEW, std::string("-VIEW") }, 192 { CommandType::CT_FL, std::string("-fl") }, 193 { CommandType::CT_FTL, std::string("-ftl") }, 194 { CommandType::CT_GC, std::string("-GPU_COUNTER") }, 195 { CommandType::CT_NAV, std::string("-nav") }, 196 { CommandType::CT_O, std::string("-o") }, 197 { CommandType::CT_LF, std::string("-lockfreq") }, 198 { CommandType::CT_AS, std::string("-aischedule") }, 199 { CommandType::CT_GE, std::string("-ge") }, 200 { CommandType::CT_CI, std::string("-ci") }, 201 { CommandType::CT_FC, std::string("-fc") }, 202 { CommandType::CT_HCI, std::string("-HCI") }, 203 }; 204 205 const std::unordered_map<std::string, CommandType> COMMAND_SHELL_MAP = { 206 { std::string("-N"), CommandType::CT_N }, 207 { std::string("-PKG"), CommandType::CT_PKG }, 208 { std::string("-PID"), CommandType::CT_PID }, 209 { std::string("-threads"), CommandType::CT_THREADS }, 210 { std::string("-c"), CommandType::CT_C }, 211 { std::string("-ci"), CommandType::CT_CI }, 212 { std::string("-g"), CommandType::CT_G }, 213 { std::string("-gc"), CommandType::CT_GC }, 214 { std::string("-f"), CommandType::CT_F }, 215 { std::string("-t"), CommandType::CT_T }, 216 { std::string("-p"), CommandType::CT_P }, 217 { std::string("-print"), CommandType::CT_PRINT }, 218 { std::string("-r"), CommandType::CT_R }, 219 { std::string("-snapshot"), CommandType::CT_SNAPSHOT }, 220 { std::string("-net"), CommandType::CT_NET }, 221 { std::string("-VIEW"), CommandType::CT_VIEW }, 222 { std::string("-OUT"), CommandType::CT_OUT }, 223 { std::string("-d"), CommandType::CT_D }, 224 { std::string("-fl"), CommandType::CT_FL }, 225 { std::string("-ftl"), CommandType::CT_FTL }, 226 { std::string("-nav"), CommandType::CT_NAV }, 227 }; 228 229 const std::unordered_map<CommandHelp, std::string> COMMAND_HELP_MAP = { 230 { CommandHelp::HELP, std::string("--help") }, 231 { CommandHelp::VERSION, std::string("--version") }, 232 { CommandHelp::SCREEN, std::string("-screen") }, 233 { CommandHelp::CLEAR, std::string("-clear") }, 234 { CommandHelp::CLEARALL, std::string("-clearAll") }, 235 { CommandHelp::SERVER, std::string("-server") }, 236 { CommandHelp::EDITORSERVER, std::string("-editorServer") }, 237 { CommandHelp::DEVICESERVER, std::string("-deviceServer") }, 238 }; 239 240 enum class CmdCommand { 241 HITRACE_1024, 242 HITRACE_2048, 243 HITRACE_CMD, 244 CREAT_DIR, 245 SNAPSHOT, 246 SERVER, 247 OHTESTFPS, 248 RM_FILE, 249 TASKSET, 250 PROC_STAT, 251 HIPROFILER, 252 PERF, 253 HIPROFILER_CMD, 254 HIPROFILER_PID, 255 KILL_CMD, 256 PIDOF_SP, 257 SERVER_GREP, 258 EDITOR_SERVER_GREP, 259 UINPUT_BACK, 260 TIMESTAMPS, 261 USER_PERMISSIONS, 262 REMOVE, 263 CP, 264 TAR, 265 GET_HILOG, 266 CPU_FREQ, 267 }; 268 269 const std::unordered_map<CmdCommand, std::string> CMD_COMMAND_MAP = { 270 { CmdCommand::HITRACE_1024, std::string( 271 "hitrace --trace_clock mono -t 10 -b 102400 --overwrite idle ace app ohos ability graphic " 272 "nweb sched freq sync workq multimodalinput > ") }, 273 { CmdCommand::HITRACE_2048, std::string( 274 "hitrace --trace_clock mono -t 10 -b 204800 --overwrite idle ace app ohos ability graphic " 275 "nweb sched freq sync workq multimodalinput > ") }, 276 { CmdCommand::HITRACE_CMD, std::string("ps -ef |grep hitrace |grep -v grep") }, 277 { CmdCommand::CREAT_DIR, std::string("mkdir -p -m 777 ") }, 278 { CmdCommand::SNAPSHOT, std::string("snapshot_display -f ") }, 279 { CmdCommand::SERVER, std::string("SP_daemon -server") }, 280 { CmdCommand::OHTESTFPS, std::string("SP_daemon -ohtestfps 10") }, 281 { CmdCommand::RM_FILE, std::string("rm -rfv /data/local/tmp/") }, 282 { CmdCommand::TASKSET, std::string("taskset -p f ") }, 283 { CmdCommand::PROC_STAT, std::string("chmod o+r /proc/stat") }, 284 { CmdCommand::HIPROFILER, std::string("rm -f /data/local/tmp/hiprofiler_[0-9]*.htrace") }, 285 { CmdCommand::PERF, std::string("rm -f /data/local/tmp/perf_[0-9]*.data") }, 286 { CmdCommand::HIPROFILER_CMD, std::string("ps -ef |grep hiprofiler_cmd |grep -v grep") }, 287 { CmdCommand::HIPROFILER_PID, std::string("pidof hiprofiler_cmd") }, 288 { CmdCommand::KILL_CMD, std::string("kill ") }, 289 { CmdCommand::PIDOF_SP, std::string("pidof SP_daemon") }, 290 { CmdCommand::SERVER_GREP, std::string("ps -ef | grep -v grep | grep 'SP_daemon -server'") }, 291 { CmdCommand::EDITOR_SERVER_GREP, std::string("ps -ef | grep -v grep | grep 'SP_daemon -editorServer'") }, 292 { CmdCommand::UINPUT_BACK, std::string("uinput -K -d 2076 -d 2020 -u 2076 -u 2020") }, 293 { CmdCommand::TIMESTAMPS, std::string("timestamps") }, 294 { CmdCommand::USER_PERMISSIONS, std::string("whoami") }, 295 { CmdCommand::REMOVE, std::string("rm -rf ") }, 296 { CmdCommand::CP, std::string("cp ") }, 297 { CmdCommand::TAR, std::string("tar -czf ") }, 298 { CmdCommand::GET_HILOG, std::string("timeout 1s hilog > ") }, 299 { CmdCommand::CPU_FREQ, std::string("/sys/devices/system/cpu/cpufreq/") }, 300 }; 301 302 enum class DeviceCmd { 303 SN, 304 DEVICET_NAME, 305 BRAND, 306 VERSION, 307 ABILIST, 308 NAME, 309 MODEL, 310 FULL_NAME, 311 }; 312 const std::unordered_map<DeviceCmd, std::string> DEVICE_CMD_MAP = { 313 { DeviceCmd::SN, std::string("ohos.boot.sn") }, 314 { DeviceCmd::DEVICET_NAME, std::string("ohos.boot.hardware") }, 315 { DeviceCmd::BRAND, std::string("const.product.brand") }, 316 { DeviceCmd::VERSION, std::string("const.product.software.version") }, 317 { DeviceCmd::ABILIST, std::string("const.product.cpu.abilist") }, 318 { DeviceCmd::NAME, std::string("const.product.name") }, 319 { DeviceCmd::MODEL, std::string("const.product.model") }, 320 { DeviceCmd::FULL_NAME, std::string("const.ohos.fullname") }, 321 }; 322 323 enum class HidumperCmd { 324 DUMPER_DUBAI_B, 325 DUMPER_DUBAI_F, 326 DUMPER_SURFACE, 327 DUMPER_HEAD, 328 DUMPER_SCREEN, 329 DUMPER_A_A, 330 DUMPER_NAV, 331 DUMPER_MEM, 332 DUMPER_RS_TREE, 333 }; 334 const std::unordered_map<HidumperCmd, std::string> HIDUMPER_CMD_MAP = { 335 { HidumperCmd::DUMPER_DUBAI_B, std::string("hidumper -s 1213 -a '-b'") }, 336 { HidumperCmd::DUMPER_DUBAI_F, std::string("hidumper -s 1213 -a '-f'") }, 337 { HidumperCmd::DUMPER_SURFACE, std::string("hidumper -s 10 -a surface | grep surface") }, 338 { HidumperCmd::DUMPER_HEAD, std::string( 339 "hidumper -s AbilityManagerService -a '-a' | grep 'bundle name' | head -n 1") }, 340 { HidumperCmd::DUMPER_SCREEN, std::string("hidumper -s 10 -a screen") }, 341 { HidumperCmd::DUMPER_A_A, std::string("hidumper -s WindowManagerService -a '-a'") }, 342 { HidumperCmd::DUMPER_NAV, std::string("hidumper -s WindowManagerService -a '-w ") }, 343 { HidumperCmd::DUMPER_MEM, std::string("hidumper --mem ") }, 344 { HidumperCmd::DUMPER_RS_TREE, std::string("hidumper -s 10 -a RSTree | grep SURFACE_NODE") }, 345 }; 346 347 enum class HisyseventCmd { 348 HISYS_APP_START, 349 HISYS_JANK, 350 HISYS_RESPONSE, 351 HISYS_COMPLETED, 352 HISYSEVENT, 353 HISYS_PID, 354 HISYS_SCROLL_ANIMATION, 355 }; 356 const std::unordered_map<HisyseventCmd, std::string> HISYSEVENT_CMD_MAP = { 357 { HisyseventCmd::HISYS_APP_START, std::string("hisysevent -r -o PERFORMANCE -n APP_START") }, 358 { HisyseventCmd::HISYS_JANK, std::string("hisysevent -r -o PERFORMANCE -n INTERACTION_JANK") }, 359 { HisyseventCmd::HISYS_SCROLL_ANIMATION, std::string("hisysevent -r -o PERFORMANCE -n SCROLL_ANIMATION") }, 360 { HisyseventCmd::HISYS_RESPONSE, std::string("hisysevent -r -n INTERACTION_RESPONSE_LATENCY") }, 361 { HisyseventCmd::HISYS_COMPLETED, std::string("hisysevent -r -n INTERACTION_COMPLETED_LATENCY") }, 362 { HisyseventCmd::HISYSEVENT, std::string("ps -ef |grep hisysevent") }, 363 { HisyseventCmd::HISYS_PID, std::string("pidof hisysevent") }, 364 }; 365 } 366 } 367 #endif