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 16 #ifndef SMARTPERF_COMMAND_H 17 #define SMARTPERF_COMMAND_H 18 19 #include <iostream> 20 #include <vector> 21 #include "common.h" 22 #include "sp_utils.h" 23 #include "GpuCounter.h" 24 #include "GameEvent.h" 25 #include "task_manager.h" 26 27 namespace OHOS { 28 namespace SmartPerf { 29 class SmartPerfCommand { 30 public: 31 const std::string smartPerfExeName = "SP_daemon"; 32 const std::string smartPerfMsgErr = "error input!\n use command '--help' get more information\n"; 33 const std::string smartPerfMsg = "OpenHarmony performance testing tool SmartPerf command-line version\n" 34 "Usage: SP_daemon [options] [arguments]\n\n" 35 "options:\n" 36 " -N set the collection times(default value is 0) range[1,2147483647], for example: -N 10 \n" 37 " -PKG set package name, must add, for example: -PKG ohos.samples.ecg \n" 38 " -PID set process pid, must add, for example: -PID 3568 \n" 39 " -threads get threads, must add -PID or -PKG for example: \n" 40 "\t\t -threads -PID 3568 or -threads -PKG ohos.samples.ecg \n" 41 " -c get device CPU frequency and CPU usage, process CPU usage and CPU load .. \n" 42 " -ci get cpu instructions and cycles \n" 43 " -g get device GPU frequency and GPU load \n" 44 " -f get app refresh fps(frames per second) and fps jitters and refreshrate \n" 45 " -profilerfps get refresh fps and timestamp \n" 46 " -sections set collection time period(using with profilerfps)\n" 47 " -t get remaining battery power and temperature.. \n" 48 " -p get battery power consumption and voltage(Not supported by some devices) \n" 49 " -print start mode print log \n" 50 " -r get process memory and total memory \n" 51 " -snapshot get screen capture\n" 52 " -net get uplink and downlink traffic\n" 53 " -start collection start command \n" 54 " -stop collection stop command \n" 55 " -VIEW set layler, for example: -VIEW DisplayNode \n" 56 " -OUT set csv output path.\n" 57 " -d get device DDR information \n" 58 " -screen get screen resolution \n" 59 " -deviceinfo get device information \n" 60 " -server start a process to listen to the socket message of the start and stop commands \n" 61 " -clear clear the process ID \n" 62 " -ohtestfps used by the vilidator to obtain the fps, the collection times can be set \n" 63 " -recordcapacity get the battery level difference \n" 64 " --version get version \n" 65 " --help get help \n" 66 " -editor scenario-based collection identifier, parameter configuration items can be added later \n" 67 " responseTime get the page response delay after an application is operated \n" 68 " completeTime get the page completion delay after an application is operated \n" 69 " fpsohtest used by the vilidator to obtain the fps \n" 70 "example1:\n" 71 "SP_daemon -N 20 -c -g -t -p -r -net -snapshot -d \n" 72 "SP_daemon -N 20 -PKG ohos.samples.ecg -c -g -t -p -f -r -net -snapshot -d \n" 73 "SP_daemon -start -c \n" 74 "SP_daemon -stop \n" 75 "example2: These parameters need to be used separately \n" 76 "SP_daemon -screen \n" 77 "SP_daemon -deviceinfo \n" 78 "SP_daemon -server \n" 79 "SP_daemon -clear \n" 80 "SP_daemon -ohtestfps 10 \n" 81 "SP_daemon -recordcapacity \n" 82 "example3: These parameters need to be used separately \n" 83 "SP_daemon -editor responseTime ohos.samples.ecg app name \n" 84 "SP_daemon -editor completeTime ohos.samples.ecg app name \n" 85 "SP_daemon -editor fpsohtest \n"; 86 87 const size_t oneParam = 1; 88 const size_t twoParam = 2; 89 const size_t threeParamMore = 3; 90 const size_t serverCommandLength = 14; // -deviceServer: 与 -editorServer: 的长度 91 explicit SmartPerfCommand(std::vector<std::string>& argv); ~SmartPerfCommand()92 ~SmartPerfCommand() {}; 93 static void InitSomething(); 94 std::string ExecCommand(); 95 void HelpCommand(CommandHelp type, const std::string& token) const; 96 void CreateSocketThread() const; 97 void DeviceServer(int isNeedDaemon) const; 98 TaskManager taskMgr_; 99 }; 100 } 101 } 102 #endif // SMARTPERF_COMMAND_H