[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
* 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.
* Copyright 2013-2020 Software Radio Systems Limited
*
* srsLTE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* 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/.
* 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
* the distribution.
*
*/
#ifndef SRSLTE_SYS_METRICS_H
#define SRSLTE_SYS_METRICS_H
#include <cstdint>
namespace srslte {
/// 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;
uint32_t process_realmem_kB = 0;
uint32_t process_virtualmem_kB = 0;
float process_realmem = -1.f;
float process_virtualmem = -1.f;
unsigned thread_count = 0;
uint32_t thread_count = 0;
float process_cpu_usage = -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
* 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.
* Copyright 2013-2020 Software Radio Systems Limited
*
* srsLTE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* 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/.
* 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
* the distribution.
*
*/
@ -36,20 +27,19 @@ class sys_metrics_processor
proc_stats_info();
// Initialize the variables that will be used.
int long num_threads = 0;
unsigned long utime = 0;
unsigned long stime = 0;
int32_t num_threads = 0;
uint32_t utime = 0;
uint32_t 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, 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;
int32_t pid, ppid, pgrp, session, tty_nr, tpgid, exit_signal, processor, exit_code, cutime, cstime, priority, nice,
itrealvalue, rss, cguest_time;
uint32_t 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, flags, rt_priority, policy;
uint64_t starttime, delaycct_blkio_ticks;
uint8_t state;
std::string comm;
};
public:
@ -67,7 +57,7 @@ private:
void calculate_mem_usage(sys_metrics_t& metrics) const;
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();
};

@ -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
* 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.
* Copyright 2013-2020 Software Radio Systems Limited
*
* srsLTE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* 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/.
* 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
* the distribution.
*
*/
#include "srslte/system/sys_metrics_processor.h"
#include "sys/sysinfo.h"
#include <fstream>
#include <sstream>
#include <sys/sysinfo.h>
#include <unistd.h>
using namespace srslte;
@ -51,7 +42,7 @@ sys_metrics_processor::proc_stats_info::proc_stats_info()
sys_metrics_t sys_metrics_processor::get_metrics()
{
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();
// 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;
}
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);
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.
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::string label, unit;
unsigned value;
uint32_t value;
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.
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.
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.
metrics.process_realmem = 100.f * (float(metrics.process_realmem_kB) / total_mem_kB);

Loading…
Cancel
Save