23static constexpr char LOG_TAG[] =
"zigpc_metric_ram_usage";
35 long int page_size = sysconf(_SC_PAGESIZE);
36 if (page_size == -1) {
53 unsigned long mem_total_kb = 0UL;
56 if (!meminfo_f.is_open()) {
61 std::string meminfo_field;
62 meminfo_f >> meminfo_field;
63 if (meminfo_field !=
"MemTotal:") {
68 meminfo_f >> mem_total_kb;
69 if (meminfo_f.fail()) {
85 unsigned long rss_kb = 0UL;
88 if (!statm_file.is_open()) {
93 unsigned long stat_m_field;
94 statm_file >> stat_m_field;
95 statm_file >> stat_m_field;
97 if (statm_file.fail()) {
99 "Failed to read resident set from %s",
104 rss_kb = stat_m_field;
114 static constexpr char LOG_TAG[] =
"zigpc_metric_ram_usage";
147 unsigned long resident_set_kb
149 if (resident_set_kb == 0UL) {
160 std::stringstream ss;
161 ss << std::fixed << std::setprecision(1) <<
mem_usage;
Abstract top level metric from which all diagnostic metric derive from.
Definition: zigpc_diagnostics_metric.hpp:25
zigpc_diagnostics_notification & on_update_complete
Definition: zigpc_diagnostics_metric.hpp:28
std::string serialized_value
Definition: zigpc_diagnostics_metric.hpp:30
std::string metric_id
Definition: zigpc_diagnostics_metric.hpp:29
Definition: zigpc_diagnostics_notification.hpp:20
virtual void notify(std::string metric_id)
Definition: zigpc_diagnostics_notification.hpp:22
Definition: zigpc_mem_usage_metric.hpp:112
void update_value(void) final
Update the memory usage by process.
Definition: zigpc_mem_usage_metric.hpp:140
static constexpr char LOG_TAG[]
Definition: zigpc_mem_usage_metric.hpp:114
float get_value(void) const
Get the memory usage.
Definition: zigpc_mem_usage_metric.hpp:131
zigpc_mem_usage_metric(zigpc_diagnostics_notification ¬if, std::string const &metric_id)
Definition: zigpc_mem_usage_metric.hpp:121
long int page_size_kb
Definition: zigpc_mem_usage_metric.hpp:116
float mem_usage
Definition: zigpc_mem_usage_metric.hpp:118
unsigned long total_mem_kb
Definition: zigpc_mem_usage_metric.hpp:117
#define sl_log_error(tag, fmtstr,...)
Definition: sl_log.h:145
Definition: zigpc_mem_usage_metric.hpp:22
static unsigned long get_mem_total(void)
Get system total memory usage in KiloBytes.
Definition: zigpc_mem_usage_metric.hpp:51
static constexpr char PATH_PROC_STATM[]
Definition: zigpc_mem_usage_metric.hpp:26
static constexpr char PATH_PROC_MEMINFO[]
Definition: zigpc_mem_usage_metric.hpp:25
static unsigned long get_resident_set_kb(void)
Get the resident memory pages used by program. This number is in KiloBytes.
Definition: zigpc_mem_usage_metric.hpp:83
static long int get_pagesize_kb(void)
Get system page size in KiloBytes.
Definition: zigpc_mem_usage_metric.hpp:33
static constexpr char LOG_TAG[]
Definition: zigpc_mem_usage_metric.hpp:23