From 43ec714ce158ce5959ce1657f32312b7e6205b12 Mon Sep 17 00:00:00 2001 From: David Rupprecht Date: Wed, 7 Apr 2021 21:03:19 +0200 Subject: [PATCH] Added functionality for printing nr metrics --- srsue/hdr/metrics_csv.h | 8 ++ srsue/hdr/metrics_stdout.h | 12 +- srsue/hdr/ue_metrics_interface.h | 3 + srsue/src/metrics_csv.cc | 201 ++++++++++++++++++------------- srsue/src/metrics_stdout.cc | 109 +++++++++-------- srsue/test/metrics_test.cc | 8 ++ 6 files changed, 203 insertions(+), 138 deletions(-) diff --git a/srsue/hdr/metrics_csv.h b/srsue/hdr/metrics_csv.h index d00aa5b5d..f2d8ec729 100644 --- a/srsue/hdr/metrics_csv.h +++ b/srsue/hdr/metrics_csv.h @@ -42,6 +42,14 @@ public: void stop(); private: + void set_metrics_helper(const srsran::rf_metrics_t rf, + const srsran::sys_metrics_t sys, + const phy_metrics_t phy, + const mac_metrics_t mac[SRSRAN_MAX_CARRIERS], + const rrc_metrics_t rrc, + const uint32_t cc, + const uint32_t r); + std::string float_to_string(float f, int digits, bool add_semicolon = true); std::ofstream file; diff --git a/srsue/hdr/metrics_stdout.h b/srsue/hdr/metrics_stdout.h index 085f2ddfc..95285a64b 100644 --- a/srsue/hdr/metrics_stdout.h +++ b/srsue/hdr/metrics_stdout.h @@ -39,10 +39,14 @@ public: private: static const bool FORCE_NEIGHBOUR_CELL = false; // Set to true for printing always neighbour cells - - std::string float_to_string(float f, int digits); - std::string float_to_eng_string(float f, int digits); - void print_table(const bool display_neighbours); + void set_metrics_helper(const phy_metrics_t phy, + const mac_metrics_t mac[SRSRAN_MAX_CARRIERS], + const rrc_metrics_t rrc, + bool display_neighbours, + const uint32_t r); + std::string float_to_string(float f, int digits); + std::string float_to_eng_string(float f, int digits); + void print_table(const bool display_neighbours); bool do_print = false; bool table_has_neighbours = false; ///< state of last table head diff --git a/srsue/hdr/ue_metrics_interface.h b/srsue/hdr/ue_metrics_interface.h index 725cbcb51..43bca5f5f 100644 --- a/srsue/hdr/ue_metrics_interface.h +++ b/srsue/hdr/ue_metrics_interface.h @@ -30,14 +30,17 @@ namespace srsue { typedef struct { uint32_t ul_dropped_sdus; mac_metrics_t mac[SRSRAN_MAX_CARRIERS]; + mac_metrics_t mac_nr[SRSRAN_MAX_CARRIERS]; srsran::rlc_metrics_t rlc; nas_metrics_t nas; rrc_metrics_t rrc; + rrc_metrics_t rrc_nr; } stack_metrics_t; typedef struct { srsran::rf_metrics_t rf; phy_metrics_t phy; + phy_metrics_t phy_nr; gw_metrics_t gw; stack_metrics_t stack; srsran::sys_metrics_t sys; diff --git a/srsue/src/metrics_csv.cc b/srsue/src/metrics_csv.cc index 7474355ab..8fb000b21 100644 --- a/srsue/src/metrics_csv.cc +++ b/srsue/src/metrics_csv.cc @@ -65,6 +65,108 @@ void metrics_csv::stop() } } +void metrics_csv::set_metrics_helper(const srsran::rf_metrics_t rf, + const srsran::sys_metrics_t sys, + const phy_metrics_t phy, + const mac_metrics_t mac[SRSRAN_MAX_CARRIERS], + const rrc_metrics_t rrc, + const uint32_t cc, + const uint32_t r) +{ + if (not file.is_open()) { + return; + } + + file << time_ms << ";"; + + // CC and PCI + file << cc << ";"; + file << phy.info[r].dl_earfcn << ";"; + file << phy.info[r].pci << ";"; + + // Print PHY metrics for first CC + file << float_to_string(phy.ch[r].rsrp, 2); + file << float_to_string(phy.ch[r].pathloss, 2); + file << float_to_string(phy.sync[r].cfo, 2); + + // Find strongest neighbour for this EARFCN (cells are ordered) + bool has_neighbour = false; + for (auto& c : rrc.neighbour_cells) { + if (c.earfcn == phy.info[r].dl_earfcn && c.pci != phy.info[r].pci) { + file << c.pci << ";"; + file << float_to_string(c.rsrp, 2); + file << float_to_string(c.cfo_hz, 2); + has_neighbour = true; + break; + } + } + if (!has_neighbour) { + file << "n/a;"; + file << "n/a;"; + file << "n/a;"; + } + + file << float_to_string(phy.dl[r].mcs, 2); + file << float_to_string(phy.ch[r].sinr, 2); + file << float_to_string(phy.dl[r].turbo_iters, 2); + + if (mac[r].rx_brate > 0) { + file << float_to_string(mac[r].rx_brate / (mac[r].nof_tti * 1e-3), 2); + } else { + file << float_to_string(0, 2); + } + + int rx_pkts = mac[r].rx_pkts; + int rx_errors = mac[r].rx_errors; + if (rx_pkts > 0) { + file << float_to_string((float)100 * rx_errors / rx_pkts, 1); + } else { + file << float_to_string(0, 2); + } + + file << float_to_string(phy.sync[r].ta_us, 2); + file << float_to_string(phy.sync[r].distance_km, 2); + file << float_to_string(phy.sync[r].speed_kmph, 2); + file << float_to_string(phy.ul[r].mcs, 2); + file << float_to_string((float)mac[r].ul_buffer, 2); + + if (mac[r].tx_brate > 0) { + file << float_to_string(mac[r].tx_brate / (mac[r].nof_tti * 1e-3), 2); + } else { + file << float_to_string(0, 2); + } + + // Sum UL BLER for all CCs + int tx_pkts = mac[r].tx_pkts; + int tx_errors = mac[r].tx_errors; + if (tx_pkts > 0) { + file << float_to_string((float)100 * tx_errors / tx_pkts, 1); + } else { + file << float_to_string(0, 2); + } + + file << float_to_string(rf.rf_o, 2); + file << float_to_string(rf.rf_u, 2); + file << float_to_string(rf.rf_l, 2); + file << (rrc.state == RRC_STATE_CONNECTED ? "1.0" : "0.0") << ";"; + + // Write system metrics. + const srsran::sys_metrics_t& m = sys; + file << float_to_string(m.process_realmem, 2); + file << std::to_string(m.process_realmem_kB) << ";"; + file << std::to_string(m.process_virtualmem_kB) << ";"; + file << float_to_string(m.system_mem, 2); + file << float_to_string(m.process_cpu_usage, 2); + file << std::to_string(m.thread_count) << ";"; + + // Write the cpu metrics. + for (uint32_t i = 0, e = m.cpu_count, last_cpu_index = e - 1; i != e; ++i) { + file << float_to_string(m.cpu_load[i], 2, (i != last_cpu_index)); + } + + file << "\n"; +} + void metrics_csv::set_metrics(const ue_metrics_t& metrics, const uint32_t period_usec) { std::unique_lock lock(mutex); @@ -89,95 +191,20 @@ void metrics_csv::set_metrics(const ue_metrics_t& metrics, const uint32_t period file << "\n"; } + // Metrics for LTE carrier for (uint32_t r = 0; r < metrics.phy.nof_active_cc; r++) { - file << time_ms << ";"; - - // CC and PCI - file << r << ";"; - file << metrics.phy.info[r].dl_earfcn << ";"; - file << metrics.phy.info[r].pci << ";"; - - // Print PHY metrics for first CC - file << float_to_string(metrics.phy.ch[r].rsrp, 2); - file << float_to_string(metrics.phy.ch[r].pathloss, 2); - file << float_to_string(metrics.phy.sync[r].cfo, 2); - - // Find strongest neighbour for this EARFCN (cells are ordered) - bool has_neighbour = false; - for (auto& c : metrics.stack.rrc.neighbour_cells) { - if (c.earfcn == metrics.phy.info[r].dl_earfcn && c.pci != metrics.phy.info[r].pci) { - file << c.pci << ";"; - file << float_to_string(c.rsrp, 2); - file << float_to_string(c.cfo_hz, 2); - has_neighbour = true; - break; - } - } - if (!has_neighbour) { - file << "n/a;"; - file << "n/a;"; - file << "n/a;"; - } - - file << float_to_string(metrics.phy.dl[r].mcs, 2); - file << float_to_string(metrics.phy.ch[r].sinr, 2); - file << float_to_string(metrics.phy.dl[r].turbo_iters, 2); - - if (metrics.stack.mac[r].rx_brate > 0) { - file << float_to_string(metrics.stack.mac[r].rx_brate / (metrics.stack.mac[r].nof_tti * 1e-3), 2); - } else { - file << float_to_string(0, 2); - } - - int rx_pkts = metrics.stack.mac[r].rx_pkts; - int rx_errors = metrics.stack.mac[r].rx_errors; - if (rx_pkts > 0) { - file << float_to_string((float)100 * rx_errors / rx_pkts, 1); - } else { - file << float_to_string(0, 2); - } - - file << float_to_string(metrics.phy.sync[r].ta_us, 2); - file << float_to_string(metrics.phy.sync[r].distance_km, 2); - file << float_to_string(metrics.phy.sync[r].speed_kmph, 2); - file << float_to_string(metrics.phy.ul[r].mcs, 2); - file << float_to_string((float)metrics.stack.mac[r].ul_buffer, 2); - - if (metrics.stack.mac[r].tx_brate > 0) { - file << float_to_string(metrics.stack.mac[r].tx_brate / (metrics.stack.mac[r].nof_tti * 1e-3), 2); - } else { - file << float_to_string(0, 2); - } - - // Sum UL BLER for all CCs - int tx_pkts = metrics.stack.mac[r].tx_pkts; - int tx_errors = metrics.stack.mac[r].tx_errors; - if (tx_pkts > 0) { - file << float_to_string((float)100 * tx_errors / tx_pkts, 1); - } else { - file << float_to_string(0, 2); - } - - file << float_to_string(metrics.rf.rf_o, 2); - file << float_to_string(metrics.rf.rf_u, 2); - file << float_to_string(metrics.rf.rf_l, 2); - file << (metrics.stack.rrc.state == RRC_STATE_CONNECTED ? "1.0" : "0.0") << ";"; - - // Write system metrics. - const srsran::sys_metrics_t& m = metrics.sys; - file << float_to_string(m.process_realmem, 2); - file << std::to_string(m.process_realmem_kB) << ";"; - file << std::to_string(m.process_virtualmem_kB) << ";"; - file << float_to_string(m.system_mem, 2); - file << float_to_string(m.process_cpu_usage, 2); - file << std::to_string(m.thread_count) << ";"; - - // Write the cpu metrics. - for (uint32_t i = 0, e = m.cpu_count, last_cpu_index = e - 1; i != e; ++i) { - file << float_to_string(m.cpu_load[i], 2, (i != last_cpu_index)); - } + set_metrics_helper(metrics.rf, metrics.sys, metrics.phy, metrics.stack.mac, metrics.stack.rrc, r, r); + } - file << "\n"; + // Metrics for NR carrier + for (uint32_t r = 0; r < metrics.phy_nr.nof_active_cc; r++) { + set_metrics_helper(metrics.rf, + metrics.sys, + metrics.phy_nr, + metrics.stack.mac_nr, + metrics.stack.rrc, + r, + metrics.phy.nof_active_cc + r); } n_reports++; diff --git a/srsue/src/metrics_stdout.cc b/srsue/src/metrics_stdout.cc index 953d3d066..f504be62b 100644 --- a/srsue/src/metrics_stdout.cc +++ b/srsue/src/metrics_stdout.cc @@ -76,6 +76,62 @@ void metrics_stdout::print_table(const bool display_neighbours) n_reports = 0; } +void metrics_stdout::set_metrics_helper(const phy_metrics_t phy, + const mac_metrics_t mac[SRSRAN_MAX_CARRIERS], + const rrc_metrics_t rrc, + bool display_neighbours, + const uint32_t r) +{ + if (phy.info[r].pci != UINT32_MAX) { + cout << std::setw(4) << phy.info[r].pci << std::setw(0); + } else { + cout << " n/a"; + } + cout << float_to_string(phy.ch[r].rsrp, 2); + cout << float_to_string(phy.ch[r].pathloss, 2); + cout << float_to_eng_string(phy.sync[r].cfo, 2); + + // Find strongest neighbour for this EARFCN (cells are ordered) + if (display_neighbours) { + bool has_neighbour = false; + for (auto& c : rrc.neighbour_cells) { + if (c.earfcn == phy.info[r].dl_earfcn && c.pci != phy.info[r].pci) { + cout << std::setw(4) << c.pci << std::setw(0); + cout << float_to_string(c.rsrp, 2); + has_neighbour = true; + break; + } + } + if (!has_neighbour) { + cout << " n/a"; + cout << " n/a"; + } + } + + cout << float_to_string(phy.dl[r].mcs, 2); + cout << float_to_string(phy.ch[r].sinr, 2); + cout << float_to_string(phy.dl[r].turbo_iters, 2); + + cout << float_to_eng_string((float)mac[r].rx_brate / (mac[r].nof_tti * 1e-3), 2); + if (mac[r].rx_pkts > 0) { + cout << float_to_string((float)100 * mac[r].rx_errors / mac[r].rx_pkts, 1) << "%"; + } else { + cout << float_to_string(0, 1) << "%"; + } + + cout << float_to_string(phy.sync[r].ta_us, 2); + + cout << float_to_string(phy.ul[r].mcs, 2); + cout << float_to_eng_string((float)mac[r].ul_buffer, 2); + cout << float_to_eng_string((float)mac[r].tx_brate / (mac[r].nof_tti * 1e-3), 2); + if (mac[r].tx_pkts > 0) { + cout << float_to_string((float)100 * mac[r].tx_errors / mac[r].tx_pkts, 1) << "%"; + } else { + cout << float_to_string(0, 1) << "%"; + } + cout << endl; +} + void metrics_stdout::set_metrics(const ue_metrics_t& metrics, const uint32_t period_usec) { if (ue == nullptr) { @@ -115,54 +171,13 @@ void metrics_stdout::set_metrics(const ue_metrics_t& metrics, const uint32_t per for (uint32_t r = 0; r < metrics.phy.nof_active_cc; r++) { cout << std::setw(2) << r; - if (metrics.phy.info[r].pci != UINT32_MAX) { - cout << std::setw(4) << metrics.phy.info[r].pci << std::setw(0); - } else { - cout << " n/a"; - } - cout << float_to_string(metrics.phy.ch[r].rsrp, 2); - cout << float_to_string(metrics.phy.ch[r].pathloss, 2); - cout << float_to_eng_string(metrics.phy.sync[r].cfo, 2); - - // Find strongest neighbour for this EARFCN (cells are ordered) - if (display_neighbours) { - bool has_neighbour = false; - for (auto& c : metrics.stack.rrc.neighbour_cells) { - if (c.earfcn == metrics.phy.info[r].dl_earfcn && c.pci != metrics.phy.info[r].pci) { - cout << std::setw(4) << c.pci << std::setw(0); - cout << float_to_string(c.rsrp, 2); - has_neighbour = true; - break; - } - } - if (!has_neighbour) { - cout << " n/a"; - cout << " n/a"; - } - } - - cout << float_to_string(metrics.phy.dl[r].mcs, 2); - cout << float_to_string(metrics.phy.ch[r].sinr, 2); - cout << float_to_string(metrics.phy.dl[r].turbo_iters, 2); - - cout << float_to_eng_string((float)metrics.stack.mac[r].rx_brate / (metrics.stack.mac[r].nof_tti * 1e-3), 2); - if (metrics.stack.mac[r].rx_pkts > 0) { - cout << float_to_string((float)100 * metrics.stack.mac[r].rx_errors / metrics.stack.mac[r].rx_pkts, 1) << "%"; - } else { - cout << float_to_string(0, 1) << "%"; - } - - cout << float_to_string(metrics.phy.sync[r].ta_us, 2); + set_metrics_helper(metrics.phy, metrics.stack.mac, metrics.stack.rrc, display_neighbours, r); + } - cout << float_to_string(metrics.phy.ul[r].mcs, 2); - cout << float_to_eng_string((float)metrics.stack.mac[r].ul_buffer, 2); - cout << float_to_eng_string((float)metrics.stack.mac[r].tx_brate / (metrics.stack.mac[r].nof_tti * 1e-3), 2); - if (metrics.stack.mac[r].tx_pkts > 0) { - cout << float_to_string((float)100 * metrics.stack.mac[r].tx_errors / metrics.stack.mac[r].tx_pkts, 1) << "%"; - } else { - cout << float_to_string(0, 1) << "%"; - } - cout << endl; + for (uint32_t r = 0; r < metrics.phy_nr.nof_active_cc; r++) { + // Assumption LTE is followed by the NR carriers. + cout << std::setw(2) << metrics.phy.nof_active_cc + r; + set_metrics_helper(metrics.phy_nr, metrics.stack.mac_nr, metrics.stack.rrc, display_neighbours, r); } if (metrics.rf.rf_error) { diff --git a/srsue/test/metrics_test.cc b/srsue/test/metrics_test.cc index fad64c1a2..f1308b047 100644 --- a/srsue/test/metrics_test.cc +++ b/srsue/test/metrics_test.cc @@ -60,6 +60,14 @@ public: m->stack.rrc.neighbour_cells.push_back(neighbor); // need to add twice since we use CA } + m->phy_nr.nof_active_cc = 1; + m->phy_nr.ch[0].rsrp = -10.0f; + m->phy_nr.ch[0].pathloss = 32; + m->stack.mac_nr[0].rx_pkts = 100; + m->stack.mac_nr[0].rx_errors = 2; + m->stack.mac_nr[0].rx_brate = 223; + m->stack.mac_nr[0].nof_tti = 1; + m->stack.rrc.state = (rand() % 2 == 0) ? RRC_STATE_CONNECTED : RRC_STATE_IDLE; return true;