- Deleted the magic number of maximum supported cores, now it is a

constexpr.
- When the system has more cores that the maximum supported, the cpu
metrics will not be registered.
master
AlaiaL 4 years ago committed by AlaiaL
parent 6cd9bba641
commit c9d1c77e8c

@ -17,6 +17,8 @@
namespace srsran { namespace srsran {
constexpr uint32_t metrics_max_supported_cpu = 32;
/// 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 {
uint32_t process_realmem_kB = 0; uint32_t process_realmem_kB = 0;
@ -26,7 +28,7 @@ struct sys_metrics_t {
float process_cpu_usage = 0.f; float process_cpu_usage = 0.f;
float system_mem = 0.f; float system_mem = 0.f;
uint32_t cpu_count = 0; uint32_t cpu_count = 0;
float cpu_load[128]; float cpu_load[metrics_max_supported_cpu];
}; };
} // namespace srsran } // namespace srsran

@ -77,7 +77,7 @@ private:
private: private:
proc_stats_info last_query = {}; proc_stats_info last_query = {};
cpu_metrics_t last_cpu_thread[128] = {}; cpu_metrics_t last_cpu_thread[metrics_max_supported_cpu] = {};
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();
}; };

@ -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) 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; metrics.cpu_count = cpu_count;
std::ifstream file("/proc/stat"); std::ifstream file("/proc/stat");

@ -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;" file << "time;nof_ue;dl_brate;ul_brate;"
"proc_rmem;proc_rmem_kB;proc_vmem_kB;sys_mem;system_load;thread_count"; "proc_rmem;proc_rmem_kB;proc_vmem_kB;sys_mem;system_load;thread_count";
// Add the cores. // Add the cpus
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); file << ";cpu_" << std::to_string(i);
} }

@ -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"; "proc_rmem;proc_rmem_kB;proc_vmem_kB;sys_mem;sys_load;thread_count";
// Add the cores. // 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); file << ";cpu_" << std::to_string(i);
} }

Loading…
Cancel
Save