Apollo 10.0
自动驾驶开放平台
apollo::cyber::statistics::Statistics类 参考

#include <statistics.h>

apollo::cyber::statistics::Statistics 的协作图:

Public 成员函数

 ~Statistics ()
 
bool RegisterChanVar (const proto::RoleAttributes &role_attr)
 
bool CreateSpan (std::string name, uint64_t min_ns=0)
 
bool StartSpan (std::string name)
 
bool EndSpan (std::string name)
 
void DisableChanVar ()
 
template<typename SampleT >
std::shared_ptr<::bvar::Adder< SampleT > > CreateAdder (const proto::RoleAttributes &role_attr)
 
template<typename SampleT >
bool SamplingProcLatency (const proto::RoleAttributes &role_attr, SampleT sample)
 
template<typename SampleT >
bool SamplingTranLatency (const proto::RoleAttributes &role_attr, SampleT sample)
 
template<typename SampleT >
bool SamplingCyberLatency (const proto::RoleAttributes &role_attr, SampleT sample)
 
bool SetProcStatus (const proto::RoleAttributes &role_attr, uint64_t val)
 
bool GetProcStatus (const proto::RoleAttributes &role_attr, uint64_t *val)
 
bool SetTotalMsgsStatus (const proto::RoleAttributes &role_attr, int32_t val)
 
bool AddRecvCount (const proto::RoleAttributes &role_attr, int total_msg_val)
 

详细描述

在文件 statistics.h55 行定义.

构造及析构函数说明

◆ ~Statistics()

apollo::cyber::statistics::Statistics::~Statistics ( )
inline

在文件 statistics.h57 行定义.

57{}

成员函数说明

◆ AddRecvCount()

bool apollo::cyber::statistics::Statistics::AddRecvCount ( const proto::RoleAttributes role_attr,
int  total_msg_val 
)
inline

在文件 statistics.h176 行定义.

176 {
177 if (disable_chan_var_) {
178 return true;
179 }
180 if (role_attr.channel_name() == TIMER_COMPONENT_CHAN_NAME) {
181 return true;
182 }
183
184 auto var_ptr = GetAdderVar(role_attr);
185 if (var_ptr == nullptr) {
186 return true;
187 }
188
189 if cyber_unlikely(first_recv_) {
190 (*var_ptr) << total_msg_val;
191 first_recv_ = false;
192 return true;
193 }
194
195 (*var_ptr) << 1;
196
197 return true;
198 }
#define cyber_unlikely(x)
Definition macros.h:30

◆ CreateAdder()

template<typename SampleT >
std::shared_ptr<::bvar::Adder< SampleT > > apollo::cyber::statistics::Statistics::CreateAdder ( const proto::RoleAttributes role_attr)
inline

在文件 statistics.h69 行定义.

70 {
71 std::string expose_name =
72 role_attr.node_name() + "-" + role_attr.channel_name();
73 return std::make_shared<::bvar::Adder<SampleT>>(expose_name);
74 }

◆ CreateSpan()

bool apollo::cyber::statistics::Statistics::CreateSpan ( std::string  name,
uint64_t  min_ns = 0 
)
inline

在文件 statistics.h263 行定义.

263 {
264 if (cyber_unlikely(span_handlers_.find(name) != span_handlers_.end())) {
265 AERROR << "span handler " << name << "has been created!";
266 return false;
267 }
268 auto handler = std::make_shared<SpanHandler>();
269 handler->name = name;
270 handler->span_trace_node = std::move(
271 std::make_shared<::bvar::LatencyRecorder>(name, "user", 1200));
272 handler->min_ns = min_ns;
273
274 span_handlers_[name] = std::move(handler);
275 return true;
276}
#define AERROR
Definition log.h:44

◆ DisableChanVar()

void apollo::cyber::statistics::Statistics::DisableChanVar ( )
inline

在文件 statistics.h64 行定义.

