Apollo 10.0
自动驾驶开放平台
statistics.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2024 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
18
19namespace apollo {
20namespace cyber {
21namespace statistics {
22
23Statistics::Statistics() {}
24
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}
72
73StatusVarPtr Statistics::GetProcStatusVar(
74 const proto::RoleAttributes& role_attr) {
75 auto v = status_map_.find(GetStartProcessStatusKey(role_attr));
76 if (v == status_map_.end()) {
77 return nullptr;
78 }
79 return v->second;
80}
81
82LatencyVarPtr Statistics::GetChanProcVar(
83 const proto::RoleAttributes& role_attr) {
84 auto v = latency_map_.find(GetProcLatencyKey(role_attr));
85 if (v == latency_map_.end()) {
86 return nullptr;
87 }
88 return v->second;
89}
90
91LatencyVarPtr Statistics::GetChanTranVar(
92 const proto::RoleAttributes& role_attr) {
93 auto v = latency_map_.find(GetTranLatencyKey(role_attr));
94 if (v == latency_map_.end()) {
95 return nullptr;
96 }
97 return v->second;
98}
99
100LatencyVarPtr Statistics::GetChanCyberVar(
101 const proto::RoleAttributes& role_attr) {
102 auto v = latency_map_.find(GetCyberLatencyKey(role_attr));
103 if (v == latency_map_.end()) {
104 return nullptr;
105 }
106 return v->second;
107}
108
109StatusVarPtr Statistics::GetTotalMsgsStatusVar(
110 const proto::RoleAttributes& role_attr) {
111 auto v = status_map_.find(GetTotalMsgsStatusKey(role_attr));
112 if (v == status_map_.end()) {
113 return nullptr;
114 }
115 return v->second;
116}
117
118AdderVarPtr Statistics::GetAdderVar(
119 const proto::RoleAttributes& role_attr) {
120 auto v = adder_map_.find(GetTotalRecvStatusKey(role_attr));
121 if (v == adder_map_.end()) {
122 return nullptr;
123 }
124 return v->second;
125}
126
127
128} // namespace statistics
129} // namespace cyber
130} // namespace apollo
bool RegisterChanVar(const proto::RoleAttributes &role_attr)
Definition statistics.cc:25
#define AERROR
Definition log.h:44
std::shared_ptr<::bvar::LatencyRecorder > LatencyVarPtr
Definition statistics.h:41
std::shared_ptr<::bvar::Adder< int32_t > > AdderVarPtr
Definition statistics.h:43
std::shared_ptr<::bvar::Status< uint64_t > > StatusVarPtr
Definition statistics.h:42
class register implement
Definition arena_queue.h:37