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