Apollo 10.0
自动驾驶开放平台
apollo::cyber::mainboard::ModuleArgument类 参考

#include <module_argument.h>

apollo::cyber::mainboard::ModuleArgument 的协作图:

Public 成员函数

 ModuleArgument ()=default
 
virtual ~ModuleArgument ()=default
 
void DisplayUsage ()
 
void ParseArgument (int argc, char *const argv[])
 
void GetOptions (const int argc, char *const argv[])
 
const std::string & GetBinaryName () const
 
const std::string & GetProcessGroup () const
 
const std::string & GetSchedName () const
 
const std::list< std::string > & GetDAGConfList () const
 
const std::list< std::string > & GetPluginDescriptionList () const
 
const bool GetEnableCpuprofile () const
 
const std::string GetProfileFilename () const
 
const bool GetEnableHeapprofile () const
 
const std::string GetHeapProfileFilename () const
 
const bool & GetDisablePluginsAutoLoad () const
 

详细描述

在文件 module_argument.h38 行定义.

构造及析构函数说明

◆ ModuleArgument()

apollo::cyber::mainboard::ModuleArgument::ModuleArgument ( )
default

◆ ~ModuleArgument()

virtual apollo::cyber::mainboard::ModuleArgument::~ModuleArgument ( )
virtualdefault

成员函数说明

◆ DisplayUsage()

void apollo::cyber::mainboard::ModuleArgument::DisplayUsage ( )

在文件 module_argument.cc34 行定义.

34 {
35 AINFO << "Usage: \n " << binary_name_ << " [OPTION]...\n"
36 << "Description: \n"
37 << " -h, --help: help information \n"
38 << " -d, --dag_conf=CONFIG_FILE: module dag config file\n"
39 << " -p, --process_group=process_group: the process "
40 "namespace for running this module, default in manager process\n"
41 << " -s, --sched_name=sched_name: sched policy "
42 "conf for hole process, sched_name should be conf in cyber.pb.conf\n"
43 << " --plugin=plugin_description_file_path: the description file of "
44 "plugin\n"
45 << " --disable_plugin_autoload : default enable autoload "
46 "mode of plugins, use disable_plugin_autoload to ingore autoload\n"
47 << " -c, --cpuprofile: enable gperftools cpu profile\n"
48 << " -o, --profile_filename=filename: the filename to dump the "
49 "profile to, default value is ${process_group}_cpu.prof. Only work "
50 "with -c option\n"
51 << " -H, --heapprofile: enable gperftools heap profile\n"
52 << " -O, --heapprofile_filename=filename: the filename to dump the "
53 "profile to, default value is ${process_group}_mem.prof. Only work "
54 "with -c option\n"
55 << "Example:\n"
56 << " " << binary_name_ << " -h\n"
57 << " " << binary_name_ << " -d dag_conf_file1 -d dag_conf_file2 "
58 << "-p process_group -s sched_name\n"
59 << " " << binary_name_ << " --plugin plugin_xml_conf -d dag_conf ";
60}
#define AINFO
Definition log.h:42

◆ GetBinaryName()

const std::string & apollo::cyber::mainboard::ModuleArgument::GetBinaryName ( ) const
inline

在文件 module_argument.h71 行定义.

71 {
72 return binary_name_;
73}

◆ GetDAGConfList()

const std::list< std::string > & apollo::cyber::mainboard::ModuleArgument::GetDAGConfList ( ) const
inline

在文件 module_argument.h83 行定义.

83 {
84 return dag_conf_list_;
85}

◆ GetDisablePluginsAutoLoad()

const bool & apollo::cyber::mainboard::ModuleArgument::GetDisablePluginsAutoLoad ( ) const
inline

在文件 module_argument.h92 行定义.

92 {
93 return disable_plugin_autoload_;
94}

◆ GetEnableCpuprofile()

const bool apollo::cyber::mainboard::ModuleArgument::GetEnableCpuprofile ( ) const
inline

在文件 module_argument.h50 行定义.

50{ return enable_cpuprofile_; }

◆ GetEnableHeapprofile()

const bool apollo::cyber::mainboard::ModuleArgument::GetEnableHeapprofile ( ) const
inline

在文件 module_argument.h52 行定义.

52{ return enable_heapprofile_; }

◆ GetHeapProfileFilename()

const std::string apollo::cyber::mainboard::ModuleArgument::GetHeapProfileFilename ( ) const
inline

在文件 module_argument.h53 行定义.

53 {
54 return heapprofile_filename_;
55 }

◆ GetOptions()

void apollo::cyber::mainboard::ModuleArgument::GetOptions ( const int  argc,
char *const  argv[] 
)

在文件 module_argument.cc104 行定义.

