Apollo 11.0
自动驾驶开放平台
apollo::resource_statistic::MemoryResourceStatistic类 参考

#include <memory_resource_statistic.h>

apollo::resource_statistic::MemoryResourceStatistic 的协作图:

Public 成员函数

bool GetMemoryMetric (MemoryMetric *mem_metric)
 Get memory metric and write it into mem_metric.
 

详细描述

在文件 memory_resource_statistic.h 第 32 行定义.

成员函数说明

◆ GetMemoryMetric()

bool apollo::resource_statistic::MemoryResourceStatistic::GetMemoryMetric ( MemoryMetric *  mem_metric)

Get memory metric and write it into mem_metric.

参数
mem_metricMemory metric message
返回
If get metric successfully.

在文件 memory_resource_statistic.cc 第 26 行定义.

26 {
27 static const std::string system_mem_stat_file = "/proc/meminfo";
28 const int mem_total = 0, available = 2, line_count = 3;
29 const auto stat_lines = GetStatsLines(system_mem_stat_file, line_count);
30 if (stat_lines.size() < line_count) {
31 AERROR << "failed to load contents from " << system_mem_stat_file;
32 return false;
33 }
34 const auto total_memory = GetMemoryValueFromLine(stat_lines[mem_total]);
35 const auto available_memory = GetMemoryValueFromLine(stat_lines[available]);
36 if (available_memory > total_memory) {
37 AERROR << "available memory is larger than total memory";
38 return false;
39 }
40 const auto used_memory = total_memory - available_memory;
41 mem_metric->set_total_mb(total_memory >> 10);
42 mem_metric->set_used_mb(used_memory >> 10);
43 mem_metric->set_available_mb((total_memory - used_memory) >> 10);
44 mem_metric->set_usage(100.f * (static_cast<float>(used_memory) / total_memory));
45 return true;
46}
#define AERROR
Definition log.h:44
std::vector< std::string > GetStatsLines(const std::string &stat_file, const int line_count)
Get stats lines from file
Definition util.cc:24

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