74 {
75 opterr = 0;
76 int long_index = 0;
77 const std::string short_opts = "hs:t:q:d:T:co:HO:";
78 static const struct option long_opts[] = {
79 {"help", no_argument, nullptr, 'h'},
80 {"message_size", required_argument, nullptr, 's'},
81 {"transport_freq", required_argument, nullptr, 't'},
82 {"qos_policy", required_argument, nullptr, 'q'},
83 {"data_type", required_argument, nullptr, 'd'},
84 {"time", required_argument, nullptr, 'T'},
85 {"cpuprofile", no_argument, nullptr, 'c'},
86 {"profile_filename", required_argument, nullptr, 'o'},
87 {"heapprofile", no_argument, nullptr, 'H'},
88 {"heapprofile_filename", required_argument, nullptr, 'O'},
89 {NULL, no_argument, nullptr, 0}};
90
91
92 std::string cmd("");
93 for (int i = 0; i < argc; ++i) {
94 cmd += argv[i];
95 cmd += " ";
96 }
97 AINFO <<
"command: " << cmd;
98
99 if (1 == argc) {
101 exit(0);
102 }
103
104 do {
105 int opt =
106 getopt_long(argc, argv, short_opts.c_str(), long_opts, &long_index);
107 if (opt == -1) {
108 break;
109 }
110 int base_size = 1;
111 std::string arg;
112 switch (opt) {
113 case 's':
114 arg = std::string(optarg);
115 switch (arg[arg.length() - 1]) {
116 case 'B':
117 base_size = 1;
118 break;
119 case 'K':
120 base_size = 1024;
121 break;
122 case 'M':
123 base_size = 1024 * 1024;
124 break;
125 default:
126 AERROR <<
"Invalid identifier. It should be 'K' or 'M' or 'B'";
127 exit(-1);
128 }
129 message_size = std::stoi(arg.substr(0, arg.length() - 1)) * base_size;
131 AERROR <<
"Invalid message size.";
132 exit(-1);
133 }
134 break;
135 case 't':
137 break;
138 case 'T':
141 AERROR <<
"Invalid running time. It should greater than 0";
142 exit(-1);
143 }
144 break;
145 case 'q':
148 AERROR <<
"Invalid qos_policy. It should be 0 or 1";
149 exit(-1);
150 }
151 break;
152 case 'd':
153 data_type = std::stoi(std::string(optarg));
155 AERROR <<
"Invalid data_type. It should be 0 or 1";
156 exit(-1);
157 }
158 break;
159 case 'c':
160#ifndef BASE_PROFILER_H_
161 AWARN <<
"gperftools not installed, ignore perf parameters";
162#endif
164 break;
165 case 'o':
167 break;
168 case 'H':
169#ifndef BASE_PROFILER_H_
170 AWARN <<
"gperftools not installed, ignore perf parameters";
171#endif
173 break;
174 case 'O':
176 break;
177 case 'h':
179 exit(0);
180 default:
181 break;
182 }
183 } while (true);
184
185 if (optind < argc) {
186 AINFO <<
"Found non-option ARGV-element \"" << argv[optind++] <<
"\"";
188 exit(1);
189 }
190
192 AINFO <<
"-s parameters must be specified";
194 exit(1);
195 }
196}
std::string heapprofile_filename
std::string profile_filename