[metrics] Changing variable types.

Adjusting the license.
master
AlaiaL 4 years ago committed by Andre Puschmann
parent 13fdbd9e0f
commit 390a4c0f76

@ -1,36 +1,29 @@
/** /**
* Copyright 2013-2021 Software Radio Systems Limited
* *
* This file is part of srsLTE. * \section COPYRIGHT
* *
* srsLTE is free software: you can redistribute it and/or modify * Copyright 2013-2020 Software Radio Systems Limited
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* *
* srsLTE is distributed in the hope that it will be useful, * By using this file, you agree to the terms and conditions set
* but WITHOUT ANY WARRANTY; without even the implied warranty of * forth in the LICENSE file which can be found at the top level of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * the distribution.
* GNU Affero General Public License for more details.
*
* A copy of the GNU Affero General Public License can be found in
* the LICENSE file in the top-level directory of this distribution
* and at http://www.gnu.org/licenses/.
* *
*/ */
#ifndef SRSLTE_SYS_METRICS_H #ifndef SRSLTE_SYS_METRICS_H
#define SRSLTE_SYS_METRICS_H #define SRSLTE_SYS_METRICS_H
#include <cstdint>
namespace srslte { namespace srslte {
/// Metrics of cpu usage, memory consumption and number of thread used by the process. /// 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; uint32_t process_realmem_kB = 0;
unsigned process_virtualmem_kB = 0; uint32_t process_virtualmem_kB = 0;
float process_realmem = -1.f; float process_realmem = -1.f;
float process_virtualmem = -1.f; float process_virtualmem = -1.f;
unsigned thread_count = 0; uint32_t thread_count = 0;
float process_cpu_usage = -1.f; float process_cpu_usage = -1.f;
float system_mem = -1.f; float system_mem = -1.f;
}; };

@ -1,21 +1,12 @@
/** /**
* Copyright 2013-2021 Software Radio Systems Limited
* *
* This file is part of srsLTE. * \section COPYRIGHT
* *
* srsLTE is free software: you can redistribute it and/or modify * Copyright 2013-2020 Software Radio Systems Limited
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* *
* srsLTE is distributed in the hope that it will be useful, * By using this file, you agree to the terms and conditions set
* but WITHOUT ANY WARRANTY; without even the implied warranty of * forth in the LICENSE file which can be found at the top level of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * the distribution.
* GNU Affero General Public License for more details.
*
* A copy of the GNU Affero General Public License can be found in
* the LICENSE file in the top-level directory of this distribution
* and at http://www.gnu.org/licenses/.
* *
*/ */
@ -36,19 +27,18 @@ class sys_metrics_processor
proc_stats_info(); proc_stats_info();
// Initialize the variables that will be used. // Initialize the variables that will be used.
int long num_threads = 0; int32_t num_threads = 0;
unsigned long utime = 0; uint32_t utime = 0;
unsigned long stime = 0; uint32_t stime = 0;
// Rest of the information of the stats file. // Rest of the information of the stats file.
int pid, ppid, pgrp, session, tty_nr, tpgid, exit_signal, processor, exit_code; int32_t pid, ppid, pgrp, session, tty_nr, tpgid, exit_signal, processor, exit_code, cutime, cstime, priority, nice,
unsigned flags, rt_priority, policy; itrealvalue, rss, cguest_time;
unsigned long minflt, cminflt, majflt, cmajflt, vsize, rsslim, startcode, endcode, startstack, kstkesp, kstkeip, uint32_t minflt, cminflt, majflt, cmajflt, vsize, rsslim, startcode, endcode, startstack, kstkesp, kstkeip, signal,
signal, blocked, sigignore, sigcatch, wchan, nswap, cnswap, guest_time, start_data, end_data, start_brk, blocked, sigignore, sigcatch, wchan, nswap, cnswap, guest_time, start_data, end_data, start_brk, arg_start,
arg_start, arg_end, env_start, env_end; arg_end, env_start, env_end, flags, rt_priority, policy;
int long cutime, cstime, priority, nice, itrealvalue, rss, cguest_time; uint64_t starttime, delaycct_blkio_ticks;
unsigned long long starttime, delaycct_blkio_ticks; uint8_t state;
char state;
std::string comm; std::string comm;
}; };
@ -67,7 +57,7 @@ private:
void calculate_mem_usage(sys_metrics_t& metrics) const; void calculate_mem_usage(sys_metrics_t& metrics) const;
private: private:
proc_stats_info last_query; proc_stats_info last_query = {};
std::chrono::time_point<std::chrono::steady_clock> last_query_time = std::chrono::steady_clock::now(); std::chrono::time_point<std::chrono::steady_clock> last_query_time = std::chrono::steady_clock::now();
}; };

