LCOV - code coverage report
Current view: top level - server - qs_args_parser.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 76.3 % 59 45
Test Date: 2026-07-28 10:54:05 Functions: 100.0 % 20 20

            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 QS_ARGS_PARSER_H
      12              : #define QS_ARGS_PARSER_H
      13              : 
      14              : #include <string>
      15              : #include <vector>
      16              : #include <unordered_map>
      17              : #include "bqs_msg.h"
      18              : 
      19              : namespace bqs {
      20              : namespace {
      21              :     const std::string PARAM_DEVICEID = "--deviceId=";
      22              :     const std::string PARAM_HOST_PID = "--pid=";
      23              :     const std::string PARAM_PIDSIGN = "--pidSign=";
      24              :     const std::string PARAM_VFID = "--vfId=";
      25              :     const std::string PARAM_LOGLEVEL = "--logLevelInPid=";
      26              :     const std::string PARAM_AICPULOGLEVEL = "--aicpuLogLevel=";
      27              :     const std::string PARAM_DEPLOY_MODE = "--deployMode=";
      28              :     const std::string PARAM_RESCHED_INTERVAL = "--reschedInterval=";
      29              :     const std::string PARAM_GRP_NAME = "--qsInitGroupName=";
      30              :     const std::string PARAM_SCHED_POLICY = "--schedPolicy=";
      31              :     const std::string PARAM_STARTER = "--starter=";
      32              :     const std::string PARAM_PROF_CFG_DATA = "--profCfgData=";
      33              :     const std::string PARAM_PROF_FLAG = "--profFlag=";
      34              :     const std::string PARAM_ABNORMAL_INTERVAL = "--abnormalInterval=";
      35              :     const std::string PARAM_RESOURCE_LIST = "--resIds=";
      36              :     const std::string PARAM_DEVICEIDS_LIST = "--devIds=";
      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 QS_FW_CHIP_NUM_MAX = 64;
      41              :     constexpr int32_t VF_ID_MAX = 16;
      42              :     constexpr int32_t VALUE_FOR_CALCULATE_LOG_LEVEL = 100;
      43              :     constexpr int32_t SUCCESS_VALUE = 0;
      44              :     constexpr int32_t RESCHED_INTERVAL_CLOSE = -1;
      45              :     constexpr int32_t RESCHED_INTERVAL_DEFAULT = 30;
      46              :     constexpr int32_t RESCHED_INTERVAL_MAX = 1000;
      47              :     constexpr int32_t ABNORMAL_INTERVAL_MIN = 0;
      48              :     constexpr int32_t ABNORMAL_INTERVAL_DEFAULT = 10;
      49              :     constexpr int32_t ABNORMAL_INTERVAL_MAX = 1000;
      50              : 
      51              : }
      52              : 
      53              :     class ArgsParser {
      54              :     public:
      55          156 :         ArgsParser() : deviceId_(0U), hostPid_(0U), pidSign_(""), vfId_(0U), logLevel_(ERROR_LOG),
      56           78 :                        eventLevel_(EVENT_LOG), aicpulogLevel_(-1), deployMode_(QueueSchedulerRunMode::SINGLE_PROCESS),
      57          156 :                        reschedInterval_(RESCHED_INTERVAL_DEFAULT), groupName_(""), schedPolicy_(0U),
      58          156 :                        starter_(QsStartType::START_BY_TSD), profCfgData_(""), abnormalInterval_(ABNORMAL_INTERVAL_DEFAULT),
      59           78 :                        profFlag_(false), withDeviceId_(false), withHostPid_(false),
      60           78 :                        withPidSign_(false), withVfId_(false), withLogLevel_(false), withGroupName_(false), withStarter_(false),
      61         1404 :                        argsParseFuncMap_({{PARAM_DEVICEID, &ArgsParser::ParseDeviceId},
      62            0 :                                           {PARAM_HOST_PID, &ArgsParser::ParseHostPid},
      63            0 :                                           {PARAM_PIDSIGN, &ArgsParser::ParsePidSign},
      64            0 :                                           {PARAM_VFID, &ArgsParser::ParseVfId},
      65            0 :                                           {PARAM_LOGLEVEL, &ArgsParser::ParseLogAndEventLevel},
      66            0 :                                           {PARAM_AICPULOGLEVEL, &ArgsParser::ParseAicpuLogLevel},
      67            0 :                                           {PARAM_DEPLOY_MODE, &ArgsParser::ParseDeployMode},
      68            0 :                                           {PARAM_RESCHED_INTERVAL, &ArgsParser::ParseReschedInterval},
      69            0 :                                           {PARAM_GRP_NAME, &ArgsParser::ParseGroupName},
      70            0 :                                           {PARAM_SCHED_POLICY, &ArgsParser::ParseSchedPolicy},
      71            0 :                                           {PARAM_STARTER, &ArgsParser::ParseStarter},
      72            0 :                                           {PARAM_PROF_CFG_DATA, &ArgsParser::ParseProfCfgData},
      73            0 :                                           {PARAM_PROF_FLAG, &ArgsParser::ParseProfFlag},
      74            0 :                                           {PARAM_ABNORMAL_INTERVAL, &ArgsParser::ParseAbnormalInterval},
      75            0 :                                           {PARAM_RESOURCE_LIST, &ArgsParser::ParseResourceList},
      76          234 :                                           {PARAM_DEVICEIDS_LIST, &ArgsParser::ParseDeviceIdsList}}) {};
      77              : 
      78           78 :         ~ArgsParser() = default;
      79              : 
      80              :         bool ParseArgs(const int32_t argc, const char_t * const argv[]);
      81              : 
      82              :         bool ParseArgs(const std::vector<std::string> &args);
      83              : 
      84              :         std::string GetParaParsedStr();
      85              : 
      86           28 :         inline uint32_t GetDeviceId() const
      87              :         {
      88           28 :             return deviceId_;
      89              :         }
      90              : 
      91           27 :         inline uint32_t GetHostPid() const
      92              :         {
      93           27 :             return hostPid_;
      94              :         }
      95              : 
      96           27 :         inline std::string GetPidSign() const
      97              :         {
      98           27 :             return pidSign_;
      99              :         }
     100              : 
     101           27 :         inline uint32_t GetVfId() const
     102              :         {
     103           27 :             return vfId_;
     104              :         }
     105              : 
     106            4 :         inline int32_t GetLogLevel() const
     107              :         {
     108            4 :             return logLevel_;
     109              :         }
     110              : 
     111            4 :         inline int32_t GetEventLevel() const
     112              :         {
     113            4 :             return eventLevel_;
     114              :         }
     115              : 
     116              :         inline int32_t GetAicpuLogLevel() const
     117              :         {
     118              :             return aicpulogLevel_;
     119              :         }
     120              : 
     121           24 :         inline QueueSchedulerRunMode GetDeployMode() const
     122              :         {
     123           24 :             return deployMode_;
     124              :         }
     125              : 
     126           24 :         inline int32_t GetReschedInterval() const
     127              :         {
     128           24 :             return reschedInterval_;
     129              :         }
     130              : 
     131           27 :         inline std::string GetGroupName() const
     132              :         {
     133           27 :             return groupName_;
     134              :         }
     135              : 
     136           24 :         inline uint64_t GetSchedPolicy() const
     137              :         {
     138           24 :             return schedPolicy_;
     139              :         }
     140              : 
     141           36 :         inline QsStartType GetStarter() const
     142              :         {
     143           36 :             return starter_;
     144              :         }
     145              : 
     146           24 :         inline std::string GetProfCfgData() const
     147              :         {
     148           24 :             return profCfgData_;
     149              :         }
     150              : 
     151           24 :         inline bool GetProfFlag() const
     152              :         {
     153           24 :             return profFlag_;
     154              :         }
     155              : 
     156           24 :         inline int32_t GetAbnormalInterval() const
     157              :         {
     158           24 :             return abnormalInterval_;
     159              :         }
     160              : 
     161              :         inline bool GetWithDeviceId() const
     162              :         {
     163              :             return withDeviceId_;
     164              :         }
     165              : 
     166              :         inline bool GetWithHostPid() const
     167              :         {
     168              :             return withHostPid_;
     169              :         }
     170              : 
     171              :         inline bool GetWithPidSign() const
     172              :         {
     173              :             return withPidSign_;
     174              :         }
     175              : 
     176              :         inline bool GetWithVfId() const
     177              :         {
     178              :             return withVfId_;
     179              :         }
     180              : 
     181           20 :         inline bool GetWithLogLevel() const
     182              :         {
     183           20 :             return withLogLevel_;
     184              :         }
     185              : 
     186            4 :         inline bool GetWithGroupName() const
     187              :         {
     188            4 :             return withGroupName_;
     189              :         }
     190              : 
     191              :         inline bool GetWithStarter() const
     192              :         {
     193              :             return withStarter_;
     194              :         }
     195              : 
     196           20 :         inline std::vector<uint32_t> GetResvec() const
     197              :         {
     198           20 :             return resVec_;
     199              :         }
     200              : 
     201           20 :         inline std::vector<uint32_t> GetDevIdVec() const
     202              :         {
     203           20 :             return devIdVec_;
     204              :         }
     205              : 
     206              :         void SetLogLevel(const int32_t logLevel, const int32_t eventLevel) const;
     207              : 
     208              :     private:
     209              :         bool CheckRequiredParas() const;
     210              :         bool ParseSinglePara(const std::string &singlePara);
     211              :         bool ParseDeviceId(const std::string &para);
     212              :         bool ParseDeviceId(const std::string &para, int32_t &deviceId) const;
     213              :         bool ParseHostPid(const std::string &para);
     214              :         bool ParsePidSign(const std::string &para);
     215              :         bool ParseLogAndEventLevel(const std::string &para);
     216              :         bool ParseAicpuLogLevel(const std::string &para);
     217              :         bool ParseVfId(const std::string &para);
     218              :         bool ParseDeployMode(const std::string &para);
     219              :         bool ParseReschedInterval(const std::string &para);
     220              :         bool ParseGroupName(const std::string &para);
     221              :         bool ParseSchedPolicy(const std::string &para);
     222              :         bool ParseStarter(const std::string &para);
     223              :         bool ParseProfCfgData(const std::string &para);
     224              :         bool ParseProfFlag(const std::string &para);
     225              :         bool ParseAbnormalInterval(const std::string &para);
     226              :         bool ParseResourceList(const std::string &para);
     227              :         bool ParseDeviceIdsList(const std::string &para);
     228              :         void SetAicpuLogLevel() const;
     229              :       
     230              :         ArgsParser(ArgsParser const &) = delete;
     231              :         ArgsParser &operator=(ArgsParser const &) = delete;
     232              :         ArgsParser(ArgsParser &&) = delete;
     233              :         ArgsParser &operator=(ArgsParser &&) = delete;
     234              : 
     235              :         uint32_t deviceId_;
     236              :         uint32_t hostPid_;
     237              :         std::string pidSign_;
     238              :         uint32_t vfId_;
     239              :         int32_t logLevel_;
     240              :         int32_t eventLevel_;
     241              :         int32_t aicpulogLevel_;
     242              :         QueueSchedulerRunMode deployMode_;
     243              :         int32_t reschedInterval_;
     244              :         std::string groupName_;
     245              :         uint64_t schedPolicy_;
     246              :         QsStartType starter_;
     247              :         std::string  profCfgData_;
     248              :         int32_t abnormalInterval_;
     249              :         std::vector<uint32_t> resVec_;
     250              :         std::vector<uint32_t> devIdVec_;
     251              :         bool profFlag_;
     252              :         bool withDeviceId_;
     253              :         bool withHostPid_;
     254              :         bool withPidSign_;
     255              :         bool withVfId_;
     256              :         bool withLogLevel_;
     257              :         bool withGroupName_;
     258              :         bool withStarter_;
     259              :         using SingleParaParseFunc = bool (ArgsParser::*)(const std::string &);
     260              :         const std::unordered_map<std::string, SingleParaParseFunc> argsParseFuncMap_;
     261              :     };
     262              : } // namespace bqs
     263              : 
     264              : #endif // QS_ARGS_PARSER_H
        

Generated by: LCOV version 2.0-1