64 {
65 disable_chan_var_ = true;
66 }

◆ EndSpan()

bool apollo::cyber::statistics::Statistics::EndSpan ( std::string  name)
inline

在文件 statistics.h288 行定义.

288 {
289 auto it = span_handlers_.find(name);
290 if (cyber_unlikely(it == span_handlers_.end())) {
291 AERROR << "span handler " << name << "not found!";
292 return false;
293 }
294 it->second->end_time = std::move(GetMicroTimeNow());
295 auto handler = it->second;
296 auto diff = handler->end_time - handler->start_time;
297 if (cyber_unlikely(diff < handler->min_ns)) {
298 AWARN << "Time span less than preset value: " \
299 << diff << " vs " << handler->min_ns;
300 return false;
301 }
302 if (cyber_unlikely(diff > INT32_MAX)) {
303 AWARN << "Time span is larger than INT32_MAX: " << diff << ", drop it...";
304 return false;
305 }
306 *(handler->span_trace_node) << diff;
307 return true;
308}
#define AWARN
Definition log.h:43

◆ GetProcStatus()

bool apollo::cyber::statistics::Statistics::GetProcStatus ( const proto::RoleAttributes role_attr,
uint64_t *  val 
)
inline

在文件 statistics.h143 行定义.

143 {
144 if (disable_chan_var_) {
145 *val = 0;
146 return true;
147 }
148 if (role_attr.channel_name() == TIMER_COMPONENT_CHAN_NAME) {
149 return false;
150 }
151 auto var_ptr = GetProcStatusVar(role_attr);
152 if (var_ptr != nullptr) {
153 *val = var_ptr->get_value();
154 } else {
155 return false;
156 }
157 return true;
158 }

◆ RegisterChanVar()

bool apollo::cyber::statistics::Statistics::RegisterChanVar ( const proto::RoleAttributes role_attr)

在文件 statistics.cc25 行定义.

25 {
26 if (latency_map_.find(GetProcLatencyKey(role_attr)) != latency_map_.end()) {
27 AERROR << "Failed to create proc latency var: "
28 "reader with the same channel already exists.";
29 return false;
30 }
31
32 if (latency_map_.find(GetTranLatencyKey(role_attr)) != latency_map_.end()) {
33 AERROR << "Failed to create tran latency var: "
34 "reader with the same channel already exists.";
35 return false;
36 }
37
38 if (latency_map_.find(GetCyberLatencyKey(role_attr)) != latency_map_.end()) {
39 AERROR << "Failed to create cyber latency var: "
40 "reader with the same channel already exists.";
41 return false;
42 }
43
44 latency_map_[GetProcLatencyKey(role_attr)] =
45 std::make_shared<::bvar::LatencyRecorder>(
46 role_attr.node_name() + "-"
47 + role_attr.channel_name(), "proc");
48 if (role_attr.channel_name() != TIMER_COMPONENT_CHAN_NAME) {
49 latency_map_[GetTranLatencyKey(role_attr)] =
50 std::make_shared<::bvar::LatencyRecorder>(
51 role_attr.node_name() + "-" +
52 role_attr.channel_name(), "tran");
53 latency_map_[GetCyberLatencyKey(role_attr)] =
54 std::make_shared<::bvar::LatencyRecorder>(
55 role_attr.node_name() + "-" +
56 role_attr.channel_name(), "cyber");
57 status_map_[GetStartProcessStatusKey(role_attr)] =
58 std::make_shared<::bvar::Status<uint64_t>>(
59 role_attr.node_name() + "-" +
60 role_attr.channel_name() + "-process", 0);
61 status_map_[GetTotalMsgsStatusKey(role_attr)] =
62 std::make_shared<::bvar::Status<uint64_t>>(
63 role_attr.node_name() + "-" +
64 role_attr.channel_name() + "-total-msgs-nums", 0);
65 adder_map_[GetTotalRecvStatusKey(role_attr)] =
66 std::make_shared<::bvar::Adder<int32_t>>(
67 role_attr.node_name() +
68 "-" + role_attr.channel_name() + "-recv-msgs-nums");
69 }
70 return true;
71}