@ -1,28 +1,19 @@
/** /**
* Copyright 2013-2021 Software Radio Systems Limited
* *
* This file is part of srsLTE. * \section COPYRIGHT
* *
* srsLTE is free software: you can redistribute it and/or modify * Copyright 2013-2020 Software Radio Systems Limited
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* *
* srsLTE is distributed in the hope that it will be useful, * By using this file, you agree to the terms and conditions set
* but WITHOUT ANY WARRANTY; without even the implied warranty of * forth in the LICENSE file which can be found at the top level of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * the distribution.
* GNU Affero General Public License for more details.
*
* A copy of the GNU Affero General Public License can be found in
* the LICENSE file in the top-level directory of this distribution
* and at http://www.gnu.org/licenses/.
* *
*/ */
#include "srslte/system/sys_metrics_processor.h" #include "srslte/system/sys_metrics_processor.h"
#include "sys/sysinfo.h"
#include <fstream> #include <fstream>
#include <sstream> #include <sstream>
#include <sys/sysinfo.h>
#include <unistd.h> #include <unistd.h>
using namespace srslte; using namespace srslte;
@ -51,7 +42,7 @@ sys_metrics_processor::proc_stats_info::proc_stats_info()
sys_metrics_t sys_metrics_processor::get_metrics() sys_metrics_t sys_metrics_processor::get_metrics()
{ {
auto current_time = std::chrono::steady_clock::now(); auto current_time = std::chrono::steady_clock::now();
unsigned measure_interval_ms = uint32_t measure_interval_ms =
std::chrono::duration_cast<std::chrono::milliseconds>(current_time - last_query_time).count(); std::chrono::duration_cast<std::chrono::milliseconds>(current_time - last_query_time).count();
// The time elapsed between 2 measures must be greater that 100 milliseconds. // The time elapsed between 2 measures must be greater that 100 milliseconds.
@ -89,7 +80,7 @@ float sys_metrics_processor::calculate_cpu_usage(const proc_stats_info& current_
return 0.f; return 0.f;
} }
static const unsigned cpu_count = ::sysconf(_SC_NPROCESSORS_CONF); static const uint32_t cpu_count = ::sysconf(_SC_NPROCESSORS_CONF);
static const float ticks_per_second = ::sysconf(_SC_CLK_TCK); static const float ticks_per_second = ::sysconf(_SC_CLK_TCK);
return ((current_query.stime + current_query.utime) - (last_query.stime + last_query.utime)) * 100.f / return ((current_query.stime + current_query.utime) - (last_query.stime + last_query.utime)) * 100.f /
@ -97,11 +88,11 @@ float sys_metrics_processor::calculate_cpu_usage(const proc_stats_info& current_
} }
/// Extracts and returns the memory size from the given line. /// Extracts and returns the memory size from the given line.
static unsigned read_memory_value_from_line(const std::string& line) static uint32_t read_memory_value_from_line(const std::string& line)
{ {
std::istringstream reader(line); std::istringstream reader(line);
std::string label, unit; std::string label, unit;
unsigned value; uint32_t value;
reader >> label >> value >> unit; reader >> label >> value >> unit;
@ -130,12 +121,12 @@ static void calculate_percentage_memory(sys_metrics_t& metrics)
// Total system's memory is in the first line. // Total system's memory is in the first line.
std::getline(file, line); std::getline(file, line);
unsigned long long total_mem_kB = read_memory_value_from_line(line); uint32_t total_mem_kB = read_memory_value_from_line(line);
// System's available memory is in the third line. // System's available memory is in the third line.
std::getline(file, line); std::getline(file, line);
std::getline(file, line); std::getline(file, line);
unsigned long long available_mem_kB = read_memory_value_from_line(line); uint32_t available_mem_kB = read_memory_value_from_line(line);
// Calculate the metrics. // Calculate the metrics.
metrics.process_realmem = 100.f * (float(metrics.process_realmem_kB) / total_mem_kB); metrics.process_realmem = 100.f * (float(metrics.process_realmem_kB) / total_mem_kB);

Loading…
Cancel
Save