Apollo 10.0
自动驾驶开放平台
mainboard.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2018 The Apollo Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
16
17#include <string.h>
18
19#include <list>
20#include <string>
21
23#include "cyber/common/log.h"
24#include "cyber/init.h"
27#include "cyber/state.h"
28
29#include "gperftools/profiler.h"
30#include "gperftools/heap-profiler.h"
31#include "gperftools/malloc_extension.h"
32
35
36int main(int argc, char** argv) {
37 // parse the argument
38 ModuleArgument module_args;
39 module_args.ParseArgument(argc, argv);
40
41 auto dag_list = module_args.GetDAGConfList();
42
43 std::string dag_info;
44 for (auto&& i = dag_list.begin(); i != dag_list.end(); i++) {
45 size_t pos = 0;
46 for (size_t j = 0; j < (*i).length(); j++) {
47 pos = ((*i)[j] == '/') ? j: pos;
48 }
49 if (i != dag_list.begin()) dag_info += "_";
50
51 if (pos == 0) {
52 dag_info += *i;
53 } else {
54 dag_info +=
55 (pos == (*i).length()-1) ? (*i).substr(pos): (*i).substr(pos+1);
56 }
57 }
58
59 if (module_args.GetProcessGroup() !=
60 apollo::cyber::mainboard::DEFAULT_process_group_) {
61 dag_info = module_args.GetProcessGroup();
62 }
63
64 // initialize cyber
65 apollo::cyber::Init(argv[0], dag_info);
66
67 static bool enable_cpu_profile = module_args.GetEnableCpuprofile();
68 static bool enable_mem_profile = module_args.GetEnableHeapprofile();
69 std::signal(SIGTERM, [](int sig){
71 if (enable_cpu_profile) {
72 ProfilerStop();
73 }
74
75 if (enable_mem_profile) {
76 HeapProfilerDump("Befor shutdown");
77 HeapProfilerStop();
78 }
79 });
80
81 if (module_args.GetEnableHeapprofile()) {
82 auto profile_filename = module_args.GetHeapProfileFilename();
83 HeapProfilerStart(profile_filename.c_str());
84 }
85
86 // start module
87 ModuleController controller(module_args);
88 if (!controller.Init()) {
89 controller.Clear();
90 AERROR << "module start error.";
91 return -1;
92 }
93
94 if (module_args.GetEnableCpuprofile()) {
95 auto profile_filename = module_args.GetProfileFilename();
96 ProfilerStart(profile_filename.c_str());
97 }
98
100
101 if (module_args.GetEnableCpuprofile()) {
102 ProfilerStop();
103 }
104
105 if (module_args.GetEnableHeapprofile()) {
106 HeapProfilerDump("Befor shutdown");
107 HeapProfilerStop();
108 }
109
110 controller.Clear();
111 AINFO << "exit mainboard.";
112
113 return 0;
114}
const std::list< std::string > & GetDAGConfList() const
const std::string & GetProcessGroup() const
void ParseArgument(int argc, char *const argv[])
const std::string GetHeapProfileFilename() const
const std::string GetProfileFilename() const
std::string profile_filename
#define AERROR
Definition log.h:44
#define AINFO
Definition log.h:42
int main(int argc, char **argv)
Definition mainboard.cc:36
void OnShutdown(int sig)
Definition init.cc:89
void WaitForShutdown()
Definition state.h:50
bool Init(const char *binary_name, const std::string &dag_info)
Definition init.cc:98