LCOV - code coverage report
Current view: top level - aicpu_cust_schedule/core - aicpusd_args_parser.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 78.2 % 55 43
Test Date: 2026-07-28 10:54:05 Functions: 100.0 % 19 19

            Line data    Source code
       1              : /**
       2              :  * Copyright (c) 2025 Huawei Technologies Co., Ltd.
       3              :  * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
       4              :  * CANN Open Software License Agreement Version 2.0 (the "License").
       5              :  * Please refer to the License for details. You may not use this file except in compliance with the License.
       6              :  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
       7              :  * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
       8              :  * See LICENSE in the root of the software repository for the full text of the License.
       9              :  */
      10              : 
      11              : #ifndef CORE_AICPUSD_ARGS_PARSER_H
      12              : #define CORE_AICPUSD_ARGS_PARSER_H
      13              : 
      14              : #include <string>
      15              : #include <vector>
      16              : #include <unordered_map>
      17              : #include "aicpusd_info.h"
      18              : #include "aicpusd_common.h"
      19              : #include "profiling_adp.h"
      20              : 
      21              : namespace AicpuSchedule {
      22              : namespace {
      23              :     const std::string PARAM_DEVICEID = "--deviceId=";
      24              :     const std::string PARAM_HOST_PID = "--pid=";
      25              :     const std::string PARAM_SIGN = "--pidSign=";
      26              :     const std::string PARAM_PROFILING_MODE = "--profilingMode=";
      27              :     const std::string PARAM_CUSTSOPATH = "--custSoPath=";
      28              :     const std::string PARAM_AICPUPID = "--aicpuPid=";
      29              :     const std::string PARAM_LOGLEVEL = "--logLevelInPid=";
      30              :     const std::string PARAM_CCECPULOGLEVEL = "--ccecpuLogLevel=";
      31              :     const std::string PARAM_AICPULOGLEVEL = "--aicpuLogLevel=";
      32              :     const std::string PARAM_VFID = "--vfId=";
      33              :     const std::string PARAM_GRP_NAME_NUM = "--groupNameNum=";
      34              :     const std::string PARAM_GRP_NAME_LIST = "--groupNameList=";
      35              :     const std::string PARAM_CRL_CPU_LIST = "--ctrolCpuList=";
      36              :     const std::string PARAM_TSD_PID = "--tsdPid=";
      37              :     constexpr int32_t ERROR_LOG = 3;
      38              :     constexpr int32_t EVENT_LOG = 1;
      39              :     constexpr int32_t DEBUG_LOG = 0;
      40              :     constexpr int32_t VF_ID_MAX = 16;
      41              :     constexpr int32_t DEVICE_MODE_MAX = 1;
      42              :     constexpr int32_t AICPUFW_CHIP_NUM_MAX = 64;
      43              :     constexpr int32_t VALUE_FOR_CALCULATE_LOG_LEVEL = 100;
      44              : }
      45              : 
      46              :     class ArgsParser {
      47              :     public:
      48          154 :         ArgsParser() : deviceId_(0U), hostPid_(0U), pidSign_(""), profilingMode_(PROFILING_CLOSE), vfId_(0U),
      49           77 :                        logLevel_(ERROR_LOG), eventLevel_(EVENT_LOG), ccecpulogLevel_(-1), aicpulogLevel_(-1),
      50          462 :                        custSoPath_(""), aicpuPid_(0U), grpNameNum_(0U), grpNameList_({}), controlCpuList_({}),
      51           77 :                        tsdPid_(0U), withDeviceId_(false),withHostPid_(false), withPidSign_(false), 
      52           77 :                        withCustSoPath_(false), withAicpuPid_(false), withGrpNameNum_(false), withGrpNameList_(false), 
      53           77 :                        withControlCpuList_(false), withTsdPid_(false),
      54         1232 :                        argsParseFuncMap_({{PARAM_DEVICEID, &ArgsParser::ParseDeviceId},
      55            0 :                                           {PARAM_HOST_PID, &ArgsParser::ParseHostPid},
      56            0 :                                           {PARAM_SIGN, &ArgsParser::ParseSign},
      57            0 :                                           {PARAM_PROFILING_MODE, &ArgsParser::ParseProfilingMode},
      58            0 :                                           {PARAM_LOGLEVEL, &ArgsParser::ParseLogAndEventLevel},
      59            0 :                                           {PARAM_CCECPULOGLEVEL, &ArgsParser::ParseCcecpuLogLevel},
      60            0 :                                           {PARAM_AICPULOGLEVEL, &ArgsParser::ParseAicpuLogLevel},
      61            0 :                                           {PARAM_VFID, &ArgsParser::ParseVfId},
      62            0 :                                           {PARAM_CUSTSOPATH, &ArgsParser::ParseCustSoPath},
      63            0 :                                           {PARAM_AICPUPID, &ArgsParser::ParseAicpuPid},
      64            0 :                                           {PARAM_GRP_NAME_NUM, &ArgsParser::ParseGrpNameNum},
      65            0 :                                           {PARAM_GRP_NAME_LIST, &ArgsParser::ParseGrpNameList},
      66            0 :                                           {PARAM_CRL_CPU_LIST, &ArgsParser::ParseCtrolCpuList},
      67          154 :                                           {PARAM_TSD_PID, &ArgsParser::ParseTsdPid}}) {};
      68              : 
      69           77 :         ~ArgsParser() = default;
      70              : 
      71              :         bool ParseArgs(const int32_t argc, const char_t * const argv[]);
      72              : 
      73              :         std::string GetParaParsedStr();
      74              : 
      75           49 :         inline uint32_t GetDeviceId() const
      76              :         {
      77           49 :             return deviceId_;
      78              :         }
      79              : 
      80           48 :         inline uint32_t GetHostPid() const
      81              :         {
      82           48 :             return hostPid_;
      83              :         }
      84              : 
      85           25 :         inline std::string GetPidSign() const
      86              :         {
      87           25 :             return pidSign_;
      88              :         }
      89              : 
      90           26 :         inline uint32_t GetProfilingMode() const
      91              :         {
      92           26 :             return profilingMode_;
      93              :         }
      94              : 
      95           26 :         inline uint32_t GetVfId() const
      96              :         {
      97           26 :             return vfId_;
      98              :         }
      99              : 
     100           26 :         inline int32_t GetLogLevel() const
     101              :         {
     102           26 :             return logLevel_;
     103              :         }
     104              : 
     105           26 :         inline int32_t GetEventLevel() const
     106              :         {
     107           26 :             return eventLevel_;
     108              :         }
     109              : 
     110           22 :         inline int32_t GetCcecpuLogLevel() const
     111              :         {
     112           22 :             return ccecpulogLevel_;
     113              :         }
     114              : 
     115           22 :         inline int32_t GetAicpuLogLevel() const
     116              :         {
     117           22 :             return aicpulogLevel_;
     118              :         }
     119              : 
     120           24 :         inline std::string GetCustSoPath() const
     121              :         {
     122           24 :             return custSoPath_;
     123              :         }
     124              : 
     125           26 :         inline uint32_t GetAicpuPid() const
     126              :         {
     127           26 :             return aicpuPid_;
     128              :         }
     129              : 
     130           50 :         inline uint32_t GetGrpNameNum() const
     131              :         {
     132           50 :             return grpNameNum_;
     133              :         }
     134              : 
     135           20 :         inline std::vector<std::string> GetGrpNameList() const
     136              :         {
     137           20 :             return grpNameList_;
     138              :         }
     139              : 
     140           10 :         inline std::vector<uint32_t> GetControlCpuList() const
     141              :         {
     142           10 :             return controlCpuList_;
     143              :         }
     144           23 :         inline bool HasControlCpuList() const
     145              :         {
     146           23 :             return withControlCpuList_;
     147              :         }
     148           66 :         inline bool HasTsdPid() const
     149              :         {
     150           66 :             return withTsdPid_;
     151              :         }
     152           26 :         inline uint32_t GetTsdPid() const
     153              :         {
     154           26 :             return tsdPid_;
     155              :         }
     156              : 
     157              :     private:
     158              :         bool CheckRequiredParas() const;
     159              :         bool ParseSinglePara(const std::string &singlePara);
     160              :         bool ParseDeviceId(const std::string &para);
     161              :         bool ParseHostPid(const std::string &para);
     162              :         bool ParseSign(const std::string &para);
     163              :         bool ParseProfilingMode(const std::string &para);
     164              :         bool ParseLogAndEventLevel(const std::string &para);
     165              :         bool ParseCcecpuLogLevel(const std::string &para);
     166              :         bool ParseAicpuLogLevel(const std::string &para);
     167              :         bool ParseVfId(const std::string &para);
     168              :         bool ParseCustSoPath(const std::string &para);
     169              :         bool ParseAicpuPid(const std::string &para);
     170              :         bool ParseGrpNameNum(const std::string &para);
     171              :         bool ParseGrpNameList(const std::string &para);
     172              :         bool ParseCtrolCpuList(const std::string &para);
     173              :         static void SplitControlCpuList(const std::string &cupListPara, std::vector<uint32_t> &controlCpuList);
     174              :         static void SplitGrpNameList(const std::string &grpNamePara, std::vector<std::string> &grpNameList);
     175              :         bool ParseTsdPid(const std::string &para);
     176              :         ArgsParser(ArgsParser const &) = delete;
     177              :         ArgsParser &operator=(ArgsParser const &) = delete;
     178              :         ArgsParser(ArgsParser &&) = delete;
     179              :         ArgsParser &operator=(ArgsParser &&) = delete;
     180              : 
     181              :         uint32_t deviceId_;
     182              :         uint32_t hostPid_;
     183              :         std::string pidSign_;
     184              :         uint32_t profilingMode_;
     185              :         uint32_t vfId_;
     186              :         int32_t logLevel_;
     187              :         int32_t eventLevel_;
     188              :         int32_t ccecpulogLevel_;
     189              :         int32_t aicpulogLevel_;
     190              :         std::string custSoPath_;
     191              :         uint32_t aicpuPid_;
     192              :         uint32_t grpNameNum_;
     193              :         std::vector<std::string> grpNameList_;
     194              :         std::vector<uint32_t> controlCpuList_;
     195              :         uint32_t tsdPid_;
     196              :         bool withDeviceId_;
     197              :         bool withHostPid_;
     198              :         bool withPidSign_;
     199              :         bool withCustSoPath_;
     200              :         bool withAicpuPid_;
     201              :         bool withGrpNameNum_;
     202              :         bool withGrpNameList_;
     203              :         bool withControlCpuList_;
     204              :         bool withTsdPid_;
     205              :         using SingleParaParseFunc = bool (ArgsParser::*)(const std::string &);
     206              :         const std::unordered_map<std::string, SingleParaParseFunc> argsParseFuncMap_;
     207              :     };
     208              : } // namespace AicpuSchedule
     209              : 
     210              : #endif // CORE_AICPUSD_ARGS_PARSER_H
        

Generated by: LCOV version 2.0-1