LCOV - code coverage report
Current view: top level - server - qs_args_parser.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 75.9 % 58 44
Test Date: 2026-08-12 11:05:07 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              : } // namespace
      52              : 
      53              : class ArgsParser {
      54              : public:
      55           79 :     ArgsParser()
      56           79 :         : deviceId_(0U),
      57           79 :           hostPid_(0U),
      58          158 :           pidSign_(""),
      59           79 :           vfId_(0U),
      60           79 :           logLevel_(ERROR_LOG),
      61           79 :           eventLevel_(EVENT_LOG),
      62           79 :           aicpulogLevel_(-1),
      63           79 :           deployMode_(QueueSchedulerRunMode::SINGLE_PROCESS),
      64           79 :           reschedInterval_(RESCHED_INTERVAL_DEFAULT),
      65          158 :           groupName_(""),
      66           79 :           schedPolicy_(0U),
      67           79 :           starter_(QsStartType::START_BY_TSD),
      68          158 :           profCfgData_(""),
      69           79 :           abnormalInterval_(ABNORMAL_INTERVAL_DEFAULT),
      70           79 :           profFlag_(false),
      71           79 :           withDeviceId_(false),
      72           79 :           withHostPid_(false),
      73           79 :           withPidSign_(false),
      74           79 :           withVfId_(false),
      75           79 :           withLogLevel_(false),
      76           79 :           withGroupName_(false),
      77           79 :           withStarter_(false),
      78         1422 :           argsParseFuncMap_(
      79              :               {{PARAM_DEVICEID, &ArgsParser::ParseDeviceId},
      80            0 :                {PARAM_HOST_PID, &ArgsParser::ParseHostPid},
      81            0 :                {PARAM_PIDSIGN, &ArgsParser::ParsePidSign},
      82            0 :                {PARAM_VFID, &ArgsParser::ParseVfId},
      83            0 :                {PARAM_LOGLEVEL, &ArgsParser::ParseLogAndEventLevel},
      84            0 :                {PARAM_AICPULOGLEVEL, &ArgsParser::ParseAicpuLogLevel},
      85            0 :                {PARAM_DEPLOY_MODE, &ArgsParser::ParseDeployMode},
      86            0 :                {PARAM_RESCHED_INTERVAL, &ArgsParser::ParseReschedInterval},
      87            0 :                {PARAM_GRP_NAME, &ArgsParser::ParseGroupName},
      88            0 :                {PARAM_SCHED_POLICY, &ArgsParser::ParseSchedPolicy},
      89            0 :                {PARAM_STARTER, &ArgsParser::ParseStarter},
      90            0 :                {PARAM_PROF_CFG_DATA, &ArgsParser::ParseProfCfgData},
      91            0 :                {PARAM_PROF_FLAG, &ArgsParser::ParseProfFlag},
      92            0 :                {PARAM_ABNORMAL_INTERVAL, &ArgsParser::ParseAbnormalInterval},
      93            0 :                {PARAM_RESOURCE_LIST, &ArgsParser::ParseResourceList},
      94          237 :                {PARAM_DEVICEIDS_LIST, &ArgsParser::ParseDeviceIdsList}}){};
      95              : 
      96           79 :     ~ArgsParser() = default;
      97              : 
      98              :     bool ParseArgs(const int32_t argc, const char_t* const argv[]);
      99              : 
     100              :     bool ParseArgs(const std::vector<std::string>& args);
     101              : 
     102              :     std::string GetParaParsedStr();
     103              : 
     104           29 :     inline uint32_t GetDeviceId() const { return deviceId_; }
     105              : 
     106           27 :     inline uint32_t GetHostPid() const { return hostPid_; }
     107              : 
     108           27 :     inline std::string GetPidSign() const { return pidSign_; }
     109              : 
     110           27 :     inline uint32_t GetVfId() const { return vfId_; }
     111              : 
     112            4 :     inline int32_t GetLogLevel() const { return logLevel_; }
     113              : 
     114            4 :     inline int32_t GetEventLevel() const { return eventLevel_; }
     115              : 
     116              :     inline int32_t GetAicpuLogLevel() const { return aicpulogLevel_; }
     117              : 
     118           24 :     inline QueueSchedulerRunMode GetDeployMode() const { return deployMode_; }
     119              : 
     120           24 :     inline int32_t GetReschedInterval() const { return reschedInterval_; }
     121              : 
     122           27 :     inline std::string GetGroupName() const { return groupName_; }
     123              : 
     124           24 :     inline uint64_t GetSchedPolicy() const { return schedPolicy_; }
     125              : 
     126           36 :     inline QsStartType GetStarter() const { return starter_; }
     127              : 
     128           24 :     inline std::string GetProfCfgData() const { return profCfgData_; }
     129              : 
     130           24 :     inline bool GetProfFlag() const { return profFlag_; }
     131              : 
     132           24 :     inline int32_t GetAbnormalInterval() const { return abnormalInterval_; }
     133              : 
     134              :     inline bool GetWithDeviceId() const { return withDeviceId_; }
     135              : 
     136              :     inline bool GetWithHostPid() const { return withHostPid_; }
     137              : 
     138              :     inline bool GetWithPidSign() const { return withPidSign_; }
     139              : 
     140              :     inline bool GetWithVfId() const { return withVfId_; }
     141              : 
     142           20 :     inline bool GetWithLogLevel() const { return withLogLevel_; }
     143              : 
     144            4 :     inline bool GetWithGroupName() const { return withGroupName_; }
     145              : 
     146              :     inline bool GetWithStarter() const { return withStarter_; }
     147              : 
     148           20 :     inline std::vector<uint32_t> GetResvec() const { return resVec_; }
     149              : 
     150           20 :     inline std::vector<uint32_t> GetDevIdVec() const { return devIdVec_; }
     151              : 
     152              :     void SetLogLevel(const int32_t logLevel, const int32_t eventLevel) const;
     153              : 
     154              : private:
     155              :     bool CheckRequiredParas() const;
     156              :     bool ParseSinglePara(const std::string& singlePara);
     157              :     bool ParseDeviceId(const std::string& para);
     158              :     bool ParseDeviceId(const std::string& para, int32_t& deviceId) const;
     159              :     bool ParseHostPid(const std::string& para);
     160              :     bool ParsePidSign(const std::string& para);
     161              :     bool ParseLogAndEventLevel(const std::string& para);
     162              :     bool ParseAicpuLogLevel(const std::string& para);
     163              :     bool ParseVfId(const std::string& para);
     164              :     bool ParseDeployMode(const std::string& para);
     165              :     bool ParseReschedInterval(const std::string& para);
     166              :     bool ParseGroupName(const std::string& para);
     167              :     bool ParseSchedPolicy(const std::string& para);
     168              :     bool ParseStarter(const std::string& para);
     169              :     bool ParseProfCfgData(const std::string& para);
     170              :     bool ParseProfFlag(const std::string& para);
     171              :     bool ParseAbnormalInterval(const std::string& para);
     172              :     bool ParseResourceList(const std::string& para);
     173              :     bool ParseDeviceIdsList(const std::string& para);
     174              :     void SetAicpuLogLevel() const;
     175              : 
     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 vfId_;
     185              :     int32_t logLevel_;
     186              :     int32_t eventLevel_;
     187              :     int32_t aicpulogLevel_;
     188              :     QueueSchedulerRunMode deployMode_;
     189              :     int32_t reschedInterval_;
     190              :     std::string groupName_;
     191              :     uint64_t schedPolicy_;
     192              :     QsStartType starter_;
     193              :     std::string profCfgData_;
     194              :     int32_t abnormalInterval_;
     195              :     std::vector<uint32_t> resVec_;
     196              :     std::vector<uint32_t> devIdVec_;
     197              :     bool profFlag_;
     198              :     bool withDeviceId_;
     199              :     bool withHostPid_;
     200              :     bool withPidSign_;
     201              :     bool withVfId_;
     202              :     bool withLogLevel_;
     203              :     bool withGroupName_;
     204              :     bool withStarter_;
     205              :     using SingleParaParseFunc = bool (ArgsParser::*)(const std::string&);
     206              :     const std::unordered_map<std::string, SingleParaParseFunc> argsParseFuncMap_;
     207              : };
     208              : } // namespace bqs
     209              : 
     210              : #endif // QS_ARGS_PARSER_H
        

Generated by: LCOV version 2.0-1