104 {
105 opterr = 0; // extern int opterr
106 int long_index = 0;
107 const std::string short_opts = "hd:p:s:co:HO:";
108 static const struct option long_opts[] = {
109 {"help", no_argument, nullptr, 'h'},
110 {"dag_conf", required_argument, nullptr, 'd'},
111 {"process_name", required_argument, nullptr, 'p'},
112 {"sched_name", required_argument, nullptr, 's'},
113 {"plugin", required_argument, nullptr, ARGS_OPT_CODE_PLUGIN},
114 {"disable_plugin_autoload", no_argument, nullptr,
115 ARGS_OPT_CODE_DISABLE_PLUGIN_AUTOLOAD},
116 {"cpuprofile", no_argument, nullptr, 'c'},
117 {"profile_filename", required_argument, nullptr, 'o'},
118 {"heapprofile", no_argument, nullptr, 'H'},
119 {"heapprofile_filename", required_argument, nullptr, 'O'},
120 {NULL, no_argument, nullptr, 0}};
121
122 // log command for info
123 std::string cmd("");
124 for (int i = 0; i < argc; ++i) {
125 cmd += argv[i];
126 cmd += " ";
127 }
128 AINFO << "command: " << cmd;
129
130 if (1 == argc) {
131 DisplayUsage();
132 exit(0);
133 }
134
135 do {
136 int opt =
137 getopt_long(argc, argv, short_opts.c_str(), long_opts, &long_index);
138 if (opt == -1) {
139 break;
140 }
141 switch (opt) {
142 case 'd':
143 dag_conf_list_.emplace_back(std::string(optarg));
144 for (int i = optind; i < argc; i++) {
145 if (*argv[i] != '-') {
146 dag_conf_list_.emplace_back(std::string(argv[i]));
147 } else {
148 break;
149 }
150 }
151 break;
152 case 'p':
153 process_group_ = std::string(optarg);
154 break;
155 case 's':
156 sched_name_ = std::string(optarg);
157 break;
158 case ARGS_OPT_CODE_PLUGIN:
159 plugin_description_list_.emplace_back(std::string(optarg));
160 break;
161 case ARGS_OPT_CODE_DISABLE_PLUGIN_AUTOLOAD:
162 disable_plugin_autoload_ = true;
163 break;
164 case 'c':
165#ifndef BASE_PROFILER_H_
166 AWARN << "gperftools not installed, ignore perf parameters";
167#endif
168 enable_cpuprofile_ = true;
169 break;
170 case 'o':
171 profile_filename_ = std::string(optarg);
172 break;
173 case 'H':
174#ifndef BASE_PROFILER_H_
175 AWARN << "gperftools not installed, ignore perf parameters";
176#endif
177 enable_heapprofile_ = true;
178 break;
179 case 'O':
180 heapprofile_filename_ = std::string(optarg);
181 break;
182 case 'h':
183 DisplayUsage();
184 exit(0);
185 default:
186 break;
187 }
188 } while (true);
189
190 if (optind < argc) {
191 AINFO << "Found non-option ARGV-element \"" << argv[optind++] << "\"";
192 DisplayUsage();
193 exit(1);
194 }
195
196 if (dag_conf_list_.empty()) {
197 AINFO << "-d parameter must be specified";
198 DisplayUsage();
199 exit(1);
200 }
201}
#define AWARN
Definition log.h:43

◆ GetPluginDescriptionList()

const std::list< std::string > & apollo::cyber::mainboard::ModuleArgument::GetPluginDescriptionList ( ) const
inline

在文件 module_argument.h87 行定义.

88 {
89 return plugin_description_list_;
90}

◆ GetProcessGroup()

const std::string & apollo::cyber::mainboard::ModuleArgument::GetProcessGroup ( ) const
inline

在文件 module_argument.h75 行定义.

75 {
76 return process_group_;
77}

◆ GetProfileFilename()

const std::string apollo::cyber::mainboard::ModuleArgument::GetProfileFilename ( ) const
inline

在文件 module_argument.h51 行定义.

51{ return profile_filename_; }

◆ GetSchedName()

const std::string & apollo::cyber::mainboard::ModuleArgument::GetSchedName ( ) const
inline

在文件 module_argument.h79 行定义.

79 {
80 return sched_name_;
81}

◆ ParseArgument()

void apollo::cyber::mainboard::ModuleArgument::ParseArgument ( int  argc,
char *const  argv[] 
)

在文件 module_argument.cc62 行定义.

62 {
63 binary_name_ = std::string(basename(argv[0]));
64 GetOptions(argc, argv);
65
66 if (process_group_.empty()) {
67 process_group_ = DEFAULT_process_group_;
68 }
69
70 if (sched_name_.empty()) {
71 sched_name_ = DEFAULT_sched_name_;
72 }
73
74 if (enable_cpuprofile_ && profile_filename_.empty()) {
75 auto pwd = common::GetEnv("PWD");
76 profile_filename_ = pwd + "/" + process_group_ + std::string("_cpu.prof");
77 }
78
79 if (profile_filename_[0] != '/') {
80 auto pwd = common::GetEnv("PWD");
81 profile_filename_ = pwd + "/" + profile_filename_;
82 }
83
84 if (enable_heapprofile_ && heapprofile_filename_.empty()) {
85 auto pwd = common::GetEnv("PWD");
86 heapprofile_filename_ =
87 pwd + "/" + process_group_ + std::string("_mem.prof");
88 }
89
90 if (heapprofile_filename_[0] != '/') {
91 auto pwd = common::GetEnv("PWD");
92 heapprofile_filename_ = pwd + "/" + heapprofile_filename_;
93 }
94
95 GlobalData::Instance()->SetProcessGroup(process_group_);
96 GlobalData::Instance()->SetSchedName(sched_name_);
97 AINFO << "binary_name_ is " << binary_name_ << ", process_group_ is "
98 << process_group_ << ", has " << dag_conf_list_.size() << " dag conf";
99 for (std::string& dag : dag_conf_list_) {
100 AINFO << "dag_conf: " << dag;
101 }
102}
void GetOptions(const int argc, char *const argv[])
std::string GetEnv(const std::string &var_name, const std::string &default_value="")
Definition environment.h:29

该类的文档由以下文件生成: