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