106f6ba60Sopenharmony_ci/*
206f6ba60Sopenharmony_ci * Copyright (C) 2021 Huawei Device Co., Ltd.
306f6ba60Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
406f6ba60Sopenharmony_ci * you may not use this file except in compliance with the License.
506f6ba60Sopenharmony_ci * You may obtain a copy of the License at
606f6ba60Sopenharmony_ci *
706f6ba60Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0
806f6ba60Sopenharmony_ci *
906f6ba60Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1006f6ba60Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1106f6ba60Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1206f6ba60Sopenharmony_ci * See the License for the specific language governing permissions and
1306f6ba60Sopenharmony_ci * limitations under the License.
1406f6ba60Sopenharmony_ci */
1506f6ba60Sopenharmony_ci
1606f6ba60Sopenharmony_ci#ifndef SMARTPERF_COMMAND_H
1706f6ba60Sopenharmony_ci#define SMARTPERF_COMMAND_H
1806f6ba60Sopenharmony_ci
1906f6ba60Sopenharmony_ci#include <iostream>
2006f6ba60Sopenharmony_ci#include <vector>
2106f6ba60Sopenharmony_ci#include "common.h"
2206f6ba60Sopenharmony_ci#include "sp_utils.h"
2306f6ba60Sopenharmony_ci#include "GpuCounter.h"
2406f6ba60Sopenharmony_ci
2506f6ba60Sopenharmony_cinamespace OHOS {
2606f6ba60Sopenharmony_cinamespace SmartPerf {
2706f6ba60Sopenharmony_ciclass SmartPerfCommand {
2806f6ba60Sopenharmony_cipublic:
2906f6ba60Sopenharmony_ci    const std::string smartPerfExeName = "SP_daemon";
3006f6ba60Sopenharmony_ci    const std::string smartPerfVersion = "1.0.4\n";
3106f6ba60Sopenharmony_ci    const std::string smartPerfMsgErr = "error input!\n use command '--help' get more information\n";
3206f6ba60Sopenharmony_ci    const std::string smartPerfMsg = "OpenHarmony performance testing tool SmartPerf command-line version\n"
3306f6ba60Sopenharmony_ci        "Usage: SP_daemon [options] [arguments]\n\n"
3406f6ba60Sopenharmony_ci        "options:\n"
3506f6ba60Sopenharmony_ci        " -N              set the collection times(default value is 0) range[1,2147483647], for example: -N 10 \n"
3606f6ba60Sopenharmony_ci        " -PKG            set package name, must add, for example: -PKG ohos.samples.ecg \n"
3706f6ba60Sopenharmony_ci        " -c              get device CPU frequency and CPU usage, process CPU usage and CPU load .. \n"
3806f6ba60Sopenharmony_ci        " -g              get device GPU frequency and GPU load  \n"
3906f6ba60Sopenharmony_ci        " -f              get app refresh fps(frames per second) and fps jitters and refreshrate \n"
4006f6ba60Sopenharmony_ci        " -profilerfps    get refresh fps and timestamp \n"
4106f6ba60Sopenharmony_ci        " -sections       set collection time period(using with profilerfps)\n"
4206f6ba60Sopenharmony_ci        " -t              get remaining battery power and temperature.. \n"
4306f6ba60Sopenharmony_ci        " -p              get battery power consumption and voltage(Not supported by some devices) \n"
4406f6ba60Sopenharmony_ci        " -r              get process memory and total memory \n"
4506f6ba60Sopenharmony_ci        " -snapshot       get screen capture\n"
4606f6ba60Sopenharmony_ci        " -net            get uplink and downlink traffic\n"
4706f6ba60Sopenharmony_ci        " -start          collection start command \n"
4806f6ba60Sopenharmony_ci        " -stop           collection stop command \n"
4906f6ba60Sopenharmony_ci        " -VIEW           set layler, for example: -VIEW DisplayNode \n"
5006f6ba60Sopenharmony_ci        " -OUT            set csv output path.\n"
5106f6ba60Sopenharmony_ci        " -d              get device DDR information \n"
5206f6ba60Sopenharmony_ci        " -screen         get screen resolution \n"
5306f6ba60Sopenharmony_ci        " -deviceinfo     get device information \n"
5406f6ba60Sopenharmony_ci        " -server         start a process to listen to the socket message of the start and stop commands \n"
5506f6ba60Sopenharmony_ci        " -clear          clear the process ID \n"
5606f6ba60Sopenharmony_ci        " -ohtestfps      used by the vilidator to obtain the fps, the collection times can be set \n"
5706f6ba60Sopenharmony_ci        " -editorServer   start a process to listen to the socket message of the editor \n"
5806f6ba60Sopenharmony_ci        " -recordcapacity get the battery level difference \n"
5906f6ba60Sopenharmony_ci        " --version       get version \n"
6006f6ba60Sopenharmony_ci        " --help          get help \n"
6106f6ba60Sopenharmony_ci        " -editor         scenario-based collection identifier, parameter configuration items can be added later \n"
6206f6ba60Sopenharmony_ci        " responseTime   get the page response delay after an application is operated \n"
6306f6ba60Sopenharmony_ci        " completeTime   get the page completion delay after an application is operated \n"
6406f6ba60Sopenharmony_ci        " fpsohtest      used by the vilidator to obtain the fps \n"
6506f6ba60Sopenharmony_ci        "example1:\n"
6606f6ba60Sopenharmony_ci        "SP_daemon -N 20 -c -g -t -p -r -net -snapshot -d \n"
6706f6ba60Sopenharmony_ci        "SP_daemon -N 20 -PKG ohos.samples.ecg -c -g -t -p -f -r -net -snapshot -d \n"
6806f6ba60Sopenharmony_ci        "SP_daemon -start -c \n"
6906f6ba60Sopenharmony_ci        "SP_daemon -stop \n"
7006f6ba60Sopenharmony_ci        "example2: These parameters need to be used separately \n"
7106f6ba60Sopenharmony_ci        "SP_daemon -screen \n"
7206f6ba60Sopenharmony_ci        "SP_daemon -deviceinfo \n"
7306f6ba60Sopenharmony_ci        "SP_daemon -server \n"
7406f6ba60Sopenharmony_ci        "SP_daemon -clear \n"
7506f6ba60Sopenharmony_ci        "SP_daemon -ohtestfps 10 \n"
7606f6ba60Sopenharmony_ci        "SP_daemon -editorServer \n"
7706f6ba60Sopenharmony_ci        "SP_daemon -recordcapacity \n"
7806f6ba60Sopenharmony_ci        "example3: These parameters need to be used separately \n"
7906f6ba60Sopenharmony_ci        "SP_daemon -editor responseTime ohos.samples.ecg app name \n"
8006f6ba60Sopenharmony_ci        "SP_daemon -editor completeTime ohos.samples.ecg app name \n"
8106f6ba60Sopenharmony_ci        "SP_daemon -editor fpsohtest \n";
8206f6ba60Sopenharmony_ci
8306f6ba60Sopenharmony_ci    const size_t oneParam = 1;
8406f6ba60Sopenharmony_ci    const size_t twoParam = 2;
8506f6ba60Sopenharmony_ci    const size_t threeParamMore = 3;
8606f6ba60Sopenharmony_ci    explicit SmartPerfCommand(std::vector<std::string> argv);
8706f6ba60Sopenharmony_ci    ~SmartPerfCommand() {};
8806f6ba60Sopenharmony_ci    static void InitSomething();
8906f6ba60Sopenharmony_ci    std::string ExecCommand();
9006f6ba60Sopenharmony_ci    void HelpCommand(CommandHelp type) const;
9106f6ba60Sopenharmony_ci    void HandleCommand(std::string argStr, const std::string &argStr1);
9206f6ba60Sopenharmony_ci    int GetItemInfo(std::multimap<std::string, std::string, decltype(SPUtils::Cmp) *> &spMap);
9306f6ba60Sopenharmony_ci    void PrintfExecCommand(const std::map<std::string, std::string> data) const;
9406f6ba60Sopenharmony_ci    void PrintMap(std::multimap<std::string, std::string, decltype(SPUtils::Cmp) *> &spMap, int index) const;
9506f6ba60Sopenharmony_ci    void CreateSocketThread() const;
9606f6ba60Sopenharmony_ci    void SaveGpuCounter() const;
9706f6ba60Sopenharmony_ci    // 采集次数
9806f6ba60Sopenharmony_ci    int num = 0;
9906f6ba60Sopenharmony_ci    // 包名
10006f6ba60Sopenharmony_ci    std::string pkgName = "";
10106f6ba60Sopenharmony_ci    // 图层名
10206f6ba60Sopenharmony_ci    std::string layerName = "";
10306f6ba60Sopenharmony_ci    // 是否开启trace 抓取
10406f6ba60Sopenharmony_ci    int trace = 0;
10506f6ba60Sopenharmony_ci    // csv输出路径
10606f6ba60Sopenharmony_ci    std::string outPath = "/data/local/tmp/data.csv";
10706f6ba60Sopenharmony_ci    std::string outPathParam = "";
10806f6ba60Sopenharmony_ci    // 指定进程pid
10906f6ba60Sopenharmony_ci    std::string pid = "";
11006f6ba60Sopenharmony_ci    // 采集配置项
11106f6ba60Sopenharmony_ci    std::vector<std::string> configs;
11206f6ba60Sopenharmony_ci    GpuCounter &gpuCounter = GpuCounter::GetInstance();
11306f6ba60Sopenharmony_ci};
11406f6ba60Sopenharmony_ci}
11506f6ba60Sopenharmony_ci}
11606f6ba60Sopenharmony_ci#endif // SMARTPERF_COMMAND_H