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