• 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 
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         " -gc             get gpu counter default frequency is 50 \n"
45         " -f              get app refresh fps(frames per second) and fps jitters and refreshrate \n"
46         " -profilerfps    get refresh fps and timestamp \n"
47         " -sections       set collection time period(using with profilerfps)\n"
48         " -t              get remaining battery power and temperature.. \n"
49         " -p              get battery power consumption and voltage(Not supported by some devices) \n"
50         " -print          start mode print log \n"
51         " -r              get process memory and total memory \n"
52         " -snapshot       get screen capture\n"
53         " -nav            get page navigation information\n"
54         " -net            get uplink and downlink traffic\n"
55         " -start          collection start command \n"
56         " -stop           collection stop command \n"
57         " -VIEW           set layler, for example: -VIEW DisplayNode \n"
58         " -OUT            set csv output path.\n"
59         " -d              get device DDR information \n"
60         " -screen         get screen resolution \n"
61         " -deviceinfo     get device information \n"
62         " -server         start a process to listen to the socket message of the start and stop commands \n"
63         " -clear          clear the process ID \n"
64         " -ohtestfps      used by the vilidator to obtain the fps, the collection times can be set \n"
65         " -recordcapacity get the battery level difference \n"
66         " --version       get version \n"
67         " --help          get help \n"
68         " -editor         scenario-based collection identifier, parameter configuration items can be added later \n"
69         " responseTime   get the page response delay after an application is operated \n"
70         " completeTime   get the page completion delay after an application is operated \n"
71         " fpsohtest      used by the vilidator to obtain the fps \n"
72         "example1:\n"
73         "SP_daemon -N 20 -c -g -t -p -r -net -snapshot -d \n"
74         "SP_daemon -N 20 -PKG ohos.samples.ecg -c -g -t -p -f -r -net -snapshot -d -nav -gc \n"
75         "SP_daemon -start -c \n"
76         "SP_daemon -stop \n"
77         "example2: These parameters need to be used separately \n"
78         "SP_daemon -screen \n"
79         "SP_daemon -deviceinfo \n"
80         "SP_daemon -server \n"
81         "SP_daemon -clear \n"
82         "SP_daemon -ohtestfps 10 \n"
83         "SP_daemon -recordcapacity \n"
84         "example3: These parameters need to be used separately \n"
85         "SP_daemon -editor responseTime ohos.samples.ecg app name \n"
86         "SP_daemon -editor completeTime ohos.samples.ecg app name \n"
87         "SP_daemon -editor fpsohtest \n";
88 
89     const size_t oneParam = 1;
90     const size_t twoParam = 2;
91     const size_t threeParamMore = 3;
92     const size_t serverCommandLength = 14;  // -deviceServer: 与 -editorServer: 的长度
93     explicit SmartPerfCommand(std::vector<std::string>& argv);
~SmartPerfCommand()94     ~SmartPerfCommand() {};
95     static void InitSomething();
96     std::string ExecCommand();
97     void HelpCommand(CommandHelp type, const std::string& token) const;
98     void CreateSocketThread() const;
99     void DeviceServer(int isNeedDaemon) const;
100     TaskManager taskMgr_;
101 };
102 }
103 }
104 #endif // SMARTPERF_COMMAND_H