Apollo 10.0
自动驾驶开放平台
cyber_benchmark_reader.cc 文件参考
#include <getopt.h>
#include <libgen.h>
#include <string>
#include <vector>
#include "cyber/benchmark/benchmark_msg.pb.h"
#include "cyber/cyber.h"
cyber_benchmark_reader.cc 的引用(Include)关系图:

浏览源代码.

函数

void DisplayUsage ()
 
void GetOptions (const int argc, char *const argv[])
 
int main (int argc, char **argv)
 

变量

std::string BINARY_NAME = "cyber_benchmark_reader"
 
int nums_of_reader = 1
 
bool enable_cpuprofile = false
 
bool enable_heapprofile = false
 
std::string profile_filename = "cyber_benchmark_reader_cpu.prof"
 
std::string heapprofile_filename = "cyber_benchmark_reader_mem.prof"
 

函数说明

◆ DisplayUsage()

void DisplayUsage ( )

在文件 cyber_benchmark_reader.cc41 行定义.

41 {
42 AINFO << "Usage: \n " << BINARY_NAME << " [OPTION]...\n"
43 << "Description: \n"
44 << " -h, --help: help information \n"
45 << " -n, --nums_of_reader=nums_of_reader: numbers of reader, "
46 "default value is 1\n"
47 << " -c, --cpuprofile: enable gperftools cpu profile\n"
48 << " -o, --profile_filename=filename: the filename to dump the "
49 "profile to, default value is cyber_benchmark_writer_cpu.prof. "
50 "Only work with -c option\n"
51 << " -H, --heapprofile: enable gperftools heap profile\n"
52 << " -O, --heapprofile_filename=filename: the filename "
53 " to dump the profile to, default value is "
54 "cyber_benchmark_writer_mem.prof. Only work with -H option\n"
55 << "Example:\n"
56 << " " << BINARY_NAME << " -h\n"
57 << " " << BINARY_NAME << " -n 1\n"
58 << " " << BINARY_NAME << " -n 10 -c -H ";
59}
std::string BINARY_NAME
#define AINFO
Definition log.h:42

◆ GetOptions()

void GetOptions ( const int  argc,
char *const  argv[] 
)

在文件 cyber_benchmark_reader.cc61 行定义.

61 {
62 opterr = 0; // extern int opterr
63 int long_index = 0;
64 const std::string short_opts = "hn:co:HO:";
65 static const struct option long_opts[] = {
66 {"help", no_argument, nullptr, 'h'},
67 {"nums_of_reader", required_argument, nullptr, 'n'},
68 {"cpuprofile", no_argument, nullptr, 'c'},
69 {"profile_filename", required_argument, nullptr, 'o'},
70 {"heapprofile", no_argument, nullptr, 'H'},
71 {"heapprofile_filename", required_argument, nullptr, 'O'},
72 {NULL, no_argument, nullptr, 0}};
73
74 // log command for info
75 std::string cmd("");
76 for (int i = 0; i < argc; ++i) {
77 cmd += argv[i];
78 cmd += " ";
79 }
80 AINFO << "command: " << cmd;
81
82 if (1 == argc) {
84 exit(0);
85 }
86
87 do {
88 int opt =
89 getopt_long(argc, argv, short_opts.c_str(), long_opts, &long_index);
90 if (opt == -1) {
91 break;
92 }
93 switch (opt) {
94 case 'n':
95 nums_of_reader = std::stoi(std::string(optarg));
96 if (nums_of_reader < 0) {
97 AERROR << "Invalid numbers of reader. It should be grater than 0";
98 exit(-1);
99 }
100 break;
101 case 'c':
102#ifndef BASE_PROFILER_H_
103 AWARN << "gperftools not installed, ignore perf parameters";
104#endif
105 enable_cpuprofile = true;
106 break;
107 case 'o':
108 profile_filename = std::string(optarg);
109 break;
110 case 'H':
111#ifndef BASE_PROFILER_H_
112 AWARN << "gperftools not installed, ignore perf parameters";
113#endif
114 enable_heapprofile = true;
115 break;
116 case 'O':
117 heapprofile_filename = std::string(optarg);
118 break;
119 case 'h':
120 DisplayUsage();
121 exit(0);
122 default:
123 break;
124 }
125 } while (true);
126
127 if (optind < argc) {
128 AINFO << "Found non-option ARGV-element \"" << argv[optind++] << "\"";
129 DisplayUsage();
130 exit(1);
131 }
132}
bool enable_heapprofile
void DisplayUsage()
int nums_of_reader
std::string heapprofile_filename
std::string profile_filename
bool enable_cpuprofile
#define AERROR
Definition log.h:44
#define AWARN
Definition log.h:43

◆ main()

int main ( int  argc,
char **  argv 
)

在文件 cyber_benchmark_reader.cc134 行定义.

134 {
135 GetOptions(argc, argv);
136 google::SetCommandLineOption("bvar_dump_interval", "1");
137 apollo::cyber::Init(argv[0],
138 BINARY_NAME + "_" + std::to_string(nums_of_reader));
139
140 apollo::cyber::ReaderConfig reader_config;
141 reader_config.channel_name = "/apollo/cyber/benchmark";
142 reader_config.qos_profile.set_depth(10);
143
144 std::vector<std::shared_ptr<apollo::cyber::Reader<BenchmarkMsg>>> vec;
145
146 // for (int i = 0; i < nums_of_reader; i++) {
147 std::string node_name = BINARY_NAME + "-" + std::to_string(nums_of_reader);
148 auto node = apollo::cyber::CreateNode(node_name);
149 vec.push_back(std::move(node->CreateReader<BenchmarkMsg>(
150 reader_config, [](const std::shared_ptr<BenchmarkMsg> m) {})));
151 // }
152
153#ifndef NO_TCMALLOC
154#ifdef BASE_PROFILER_H_
155 if (enable_cpuprofile) {
156 ProfilerStart(profile_filename.c_str());
157 }
158 if (enable_heapprofile) {
159 HeapProfilerStart(heapprofile_filename.c_str());
160 }
161#endif
162#endif
163
165
166#ifndef NO_TCMALLOC
167#ifdef BASE_PROFILER_H_
168 if (enable_cpuprofile) {
169 ProfilerStop();
170 }
171 if (enable_heapprofile) {
172 HeapProfilerDump("Befor shutdown");
173 HeapProfilerStop();
174 }
175#endif
176#endif
177
178 return 0;
179}
void GetOptions(const int argc, char *const argv[])
void WaitForShutdown()
Definition state.h:50
bool Init(const char *binary_name, const std::string &dag_info)
Definition init.cc:98
std::unique_ptr< Node > CreateNode(const std::string &node_name, const std::string &name_space)
Definition cyber.cc:33

变量说明

◆ BINARY_NAME

std::string BINARY_NAME = "cyber_benchmark_reader"

在文件 cyber_benchmark_reader.cc33 行定义.

◆ enable_cpuprofile

bool enable_cpuprofile = false

在文件 cyber_benchmark_reader.cc36 行定义.

◆ enable_heapprofile

bool enable_heapprofile = false

在文件 cyber_benchmark_reader.cc37 行定义.

◆ heapprofile_filename

std::string heapprofile_filename = "cyber_benchmark_reader_mem.prof"

在文件 cyber_benchmark_reader.cc39 行定义.

◆ nums_of_reader

int nums_of_reader = 1

在文件 cyber_benchmark_reader.cc35 行定义.

◆ profile_filename

std::string profile_filename = "cyber_benchmark_reader_cpu.prof"

在文件 cyber_benchmark_reader.cc38 行定义.