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: 77.6 % 58 45
Test Date: 2026-08-12 11:05:02 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              : } // namespace
      45              : 
      46              : class ArgsParser {
      47              : public:
      48           77 :     ArgsParser()
      49           77 :         : deviceId_(0U),
      50           77 :           hostPid_(0U),
      51          154 :           pidSign_(""),
      52           77 :           profilingMode_(PROFILING_CLOSE),
      53           77 :           vfId_(0U),
      54           77 :           logLevel_(ERROR_LOG),
      55           77 :           eventLevel_(EVENT_LOG),
      56           77 :           ccecpulogLevel_(-1),
      57           77 :           aicpulogLevel_(-1),
      58          154 :           custSoPath_(""),
      59           77 :           aicpuPid_(0U),
      60           77 :           grpNameNum_(0U),
      61          154 :           grpNameList_({}),
      62          154 :           controlCpuList_({}),
      63           77 :           tsdPid_(0U),
      64           77 :           withDeviceId_(false),
      65           77 :           withHostPid_(false),
      66           77 :           withPidSign_(false),
      67           77 :           withCustSoPath_(false),
      68           77 :           withAicpuPid_(false),
      69           77 :           withGrpNameNum_(false),
      70           77 :           withGrpNameList_(false),
      71           77 :           withControlCpuList_(false),
      72           77 :           withTsdPid_(false),
      73         1232 :           argsParseFuncMap_(
      74            0 :               {{PARAM_DEVICEID, &ArgsParser::ParseDeviceId},
      75            0 :                {PARAM_HOST_PID, &ArgsParser::ParseHostPid},
      76            0 :                {PARAM_SIGN, &ArgsParser::ParseSign},
      77            0 :                {PARAM_PROFILING_MODE, &ArgsParser::ParseProfilingMode},
      78            0 :                {PARAM_LOGLEVEL, &ArgsParser::ParseLogAndEventLevel},
      79            0 :                {PARAM_CCECPULOGLEVEL, &ArgsParser::ParseCcecpuLogLevel},
      80            0 :                {PARAM_AICPULOGLEVEL, &ArgsParser::ParseAicpuLogLevel},
      81            0 :                {PARAM_VFID, &ArgsParser::ParseVfId},
      82            0 :                {PARAM_CUSTSOPATH, &ArgsParser::ParseCustSoPath},
      83            0 :                {PARAM_AICPUPID, &ArgsParser::ParseAicpuPid},
      84            0 :                {PARAM_GRP_NAME_NUM, &ArgsParser::ParseGrpNameNum},
      85            0 :                {PARAM_GRP_NAME_LIST, &ArgsParser::ParseGrpNameList},
      86            0 :                {PARAM_CRL_CPU_LIST, &ArgsParser::ParseCtrolCpuList},
      87          154 :                {PARAM_TSD_PID, &ArgsParser::ParseTsdPid}}){};
      88              : 
      89           77 :     ~ArgsParser() = default;
      90              : 
      91              :     bool ParseArgs(const int32_t argc, const char_t* const argv[]);
      92              : 
      93              :     std::string GetParaParsedStr();
      94              : 
      95           49 :     inline uint32_t GetDeviceId() const { return deviceId_; }
      96              : 
      97           48 :     inline uint32_t GetHostPid() const { return hostPid_; }
      98              : 
      99           25 :     inline std::string GetPidSign() const { return pidSign_; }
     100              : 
     101           26 :     inline uint32_t GetProfilingMode() const { return profilingMode_; }
     102              : 
     103           26 :     inline uint32_t GetVfId() const { return vfId_; }
     104              : 
     105           26 :     inline int32_t GetLogLevel() const { return logLevel_; }
     106              : 
     107           26 :     inline int32_t GetEventLevel() const { return eventLevel_; }
     108              : 
     109           22 :     inline int32_t GetCcecpuLogLevel() const { return ccecpulogLevel_; }
     110              : 
     111           22 :     inline int32_t GetAicpuLogLevel() const { return aicpulogLevel_; }
     112              : 
     113           24 :     inline std::string GetCustSoPath() const { return custSoPath_; }
     114              : 
     115           26 :     inline uint32_t GetAicpuPid() const { return aicpuPid_; }
     116              : 
     117           50 :     inline uint32_t GetGrpNameNum() const { return grpNameNum_; }
     118              : 
     119           20 :     inline std::vector<std::string> GetGrpNameList() const { return grpNameList_; }
     120              : 
     121           10 :     inline std::vector<uint32_t> GetControlCpuList() const { return controlCpuList_; }
     122           23 :     inline bool HasControlCpuList() const { return withControlCpuList_; }
     123           66 :     inline bool HasTsdPid() const { return withTsdPid_; }
     124           26 :     inline uint32_t GetTsdPid() const { return tsdPid_; }
     125              : 
     126              : private:
     127              :     bool CheckRequiredParas() const;
     128              :     bool ParseSinglePara(const std::string& singlePara);
     129              :     bool ParseDeviceId(const std::string& para);
     130              :     bool ParseHostPid(const std::string& para);
     131              :     bool ParseSign(const std::string& para);
     132              :     bool ParseProfilingMode(const std::string& para);
     133              :     bool ParseLogAndEventLevel(const std::string& para);
     134              :     bool ParseCcecpuLogLevel(const std::string& para);
     135              :     bool ParseAicpuLogLevel(const std::string& para);
     136              :     bool ParseVfId(const std::string& para);
     137              :     bool ParseCustSoPath(const std::string& para);
     138              :     bool ParseAicpuPid(const std::string& para);
     139              :     bool ParseGrpNameNum(const std::string& para);
     140              :     bool ParseGrpNameList(const std::string& para);
     141              :     bool ParseCtrolCpuList(const std::string& para);
     142              :     static void SplitControlCpuList(const std::string& cupListPara, std::vector<uint32_t>& controlCpuList);
     143              :     static void SplitGrpNameList(const std::string& grpNamePara, std::vector<std::string>& grpNameList);
     144              :     bool ParseTsdPid(const std::string& para);
     145              :     ArgsParser(ArgsParser const&) = delete;
     146              :     ArgsParser& operator=(ArgsParser const&) = delete;
     147              :     ArgsParser(ArgsParser&&) = delete;
     148              :     ArgsParser& operator=(ArgsParser&&) = delete;
     149              : 
     150              :     uint32_t deviceId_;
     151              :     uint32_t hostPid_;
     152              :     std::string pidSign_;
     153              :     uint32_t profilingMode_;
     154              :     uint32_t vfId_;
     155              :     int32_t logLevel_;
     156              :     int32_t eventLevel_;
     157              :     int32_t ccecpulogLevel_;
     158              :     int32_t aicpulogLevel_;
     159              :     std::string custSoPath_;
     160              :     uint32_t aicpuPid_;
     161              :     uint32_t grpNameNum_;
     162              :     std::vector<std::string> grpNameList_;
     163              :     std::vector<uint32_t> controlCpuList_;
     164              :     uint32_t tsdPid_;
     165              :     bool withDeviceId_;
     166              :     bool withHostPid_;
     167              :     bool withPidSign_;
     168              :     bool withCustSoPath_;
     169              :     bool withAicpuPid_;
     170              :     bool withGrpNameNum_;
     171              :     bool withGrpNameList_;
     172              :     bool withControlCpuList_;
     173              :     bool withTsdPid_;
     174              :     using SingleParaParseFunc = bool (ArgsParser::*)(const std::string&);
     175              :     const std::unordered_map<std::string, SingleParaParseFunc> argsParseFuncMap_;
     176              : };
     177              : } // namespace AicpuSchedule
     178              : 
     179              : #endif // CORE_AICPUSD_ARGS_PARSER_H
        

Generated by: LCOV version 2.0-1