104 {
105 opterr = 0;
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
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) {
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':
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++] <<
"\"";
193 exit(1);
194 }
195
196 if (dag_conf_list_.empty()) {
197 AINFO <<
"-d parameter must be specified";
199 exit(1);
200 }
201}