From 6bdeb2d6b60809f5475c20ef04da198dab6a9a8e Mon Sep 17 00:00:00 2001 From: Ismael Gomez Date: Tue, 5 Oct 2021 14:56:40 +0200 Subject: [PATCH] Fix division by zero in JSON metrics --- srsenb/src/metrics_json.cc | 4 ++-- srsue/src/metrics_json.cc | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/srsenb/src/metrics_json.cc b/srsenb/src/metrics_json.cc index b88027534..2e2505a48 100644 --- a/srsenb/src/metrics_json.cc +++ b/srsenb/src/metrics_json.cc @@ -90,7 +90,7 @@ static void fill_ue_metrics(mset_ue_container& ue, const enb_metrics_t& m, unsig if (!std::isnan(m.phy[i].dl.mcs)) { ue.write(std::max(0.1f, m.phy[i].dl.mcs)); } - if (m.stack.mac.ues[i].tx_brate > 0) { + if (m.stack.mac.ues[i].tx_brate > 0 && m.stack.mac.ues[i].nof_tti > 0) { ue.write( std::max(0.1f, (float)m.stack.mac.ues[i].tx_brate / (m.stack.mac.ues[i].nof_tti * 0.001f))); } @@ -103,7 +103,7 @@ static void fill_ue_metrics(mset_ue_container& ue, const enb_metrics_t& m, unsig if (!std::isnan(m.phy[i].ul.mcs)) { ue.write(std::max(0.1f, m.phy[i].ul.mcs)); } - if (m.stack.mac.ues[i].rx_brate > 0) { + if (m.stack.mac.ues[i].rx_brate > 0 && m.stack.mac.ues[i].nof_tti > 0) { ue.write( std::max(0.1f, (float)m.stack.mac.ues[i].rx_brate / (m.stack.mac.ues[i].nof_tti * 0.001f))); } diff --git a/srsue/src/metrics_json.cc b/srsue/src/metrics_json.cc index e51ba7a38..fb89ece58 100644 --- a/srsue/src/metrics_json.cc +++ b/srsue/src/metrics_json.cc @@ -153,6 +153,10 @@ void metrics_json::set_metrics(const ue_metrics_t& metrics, const uint32_t perio auto& carrier_list = ctx.get(); carrier_list.resize(metrics.phy.nof_active_cc); for (uint32_t i = 0, e = carrier_list.size(); i != e; ++i) { + if (metrics.stack.mac[i].nof_tti == 0) { + continue; + } + auto& carrier = carrier_list[i]; // PHY.