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}};
93 for (
int i = 0; i < argc; ++i) {
97 AINFO <<
"command: " << cmd;
106 getopt_long(argc, argv, short_opts.c_str(), long_opts, &long_index);
114 arg = std::string(optarg);
115 switch (arg[arg.length() - 1]) {
123 base_size = 1024 * 1024;
126 AERROR <<
"Invalid identifier. It should be 'K' or 'M' or 'B'";
129 message_size = std::stoi(arg.substr(0, arg.length() - 1)) * base_size;
131 AERROR <<
"Invalid message size.";
141 AERROR <<
"Invalid running time. It should greater than 0";
148 AERROR <<
"Invalid qos_policy. It should be 0 or 1";
153 data_type = std::stoi(std::string(optarg));
155 AERROR <<
"Invalid data_type. It should be 0 or 1";
160#ifndef BASE_PROFILER_H_
161 AWARN <<
"gperftools not installed, ignore perf parameters";
169#ifndef BASE_PROFILER_H_
170 AWARN <<
"gperftools not installed, ignore perf parameters";
186 AINFO <<
"Found non-option ARGV-element \"" << argv[optind++] <<
"\"";
192 AINFO <<
"-s parameters must be specified";
198int main(
int argc,
char** argv) {
200 google::SetCommandLineOption(
"bvar_dump_interval",
"1");
206 std::make_shared<::bvar::Status<double>>(
BINARY_NAME +
"-test-time", 0);
207 auto test_message_size = std::make_shared<::bvar::Status<uint64_t>>(
210 attrs.set_channel_name(
"/apollo/cyber/benchmark");
211 auto qos = attrs.mutable_qos_profile();
215 qos->set_reliability(
218 qos->set_reliability(
256#ifdef BASE_PROFILER_H_
266 std::vector<uint32_t> trans_vec;
268 for (
int i = 0; i < num_of_instance; i++) {
269 trans_vec.push_back(rand());
276 while (send_msg < send_msg_total) {
277 auto trans_unit = writer->AcquireMessage();
280 for (
int i = 0; i < num_of_instance; i++) {
281 trans_vec[i] = base * i;
284 for (
int i = 0; i < num_of_instance; i++) {
285 *(uint32_t*)(data + i * 4) = base * i;
291 for (
int i = 0; i < num_of_instance; i++) {
292 trans_unit->add_data(trans_vec[i]);
296 writer->Write(trans_unit);
302 test_time->set_value((end_time - start_time).ToSecond());
305 auto current = start_time;
308 while (current < endtime) {
309 auto trans_unit = writer->AcquireMessage();
312 for (
int i = 0; i < num_of_instance; i++) {
313 trans_vec[i] = base * i;
316 for (
int i = 0; i < num_of_instance; i++) {
317 *(uint32_t*)(data + i * 4) = base * i;
323 for (
int i = 0; i < num_of_instance; i++) {
324 trans_unit->add_data(trans_vec[i]);
328 writer->Write(trans_unit);
332 test_time->set_value((current - start_time).ToSecond());
335 auto m = writer->AcquireMessage();
339 for (
int i = 0; i < num_of_instance; i++) {
340 m->add_data(trans_vec[i]);
343 test_message_size->set_value(m->ByteSizeLong());
348#ifdef BASE_PROFILER_H_
353 HeapProfilerDump(
"Befor shutdown");
358 std::this_thread::sleep_for(std::chrono::milliseconds(1200));