From 723c56051e828f8ed68e8f07629d4ba1241779ba Mon Sep 17 00:00:00 2001 From: AlaiaL Date: Fri, 26 Feb 2021 15:07:17 +0100 Subject: [PATCH] [metrics] Changed the extension from cpp to cc. - Fix date of CMakeLists.txt. - Initialization of the used variables in the cpu usage calculation. --- lib/include/srslte/system/sys_metrics.h | 2 +- lib/include/srslte/system/sys_metrics_processor.h | 14 ++++++++++---- lib/src/system/CMakeLists.txt | 4 ++-- ...rics_processor.cpp => sys_metrics_processor.cc} | 4 ++++ 4 files changed, 17 insertions(+), 7 deletions(-) rename lib/src/system/{sys_metrics_processor.cpp => sys_metrics_processor.cc} (99%) diff --git a/lib/include/srslte/system/sys_metrics.h b/lib/include/srslte/system/sys_metrics.h index 57fd7aa7a..090e862f1 100644 --- a/lib/include/srslte/system/sys_metrics.h +++ b/lib/include/srslte/system/sys_metrics.h @@ -24,7 +24,7 @@ namespace srslte { -/// Metrics that will be returned in the system. +/// Metrics of cpu usage, memory consumption and number of thread used by the process. struct sys_metrics_t { unsigned process_realmem_kB = 0; unsigned process_virtualmem_kB = 0; diff --git a/lib/include/srslte/system/sys_metrics_processor.h b/lib/include/srslte/system/sys_metrics_processor.h index 8f4c1de47..8690c601f 100644 --- a/lib/include/srslte/system/sys_metrics_processor.h +++ b/lib/include/srslte/system/sys_metrics_processor.h @@ -35,12 +35,18 @@ class sys_metrics_processor struct proc_stats_info { proc_stats_info(); + // Initialize the variables that will be used. + int long num_threads = 0; + unsigned long utime = 0; + unsigned long stime = 0; + + // Rest of the information of the stats file. int pid, ppid, pgrp, session, tty_nr, tpgid, exit_signal, processor, exit_code; unsigned flags, rt_priority, policy; - unsigned long minflt, cminflt, majflt, cmajflt, utime, stime, vsize, rsslim, startcode, endcode, startstack, - kstkesp, kstkeip, signal, blocked, sigignore, sigcatch, wchan, nswap, cnswap, guest_time, start_data, end_data, - start_brk, arg_start, arg_end, env_start, env_end; - int long cutime, cstime, priority, nice, num_threads, itrealvalue, rss, cguest_time; + unsigned long minflt, cminflt, majflt, cmajflt, vsize, rsslim, startcode, endcode, startstack, kstkesp, kstkeip, + signal, blocked, sigignore, sigcatch, wchan, nswap, cnswap, guest_time, start_data, end_data, start_brk, + arg_start, arg_end, env_start, env_end; + int long cutime, cstime, priority, nice, itrealvalue, rss, cguest_time; unsigned long long starttime, delaycct_blkio_ticks; char state; std::string comm; diff --git a/lib/src/system/CMakeLists.txt b/lib/src/system/CMakeLists.txt index 5ba318d19..d1f3cd9fd 100644 --- a/lib/src/system/CMakeLists.txt +++ b/lib/src/system/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright 2013-2020 Software Radio Systems Limited +# Copyright 2013-2021 Software Radio Systems Limited # # By using this file, you agree to the terms and conditions set # forth in the LICENSE file which can be found at the top level of @@ -7,7 +7,7 @@ # set(SOURCES - sys_metrics_processor.cpp) + sys_metrics_processor.cc) find_package(Threads REQUIRED) diff --git a/lib/src/system/sys_metrics_processor.cpp b/lib/src/system/sys_metrics_processor.cc similarity index 99% rename from lib/src/system/sys_metrics_processor.cpp rename to lib/src/system/sys_metrics_processor.cc index ee7c8aa18..00a9b9291 100644 --- a/lib/src/system/sys_metrics_processor.cpp +++ b/lib/src/system/sys_metrics_processor.cc @@ -32,6 +32,10 @@ sys_metrics_processor::proc_stats_info::proc_stats_info() std::string line; { std::ifstream file("/proc/self/stat"); + if (!file) { + return; + } + std::getline(file, line); }