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 :
20 : namespace AicpuSchedule {
21 : namespace {
22 : const std::string PARAM_DEVICEID = "--deviceId=";
23 : const std::string PARAM_HOST_PID = "--pid=";
24 : const std::string PARAM_SIGN = "--pidSign=";
25 : const std::string PARAM_PROFILING_MODE = "--profilingMode=";
26 : const std::string PARAM_LOGLEVEL = "--logLevelInPid=";
27 : const std::string PARAM_CCECPULOGLEVEL = "--ccecpuLogLevel=";
28 : const std::string PARAM_AICPULOGLEVEL = "--aicpuLogLevel=";
29 : const std::string PARAM_VFID = "--vfId=";
30 : const std::string PARAM_DEVICE_MODE = "--deviceMode=";
31 : const std::string PARAM_GRP_NAME_NUM = "--groupNameNum=";
32 : const std::string PARAM_GRP_NAME_LIST = "--groupNameList=";
33 : const std::string PARAM_HOST_PROC_NAME = "--hostProcName=";
34 : const std::string PARAM_QSGRP_NAME_LIST = "--qsInitGroupName=";
35 : const std::string PARAM_AICPU_PROC_NUM = "--aicpuProcNum=";
36 : constexpr int32_t ERROR_LOG = 3;
37 : constexpr int32_t EVENT_LOG = 1;
38 : constexpr int32_t DEBUG_LOG = 0;
39 : constexpr int32_t VF_ID_MAX = 16;
40 : constexpr int32_t DEVICE_MODE_MAX = 1;
41 : constexpr int32_t AICPUFW_CHIP_NUM_MAX = 64;
42 : constexpr int32_t VALUE_FOR_CALCULATE_LOG_LEVEL = 100;
43 : } // namespace
44 :
45 : class ArgsParser {
46 : public:
47 90 : ArgsParser()
48 90 : : deviceId_(0U),
49 90 : hostPid_(0U),
50 180 : pidSign_(""),
51 90 : profilingMode_(0U),
52 90 : vfId_(0U),
53 90 : logLevel_(ERROR_LOG),
54 90 : eventLevel_(EVENT_LOG),
55 90 : ccecpulogLevel_(-1),
56 90 : aicpulogLevel_(-1),
57 90 : deviceMode_(0U),
58 90 : grpNameNum_(0U),
59 90 : aicpuProcNum_(0U),
60 180 : grpNameList_({}),
61 180 : hostProcName_({}),
62 180 : qsGrpNameList_({}),
63 90 : withDeviceId_(false),
64 90 : withHostPid_(false),
65 90 : withPidSign_(false),
66 90 : withGrpNameNum_(false),
67 90 : withGrpNameList_(false),
68 1440 : argsParseFuncMap_(
69 0 : {{PARAM_DEVICEID, &ArgsParser::ParseDeviceId},
70 0 : {PARAM_HOST_PID, &ArgsParser::ParseHostPid},
71 0 : {PARAM_SIGN, &ArgsParser::ParseSign},
72 0 : {PARAM_PROFILING_MODE, &ArgsParser::ParseProfilingMode},
73 0 : {PARAM_LOGLEVEL, &ArgsParser::ParseLogAndEventLevel},
74 0 : {PARAM_CCECPULOGLEVEL, &ArgsParser::ParseCcecpuLogLevel},
75 0 : {PARAM_AICPULOGLEVEL, &ArgsParser::ParseAicpuLogLevel},
76 0 : {PARAM_VFID, &ArgsParser::ParseVfId},
77 0 : {PARAM_DEVICE_MODE, &ArgsParser::ParseDeviceMode},
78 0 : {PARAM_GRP_NAME_NUM, &ArgsParser::ParseGrpNameNum},
79 0 : {PARAM_GRP_NAME_LIST, &ArgsParser::ParseGrpNameList},
80 0 : {PARAM_HOST_PROC_NAME, &ArgsParser::ParseHostProcName},
81 0 : {PARAM_QSGRP_NAME_LIST, &ArgsParser::ParseQsGrpNameList},
82 180 : {PARAM_AICPU_PROC_NUM, &ArgsParser::ParseAicpuProcNum}}){};
83 :
84 90 : ~ArgsParser() = default;
85 :
86 : bool ParseArgs(const int32_t argc, const char_t* const argv[]);
87 :
88 : bool ParseArgs(const std::vector<std::string>& args);
89 :
90 : std::string GetParaParsedStr();
91 :
92 56 : inline uint32_t GetDeviceId() const { return deviceId_; }
93 :
94 55 : inline uint32_t GetHostPid() const { return hostPid_; }
95 :
96 32 : inline std::string GetPidSign() const { return pidSign_; }
97 :
98 32 : inline uint32_t GetProfilingMode() const { return profilingMode_; }
99 :
100 29 : inline uint32_t GetVfId() const { return vfId_; }
101 :
102 29 : inline int32_t GetLogLevel() const { return logLevel_; }
103 :
104 29 : inline int32_t GetEventLevel() const { return eventLevel_; }
105 :
106 26 : inline int32_t GetCcecpuLogLevel() const { return ccecpulogLevel_; }
107 :
108 26 : inline int32_t GetAicpuLogLevel() const { return aicpulogLevel_; }
109 :
110 1 : inline uint32_t GetDeviceMode() const { return deviceMode_; }
111 :
112 30 : inline uint32_t GetGrpNameNum() const { return grpNameNum_; }
113 :
114 27 : inline uint32_t GetAicpuProcNum() const { return aicpuProcNum_; }
115 :
116 30 : inline std::vector<std::string> GetGrpNameList() const { return grpNameList_; }
117 :
118 28 : inline std::string GetHostProcName() const { return hostProcName_; }
119 :
120 8 : inline std::vector<std::string> GetQsGrpNameList() const { return qsGrpNameList_; }
121 :
122 : private:
123 : bool CheckRequiredParas() const;
124 : bool ParseSinglePara(const std::string& singlePara);
125 : bool ParseDeviceId(const std::string& para);
126 : bool ParseHostPid(const std::string& para);
127 : bool ParseSign(const std::string& para);
128 : bool ParseProfilingMode(const std::string& para);
129 : bool ParseLogAndEventLevel(const std::string& para);
130 : bool ParseCcecpuLogLevel(const std::string& para);
131 : bool ParseAicpuLogLevel(const std::string& para);
132 : bool ParseVfId(const std::string& para);
133 : bool ParseDeviceMode(const std::string& para);
134 : bool ParseGrpNameNum(const std::string& para);
135 : bool ParseGrpNameList(const std::string& para);
136 : bool ParseHostProcName(const std::string& para);
137 : bool ParseQsGrpNameList(const std::string& para);
138 : bool ParseAicpuProcNum(const std::string& para);
139 : static void SplitGrpNameList(const std::string& grpNamePara, std::vector<std::string>& grpNameList);
140 :
141 : ArgsParser(ArgsParser const&) = delete;
142 : ArgsParser& operator=(ArgsParser const&) = delete;
143 : ArgsParser(ArgsParser&&) = delete;
144 : ArgsParser& operator=(ArgsParser&&) = delete;
145 :
146 : uint32_t deviceId_;
147 : uint32_t hostPid_;
148 : std::string pidSign_;
149 : uint32_t profilingMode_;
150 : uint32_t vfId_;
151 : int32_t logLevel_;
152 : int32_t eventLevel_;
153 : int32_t ccecpulogLevel_;
154 : int32_t aicpulogLevel_;
155 : uint32_t deviceMode_;
156 : uint32_t grpNameNum_;
157 : uint32_t aicpuProcNum_;
158 : std::vector<std::string> grpNameList_;
159 : std::string hostProcName_;
160 : std::vector<std::string> qsGrpNameList_;
161 : bool withDeviceId_;
162 : bool withHostPid_;
163 : bool withPidSign_;
164 : bool withGrpNameNum_;
165 : bool withGrpNameList_;
166 : using SingleParaParseFunc = bool (ArgsParser::*)(const std::string&);
167 : const std::unordered_map<std::string, SingleParaParseFunc> argsParseFuncMap_;
168 : };
169 : } // namespace AicpuSchedule
170 :
171 : #endif // CORE_AICPUSD_ARGS_PARSER_H
|