Apollo 11.0
自动驾驶开放平台
resource_statistic_component.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2023 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 *****************************************************************************/
17
20
21namespace apollo {
22namespace resource_statistic {
23
25 // hook: Apollo License Verification: v_apollo_park
27 if (!ComponentBase::GetProtoConfig(&conf)) {
28 AERROR << "Unable to load resource statistic conf file: " << ComponentBase::ConfigFilePath();
29 return false;
30 }
31 LoadConf(conf);
32 disk_statistic_.SetInterval(GetInterval());
33 // create metric writer
34 metric_writer_ = node_->CreateWriter<ResourceMetrics>(FLAGS_resource_statistic_topic);
35 return true;
36}
37
38void ResourceStatisticComponent::LoadConf(const ResourceStatisticConf& conf) {
39 if (conf.has_disk_conf()) {
40 disk_statistic_.LoadDiskConf(conf.disk_conf());
41 }
42}
43
45 auto metrics = std::make_shared<ResourceMetrics>();
46 apollo::common::util::FillHeader(node_->Name(), metrics.get());
47
48 auto cpu_metric = metrics->mutable_cpu();
49 cpu_statistic_.GetCpuMetric(cpu_metric);
50
51 auto gpu_metric = metrics->mutable_gpu();
52 gpu_statistic_.GetGpuMetric(gpu_metric);
53
54 auto mem_metric = metrics->mutable_memory();
55 mem_statistic_.GetMemoryMetric(mem_metric);
56
57 auto disk_metric = metrics->mutable_disk();
58 disk_statistic_.GetDiskMetric(disk_metric);
59
60 metric_writer_->Write(metrics);
61 return true;
62}
63
64} // namespace resource_statistic
65} // namespace apollo
std::shared_ptr< Node > node_
bool GetCpuMetric(CpuMetric *cpu_metric)
Get CPU metric and write it into cpu_metric.
void SetInterval(uint32_t interval)
Set timer component interval.
void LoadDiskConf(const ResourceStatisticConf_DiskConf &disk_conf)
Load disk conf.
bool GetDiskMetric(DiskMetric *disk_metric)
Get Disk metric and write it into disk_metric.
bool GetGpuMetric(GpuMetric *gpu_metric)
Get GPU metric and write it into gpu_metric.
bool GetMemoryMetric(MemoryMetric *mem_metric)
Get memory metric and write it into mem_metric.
bool Proc() override
The Proc logic of the component, which called by the CyberRT frame.
#define AERROR
Definition log.h:44
Some string util functions.
class register implement
Definition arena_queue.h:37