Apollo 10.0
自动驾驶开放平台
recorder_monitor.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2019 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
19#include "cyber/common/log.h"
20#include "modules/common_msgs/monitor_msgs/smart_recorder_status.pb.h"
25
26DEFINE_string(smart_recorder_monitor_name, "SmartRecorderMonitor",
27 "Name of the smart recorder monitor.");
28DEFINE_double(smart_recorder_monitor_interval, 5,
29 "Smart recorder status checking interval (s).");
30DEFINE_string(smart_recorder_component_name, "SmartRecorder",
31 "Smart recorder component name.");
32
33namespace apollo {
34namespace monitor {
35
38
40 : RecurrentRunner(FLAGS_smart_recorder_monitor_name,
41 FLAGS_smart_recorder_monitor_interval) {}
42
43void RecorderMonitor::RunOnce(const double current_time) {
44 auto manager = MonitorManager::Instance();
45 auto* component = apollo::common::util::FindOrNull(
46 *manager->GetStatus()->mutable_components(),
47 FLAGS_smart_recorder_component_name);
48 if (component == nullptr) {
49 // SmartRecorder is not monitored in current mode, skip.
50 return;
51 }
52
53 static auto reader =
54 manager->CreateReader<SmartRecorderStatus>(FLAGS_recorder_status_topic);
55 reader->Observe();
56 const auto status = reader->GetLatestObserved();
57
58 ComponentStatus* component_status = component->mutable_other_status();
59 component_status->clear_status();
60 if (status == nullptr) {
61 SummaryMonitor::EscalateStatus(ComponentStatus::ERROR,
62 "No SmartRecorderStatus received",
63 component_status);
64 return;
65 }
66
67 // Translate SmartRecorderStatus to ComponentStatus. Note that ERROR and FATAL
68 // will trigger safety mode in current settings.
69 switch (status->recording_state()) {
70 case RecordingState::RECORDING:
71 SummaryMonitor::EscalateStatus(ComponentStatus::OK, "", component_status);
72 break;
73 case RecordingState::TERMINATING:
75 ComponentStatus::WARN,
76 absl::StrCat("WARNNING: ", status->state_message()),
77 component_status);
78 break;
79 case RecordingState::STOPPED:
81 ComponentStatus::OK,
82 absl::StrCat("STOPPED: ", status->state_message()), component_status);
83 break;
84 default:
85 AFATAL << "Unknown recording status: " << status->recording_state();
86 break;
87 }
88}
89
90} // namespace monitor
91} // namespace apollo
void RunOnce(const double current_time) override
static void EscalateStatus(const ComponentStatus::Status new_status, const std::string &message, ComponentStatus *current_status)
#define AFATAL
Definition log.h:45
Some map util functions.
class register implement
Definition arena_queue.h:37
DEFINE_string(smart_recorder_monitor_name, "SmartRecorderMonitor", "Name of the smart recorder monitor.")
DEFINE_double(smart_recorder_monitor_interval, 5, "Smart recorder status checking interval (s).")