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 
25 namespace OHOS {
26 namespace SmartPerf {
27 class SmartPerfCommand {
28 public:
29     const std::string smartPerfExeName = "SP_daemon";
30     const std::string smartPerfVersion = "1.0.4\n";
31     const std::string smartPerfMsgErr = "error input!\n use command '--help' get more information\n";
32     const std::string smartPerfMsg = "OpenHarmony performance testing tool SmartPerf command-line version\n"
33         "Usage: SP_daemon [options] [arguments]\n\n"
34         "options:\n"
35         " -N              set the collection times(default value is 0) range[1,2147483647], for example: -N 10 \n"
36         " -PKG            set package name, must add, for example: -PKG ohos.samples.ecg \n"
37         " -c              get device CPU frequency and CPU usage, process CPU usage and CPU load .. \n"
38         " -g              get device GPU frequency and GPU load  \n"
39         " -f              get app refresh fps(frames per second) and fps jitters and refreshrate \n"
40         " -profilerfps    get refresh fps and timestamp \n"
41         " -sections       set collection time period(using with profilerfps)\n"
42         " -t              get remaining battery power and temperature.. \n"
43         " -p              get battery power consumption and voltage(Not supported by some devices) \n"
44         " -r              get process memory and total memory \n"
45         " -snapshot       get screen capture\n"
46         " -net            get uplink and downlink traffic\n"
47         " -start          collection start command \n"
48         " -stop           collection stop command \n"
49         " -VIEW           set layler, for example: -VIEW DisplayNode \n"
50         " -OUT            set csv output path.\n"
51         " -d              get device DDR information \n"
52         " -screen         get screen resolution \n"
53         " -deviceinfo     get device information \n"
54         " -server         start a process to listen to the socket message of the start and stop commands \n"
55         " -clear          clear the process ID \n"
56         " -ohtestfps      used by the vilidator to obtain the fps, the collection times can be set \n"
57         " -editorServer   start a process to listen to the socket message of the editor \n"
58         " -recordcapacity get the battery level difference \n"
59         " --version       get version \n"
60         " --help          get help \n"
61         " -editor         scenario-based collection identifier, parameter configuration items can be added later \n"
62         " responseTime   get the page response delay after an application is operated \n"
63         " completeTime   get the page completion delay after an application is operated \n"
64         " fpsohtest      used by the vilidator to obtain the fps \n"
65         "example1:\n"
66         "SP_daemon -N 20 -c -g -t -p -r -net -snapshot -d \n"
67         "SP_daemon -N 20 -PKG ohos.samples.ecg -c -g -t -p -f -r -net -snapshot -d \n"
68         "SP_daemon -start -c \n"
69         "SP_daemon -stop \n"
70         "example2: These parameters need to be used separately \n"
71         "SP_daemon -screen \n"
72         "SP_daemon -deviceinfo \n"
73         "SP_daemon -server \n"
74         "SP_daemon -clear \n"
75         "SP_daemon -ohtestfps 10 \n"
76         "SP_daemon -editorServer \n"
77         "SP_daemon -recordcapacity \n"
78         "example3: These parameters need to be used separately \n"
79         "SP_daemon -editor responseTime ohos.samples.ecg app name \n"
80         "SP_daemon -editor completeTime ohos.samples.ecg app name \n"
81         "SP_daemon -editor fpsohtest \n";
82 
83     const size_t oneParam = 1;
84     const size_t twoParam = 2;
85     const size_t threeParamMore = 3;
86     explicit SmartPerfCommand(std::vector<std::string> argv);
~SmartPerfCommand()87     ~SmartPerfCommand() {};
88     static void InitSomething();
89     std::string ExecCommand();
90     void HelpCommand(CommandHelp type) const;
91     void HandleCommand(std::string argStr, const std::string &argStr1);
92     int GetItemInfo(std::multimap<std::string, std::string, decltype(SPUtils::Cmp) *> &spMap);
93     void PrintfExecCommand(const std::map<std::string, std::string> data) const;
94     void PrintMap(std::multimap<std::string, std::string, decltype(SPUtils::Cmp) *> &spMap, int index) const;
95     void CreateSocketThread() const;
96     void SaveGpuCounter() const;
97     // 采集次数
98     int num = 0;
99     // 包名
100     std::string pkgName = "";
101     // 图层名
102     std::string layerName = "";
103     // 是否开启trace 抓取
104     int trace = 0;
105     // csv输出路径
106     std::string outPath = "/data/local/tmp/data.csv";
107     std::string outPathParam = "";
108     // 指定进程pid
109     std::string pid = "";
110     // 采集配置项
111     std::vector<std::string> configs;
112     GpuCounter &gpuCounter = GpuCounter::GetInstance();
113 };
114 }
115 }
116 #endif // SMARTPERF_COMMAND_H