diff --git a/lib/include/srsran/system/sys_metrics.h b/lib/include/srsran/system/sys_metrics.h index 890e9c9d7..92cc33a4a 100644 --- a/lib/include/srsran/system/sys_metrics.h +++ b/lib/include/srsran/system/sys_metrics.h @@ -17,6 +17,8 @@ namespace srsran { +constexpr uint32_t metrics_max_supported_cpu = 32; + /// Metrics of cpu usage, memory consumption and number of thread used by the process. struct sys_metrics_t { uint32_t process_realmem_kB = 0; @@ -26,7 +28,7 @@ struct sys_metrics_t { float process_cpu_usage = 0.f; float system_mem = 0.f; uint32_t cpu_count = 0; - float cpu_load[128]; + float cpu_load[metrics_max_supported_cpu]; }; } // namespace srsran diff --git a/lib/include/srsran/system/sys_metrics_processor.h b/lib/include/srsran/system/sys_metrics_processor.h index 7da5c9af5..18a5890d8 100644 --- a/lib/include/srsran/system/sys_metrics_processor.h +++ b/lib/include/srsran/system/sys_metrics_processor.h @@ -76,9 +76,9 @@ private: cpu_metrics_t read_cpu_idle_from_line(const std::string& line) const; private: - proc_stats_info last_query = {}; - cpu_metrics_t last_cpu_thread[128] = {}; - std::chrono::time_point last_query_time = std::chrono::steady_clock::now(); + 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(); }; } // namespace srsran diff --git a/lib/src/system/sys_metrics_processor.cc b/lib/src/system/sys_metrics_processor.cc index 4dbf3f39f..052daa9a4 100644 --- a/lib/src/system/sys_metrics_processor.cc +++ b/lib/src/system/sys_metrics_processor.cc @@ -102,6 +102,11 @@ sys_metrics_processor::cpu_metrics_t sys_metrics_processor::read_cpu_idle_from_l void sys_metrics_processor::calculate_cpu_metrics(sys_metrics_t& metrics, float delta_time_in_seconds) { + // When the number of cpu is higher than system_metrics_t supports, skip the cpu metrics. + if (cpu_count > metrics_max_supported_cpu) { + return; + } + metrics.cpu_count = cpu_count; std::ifstream file("/proc/stat"); diff --git a/srsenb/src/metrics_csv.cc b/srsenb/src/metrics_csv.cc index 34ffd0ac7..779eb8d22 100644 --- a/srsenb/src/metrics_csv.cc +++ b/srsenb/src/metrics_csv.cc @@ -58,8 +58,8 @@ void metrics_csv::set_metrics(const enb_metrics_t& metrics, const uint32_t perio file << "time;nof_ue;dl_brate;ul_brate;" "proc_rmem;proc_rmem_kB;proc_vmem_kB;sys_mem;system_load;thread_count"; - // Add the cores. - for (uint32_t i = 0, e = ::sysconf(_SC_NPROCESSORS_CONF); i != e; ++i) { + // Add the cpus + for (uint32_t i = 0, e = metrics.sys.cpu_count; i != e; ++i) { file << ";cpu_" << std::to_string(i); } diff --git a/srsue/src/metrics_csv.cc b/srsue/src/metrics_csv.cc index 666fd4981..7474355ab 100644 --- a/srsue/src/metrics_csv.cc +++ b/srsue/src/metrics_csv.cc @@ -81,7 +81,7 @@ void metrics_csv::set_metrics(const ue_metrics_t& metrics, const uint32_t period "proc_rmem;proc_rmem_kB;proc_vmem_kB;sys_mem;sys_load;thread_count"; // Add the cores. - for (uint32_t i = 0, e = ::sysconf(_SC_NPROCESSORS_CONF); i != e; ++i) { + for (uint32_t i = 0, e = metrics.sys.cpu_count; i != e; ++i) { file << ";cpu_" << std::to_string(i); }