[metrics] Changed the extension from cpp to cc.

- Fix date of CMakeLists.txt.
- Initialization of the used variables in the cpu usage calculation.
This commit is contained in:
AlaiaL 2021-02-26 15:07:17 +01:00 committed by Andre Puschmann
parent 41cf15f5ad
commit 723c56051e
4 changed files with 17 additions and 7 deletions

View File

@ -24,7 +24,7 @@
namespace srslte { 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 { struct sys_metrics_t {
unsigned process_realmem_kB = 0; unsigned process_realmem_kB = 0;
unsigned process_virtualmem_kB = 0; unsigned process_virtualmem_kB = 0;

View File

@ -35,12 +35,18 @@ class sys_metrics_processor
struct proc_stats_info { struct proc_stats_info {
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; int pid, ppid, pgrp, session, tty_nr, tpgid, exit_signal, processor, exit_code;
unsigned flags, rt_priority, policy; unsigned flags, rt_priority, policy;
unsigned long minflt, cminflt, majflt, cmajflt, utime, stime, vsize, rsslim, startcode, endcode, startstack, unsigned long minflt, cminflt, majflt, cmajflt, vsize, rsslim, startcode, endcode, startstack, kstkesp, kstkeip,
kstkesp, kstkeip, signal, blocked, sigignore, sigcatch, wchan, nswap, cnswap, guest_time, start_data, end_data, signal, blocked, sigignore, sigcatch, wchan, nswap, cnswap, guest_time, start_data, end_data, start_brk,
start_brk, arg_start, arg_end, env_start, env_end; arg_start, arg_end, env_start, env_end;
int long cutime, cstime, priority, nice, num_threads, itrealvalue, rss, cguest_time; int long cutime, cstime, priority, nice, itrealvalue, rss, cguest_time;
unsigned long long starttime, delaycct_blkio_ticks; unsigned long long starttime, delaycct_blkio_ticks;
char state; char state;
std::string comm; std::string comm;

View File

@ -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 # 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 # forth in the LICENSE file which can be found at the top level of
@ -7,7 +7,7 @@
# #
set(SOURCES set(SOURCES
sys_metrics_processor.cpp) sys_metrics_processor.cc)
find_package(Threads REQUIRED) find_package(Threads REQUIRED)

View File

@ -32,6 +32,10 @@ sys_metrics_processor::proc_stats_info::proc_stats_info()
std::string line; std::string line;
{ {
std::ifstream file("/proc/self/stat"); std::ifstream file("/proc/self/stat");
if (!file) {
return;
}
std::getline(file, line); std::getline(file, line);
} }