◆ SamplingCyberLatency()

template<typename SampleT >
bool apollo::cyber::statistics::Statistics::SamplingCyberLatency ( const proto::RoleAttributes role_attr,
SampleT  sample 
)
inline

在文件 statistics.h110 行定义.

111 {
112 if (disable_chan_var_) {
113 return true;
114 }
115 if (role_attr.channel_name() == TIMER_COMPONENT_CHAN_NAME) {
116 return true;
117 }
118 auto var_ptr = GetChanCyberVar(role_attr);
119 if (var_ptr != nullptr) {
120 (*var_ptr) << sample;
121 } else {
122 return false;
123 }
124 return true;
125 }

◆ SamplingProcLatency()

template<typename SampleT >
bool apollo::cyber::statistics::Statistics::SamplingProcLatency ( const proto::RoleAttributes role_attr,
SampleT  sample 
)
inline

在文件 statistics.h77 行定义.

78 {
79 if (disable_chan_var_) {
80 return true;
81 }
82 auto var_ptr = GetChanProcVar(role_attr);
83 if (var_ptr != nullptr) {
84 (*var_ptr) << sample;
85 } else {
86 return false;
87 }
88 return true;
89 }

◆ SamplingTranLatency()

template<typename SampleT >
bool apollo::cyber::statistics::Statistics::SamplingTranLatency ( const proto::RoleAttributes role_attr,
SampleT  sample 
)
inline

在文件 statistics.h92 行定义.

93 {
94 if (disable_chan_var_) {
95 return true;
96 }
97 if (role_attr.channel_name() == TIMER_COMPONENT_CHAN_NAME) {
98 return true;
99 }
100 auto var_ptr = GetChanTranVar(role_attr);
101 if (var_ptr != nullptr) {
102 (*var_ptr) << sample;
103 } else {
104 return false;
105 }
106 return true;
107 }

◆ SetProcStatus()

bool apollo::cyber::statistics::Statistics::SetProcStatus ( const proto::RoleAttributes role_attr,
uint64_t  val 
)
inline

在文件 statistics.h127 行定义.

127 {
128 if (disable_chan_var_) {
129 return true;
130 }
131 if (role_attr.channel_name() == TIMER_COMPONENT_CHAN_NAME) {
132 return true;
133 }
134 auto var_ptr = GetProcStatusVar(role_attr);
135 if (var_ptr != nullptr) {
136 var_ptr->set_value(val);
137 } else {
138 return false;
139 }
140 return true;
141 }

◆ SetTotalMsgsStatus()

bool apollo::cyber::statistics::Statistics::SetTotalMsgsStatus ( const proto::RoleAttributes role_attr,
int32_t  val 
)
inline

在文件 statistics.h160 行定义.

160 {
161 if (disable_chan_var_) {
162 return true;
163 }
164 if (role_attr.channel_name() == TIMER_COMPONENT_CHAN_NAME) {
165 return true;
166 }
167 auto var_ptr = GetTotalMsgsStatusVar(role_attr);
168 if (var_ptr != nullptr) {
169 var_ptr->set_value(val);
170 } else {
171 return false;
172 }
173 return true;
174 }

◆ StartSpan()

bool apollo::cyber::statistics::Statistics::StartSpan ( std::string  name)
inline

在文件 statistics.h278 行定义.

278 {
279 auto it = span_handlers_.find(name);
280 if (cyber_unlikely(it == span_handlers_.end())) {
281 AERROR << "span handler " << name << "not found!";
282 return false;
283 }
284 it->second->start_time = std::move(GetMicroTimeNow());
285 return true;
286}

该类的文档由以下文件生成: