From bbaebd1274026b6f11a83280772698e735dfd599 Mon Sep 17 00:00:00 2001 From: AlaiaL Date: Wed, 24 Mar 2021 09:59:02 +0100 Subject: [PATCH] Added a warning in the log when the cpu metrics are not registered due to the number cpu cores is greater than supported. --- lib/include/srsran/system/sys_metrics.h | 2 +- lib/include/srsran/system/sys_metrics_processor.h | 3 +++ lib/src/system/sys_metrics_processor.cc | 7 +++++++ srsenb/src/enb.cc | 2 +- srsue/src/ue.cc | 2 +- 5 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/include/srsran/system/sys_metrics.h b/lib/include/srsran/system/sys_metrics.h index 92cc33a4a..fb05aa2c3 100644 --- a/lib/include/srsran/system/sys_metrics.h +++ b/lib/include/srsran/system/sys_metrics.h @@ -17,7 +17,7 @@ namespace srsran { -constexpr uint32_t metrics_max_supported_cpu = 32; +constexpr uint32_t metrics_max_supported_cpu = 32u; /// Metrics of cpu usage, memory consumption and number of thread used by the process. struct sys_metrics_t { diff --git a/lib/include/srsran/system/sys_metrics_processor.h b/lib/include/srsran/system/sys_metrics_processor.h index 18a5890d8..1a819d222 100644 --- a/lib/include/srsran/system/sys_metrics_processor.h +++ b/lib/include/srsran/system/sys_metrics_processor.h @@ -13,6 +13,7 @@ #ifndef SRSRAN_SYS_METRICS_PROCESSOR_H #define SRSRAN_SYS_METRICS_PROCESSOR_H +#include "srsran/srslog/logger.h" #include "srsran/system/sys_metrics.h" #include #include @@ -55,6 +56,7 @@ class sys_metrics_processor }; public: + explicit sys_metrics_processor(srslog::basic_logger& log); /// Measures and returns the system metrics. sys_metrics_t get_metrics(); @@ -76,6 +78,7 @@ private: cpu_metrics_t read_cpu_idle_from_line(const std::string& line) const; private: + srslog::basic_logger& log; proc_stats_info last_query = {}; cpu_metrics_t last_cpu_thread[metrics_max_supported_cpu] = {}; std::chrono::time_point last_query_time = std::chrono::steady_clock::now(); diff --git a/lib/src/system/sys_metrics_processor.cc b/lib/src/system/sys_metrics_processor.cc index 052daa9a4..0660f270e 100644 --- a/lib/src/system/sys_metrics_processor.cc +++ b/lib/src/system/sys_metrics_processor.cc @@ -21,6 +21,13 @@ using namespace srsran; static const uint32_t cpu_count = ::sysconf(_SC_NPROCESSORS_CONF); static const float ticks_per_second = ::sysconf(_SC_CLK_TCK); +sys_metrics_processor::sys_metrics_processor(srslog::basic_logger& log) : log(log) +{ + if (cpu_count > metrics_max_supported_cpu) { + log.warning("Number of cpu is greater than supported. CPU metrics will be disabled."); + } +} + sys_metrics_processor::proc_stats_info::proc_stats_info() { std::string line; diff --git a/srsenb/src/enb.cc b/srsenb/src/enb.cc index b16cac867..4c903babd 100644 --- a/srsenb/src/enb.cc +++ b/srsenb/src/enb.cc @@ -23,7 +23,7 @@ namespace srsenb { enb::enb(srslog::sink& log_sink) : - started(false), log_sink(log_sink), enb_log(srslog::fetch_basic_logger("ENB", log_sink, false)) + started(false), log_sink(log_sink), enb_log(srslog::fetch_basic_logger("ENB", log_sink, false)), sys_proc(enb_log) { // print build info std::cout << std::endl << get_build_string() << std::endl << std::endl; diff --git a/srsue/src/ue.cc b/srsue/src/ue.cc index 94a4e344f..526a8ebda 100644 --- a/srsue/src/ue.cc +++ b/srsue/src/ue.cc @@ -29,7 +29,7 @@ using namespace srsran; namespace srsue { -ue::ue() : logger(srslog::fetch_basic_logger("UE", false)) +ue::ue() : logger(srslog::fetch_basic_logger("UE", false)), sys_proc(logger) { // print build info std::cout << std::endl << get_build_string() << std::endl << std::endl;