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 : }
44 :
45 : class ArgsParser {
46 : public:
47 180 : ArgsParser() : deviceId_(0U), hostPid_(0U), pidSign_(""), profilingMode_(0U), vfId_(0U),
48 90 : logLevel_(ERROR_LOG), eventLevel_(EVENT_LOG), ccecpulogLevel_(-1), aicpulogLevel_(-1),
49 90 : deviceMode_(0U), grpNameNum_(0U), aicpuProcNum_(0U),
50 540 : grpNameList_({}), hostProcName_({}), qsGrpNameList_({}), withDeviceId_(false), withHostPid_(false),
51 90 : withPidSign_(false), withGrpNameNum_(false), withGrpNameList_(false),
52 1440 : argsParseFuncMap_({{PARAM_DEVICEID, &ArgsParser::ParseDeviceId},
53 0 : {PARAM_HOST_PID, &ArgsParser::ParseHostPid},
54 0 : {PARAM_SIGN, &ArgsParser::ParseSign},
55 0 : {PARAM_PROFILING_MODE, &ArgsParser::ParseProfilingMode},
56 0 : {PARAM_LOGLEVEL, &ArgsParser::ParseLogAndEventLevel},
57 0 : {PARAM_CCECPULOGLEVEL, &ArgsParser::ParseCcecpuLogLevel},
58 0 : {PARAM_AICPULOGLEVEL, &ArgsParser::ParseAicpuLogLevel},
59 0 : {PARAM_VFID, &ArgsParser::ParseVfId},
60 0 : {PARAM_DEVICE_MODE, &ArgsParser::ParseDeviceMode},
61 0 : {PARAM_GRP_NAME_NUM, &ArgsParser::ParseGrpNameNum},
62 0 : {PARAM_GRP_NAME_LIST, &ArgsParser::ParseGrpNameList},
63 0 : {PARAM_HOST_PROC_NAME, &ArgsParser::ParseHostProcName},
64 0 : {PARAM_QSGRP_NAME_LIST, &ArgsParser::ParseQsGrpNameList},
65 90 : {PARAM_AICPU_PROC_NUM, &ArgsParser::ParseAicpuProcNum}})
66 180 : {};
67 :
68 90 : ~ArgsParser() = default;
69 :
70 : bool ParseArgs(const int32_t argc, const char_t * const argv[]);
71 :
72 : bool ParseArgs(const std::vector<std::string> &args);
73 :
74 : std::string GetParaParsedStr();
75 :
76 56 : inline uint32_t GetDeviceId() const
77 : {
78 56 : return deviceId_;
79 : }
80 :
81 55 : inline uint32_t GetHostPid() const
82 : {
83 55 : return hostPid_;
84 : }
85 :
86 32 : inline std::string GetPidSign() const
87 : {
88 32 : return pidSign_;
89 : }
90 :
91 32 : inline uint32_t GetProfilingMode() const
92 : {
93 32 : return profilingMode_;
94 : }
95 :
96 29 : inline uint32_t GetVfId() const
97 : {
98 29 : return vfId_;
99 : }
100 :
101 29 : inline int32_t GetLogLevel() const
102 : {
103 29 : return logLevel_;
104 : }
105 :
106 29 : inline int32_t GetEventLevel() const
107 : {
108 29 : return eventLevel_;
109 : }
110 :
111 26 : inline int32_t GetCcecpuLogLevel() const
112 : {
113 26 : return ccecpulogLevel_;
114 : }
115 :
116 26 : inline int32_t GetAicpuLogLevel() const
117 : {
118 26 : return aicpulogLevel_;
119 : }
120 :
121 1 : inline uint32_t GetDeviceMode() const
122 : {
123 1 : return deviceMode_;
124 : }
125 :
126 30 : inline uint32_t GetGrpNameNum() const
127 : {
128 30 : return grpNameNum_;
129 : }
130 :
131 27 : inline uint32_t GetAicpuProcNum() const
132 : {
133 27 : return aicpuProcNum_;
134 : }
135 :
136 30 : inline std::vector<std::string> GetGrpNameList() const
137 : {
138 30 : return grpNameList_;
139 : }
140 :
141 28 : inline std::string GetHostProcName() const
142 : {
143 28 : return hostProcName_;
144 : }
145 :
146 8 : inline std::vector<std::string> GetQsGrpNameList() const
147 : {
148 8 : return qsGrpNameList_;
149 : }
150 :
151 : private:
152 : bool CheckRequiredParas() const;
153 : bool ParseSinglePara(const std::string &singlePara);
154 : bool ParseDeviceId(const std::string ¶);
155 : bool ParseHostPid(const std::string ¶);
156 : bool ParseSign(const std::string ¶);
157 : bool ParseProfilingMode(const std::string ¶);
158 : bool ParseLogAndEventLevel(const std::string ¶);
159 : bool ParseCcecpuLogLevel(const std::string ¶);
160 : bool ParseAicpuLogLevel(const std::string ¶);
161 : bool ParseVfId(const std::string ¶);
162 : bool ParseDeviceMode(const std::string ¶);
163 : bool ParseGrpNameNum(const std::string ¶);
164 : bool ParseGrpNameList(const std::string ¶);
165 : bool ParseHostProcName(const std::string ¶);
166 : bool ParseQsGrpNameList(const std::string ¶);
167 : bool ParseAicpuProcNum(const std::string ¶);
168 : static void SplitGrpNameList(const std::string &grpNamePara, std::vector<std::string> &grpNameList);
169 :
170 : ArgsParser(ArgsParser const &) = delete;
171 : ArgsParser &operator=(ArgsParser const &) = delete;
172 : ArgsParser(ArgsParser &&) = delete;
173 : ArgsParser &operator=(ArgsParser &&) = delete;
174 :
175 : uint32_t deviceId_;
176 : uint32_t hostPid_;
177 : std::string pidSign_;
178 : uint32_t profilingMode_;
179 : uint32_t vfId_;
180 : int32_t logLevel_;
181 : int32_t eventLevel_;
182 : int32_t ccecpulogLevel_;
183 : int32_t aicpulogLevel_;
184 : uint32_t deviceMode_;
185 : uint32_t grpNameNum_;
186 : uint32_t aicpuProcNum_;
187 : std::vector<std::string> grpNameList_;
188 : std::string hostProcName_;
189 : std::vector<std::string> qsGrpNameList_;
190 : bool withDeviceId_;
191 : bool withHostPid_;
192 : bool withPidSign_;
193 : bool withGrpNameNum_;
194 : bool withGrpNameList_;
195 : using SingleParaParseFunc = bool (ArgsParser::*)(const std::string &);
196 : const std::unordered_map<std::string, SingleParaParseFunc> argsParseFuncMap_;
197 : };
198 : } // namespace AicpuSchedule
199 :
200 : #endif // CORE_AICPUSD_ARGS_PARSER_H
|