You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
srsRAN_4G/srsenb/src/metrics_stdout.cc

218 lines
6.2 KiB
C++

/**
*
* \section COPYRIGHT
*
* Copyright 2013-2021 Software Radio Systems Limited
*
* By using this file, you agree to the terms and conditions set
* forth in the LICENSE file which can be found at the top level of
* the distribution.
*
*/
#include "srsenb/hdr/metrics_stdout.h"
#include "srsran/phy/utils/vector.h"
#include <float.h>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <sstream>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
using namespace std;
namespace srsenb {
char const* const prefixes[2][9] = {
{
"",
"m",
"u",
"n",
"p",
"f",
"a",
"z",
"y",
},
{
"",
"k",
"M",
"G",
"T",
"P",
"E",
"Z",
"Y",
},
};
metrics_stdout::metrics_stdout() : do_print(false), n_reports(10), enb(NULL) {}
void metrics_stdout::set_handle(enb_metrics_interface* enb_)
{
enb = enb_;
}
void metrics_stdout::toggle_print(bool b)
{
do_print = b;
}
void metrics_stdout::set_metrics(const enb_metrics_t& metrics, const uint32_t period_usec)
{
if (!do_print || enb == nullptr) {
return;
}
if (metrics.rf.rf_error) {
printf("RF status: O=%d, U=%d, L=%d\n", metrics.rf.rf_o, metrics.rf.rf_u, metrics.rf.rf_l);
}
if (metrics.stack.rrc.ues.size() == 0) {
return;
}
std::ios::fmtflags f(cout.flags()); // For avoiding Coverity defect: Not restoring ostream format
if (++n_reports > 10) {
n_reports = 0;
cout << endl;
cout << "------DL-------------------------------UL--------------------------------------------" << endl;
cout << "rnti cqi ri mcs brate ok nok (%) pusch pucch phr mcs brate ok nok (%) bsr" << endl;
}
for (size_t i = 0; i < metrics.stack.rrc.ues.size(); i++) {
enb: fix potential invalid access in stdout metrics this fixes a potential access of invalid PHY or MAC metrics by checking the user entry actually exists. the RFCI has shown this error: ------DL--------------------------------UL------------------------------------ rnti cqi ri mcs brate ok nok (%) snr phr mcs brate ok nok (%) bsr ASAN:DEADLYSIGNAL ================================================================= m==31838==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x555d482b6893 bp 0x7f6ac32d1160 sp 0x7f6ac32d0bc0 T21) ==31838==The signal is caused by a READ memory access. ==31838==Hint: address points to the zero page. #0 0x555d482b6892 in srsenb::metrics_stdout::set_metrics(srsenb::enb_metrics_t const&, unsigned int) /mnt/data/jenkins/workspace/srslte_dev_ogt_zmq_nightly/srsLTE/srsenb/src/metrics_stdout.cc:101 #1 0x555d482865f1 in srslte::metrics_hub<srsenb::enb_metrics_t>::run_period() /mnt/data/jenkins/workspace/srslte_dev_ogt_zmq_nightly/srsLTE/lib/include/srslte/common/metrics_hub.h:88 #2 0x555d482865f1 in srslte::periodic_thread::run_thread() /mnt/data/jenkins/workspace/srslte_dev_ogt_zmq_nightly/srsLTE/lib/include/srslte/common/threads.h:143 #3 0x555d4826813d in srslte::thread::thread_function_entry(void*) /mnt/data/jenkins/workspace/srslte_dev_ogt_zmq_nightly/srsLTE/lib/include/srslte/common/threads.h:102 #4 0x7f6b0dc546da in start_thread (/lib/x86_64-linux-gnu/libpthread.so.0+0x76da) #5 0x7f6b0bf0171e in __clone (/lib/x86_64-linux-gnu/libc.so.6+0x12171e)
4 years ago
// make sure we have stats for MAC and PHY layer too
if (i >= metrics.stack.mac.ues.size() || i >= metrics.phy.size()) {
enb: fix potential invalid access in stdout metrics this fixes a potential access of invalid PHY or MAC metrics by checking the user entry actually exists. the RFCI has shown this error: ------DL--------------------------------UL------------------------------------ rnti cqi ri mcs brate ok nok (%) snr phr mcs brate ok nok (%) bsr ASAN:DEADLYSIGNAL ================================================================= m==31838==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x555d482b6893 bp 0x7f6ac32d1160 sp 0x7f6ac32d0bc0 T21) ==31838==The signal is caused by a READ memory access. ==31838==Hint: address points to the zero page. #0 0x555d482b6892 in srsenb::metrics_stdout::set_metrics(srsenb::enb_metrics_t const&, unsigned int) /mnt/data/jenkins/workspace/srslte_dev_ogt_zmq_nightly/srsLTE/srsenb/src/metrics_stdout.cc:101 #1 0x555d482865f1 in srslte::metrics_hub<srsenb::enb_metrics_t>::run_period() /mnt/data/jenkins/workspace/srslte_dev_ogt_zmq_nightly/srsLTE/lib/include/srslte/common/metrics_hub.h:88 #2 0x555d482865f1 in srslte::periodic_thread::run_thread() /mnt/data/jenkins/workspace/srslte_dev_ogt_zmq_nightly/srsLTE/lib/include/srslte/common/threads.h:143 #3 0x555d4826813d in srslte::thread::thread_function_entry(void*) /mnt/data/jenkins/workspace/srslte_dev_ogt_zmq_nightly/srsLTE/lib/include/srslte/common/threads.h:102 #4 0x7f6b0dc546da in start_thread (/lib/x86_64-linux-gnu/libpthread.so.0+0x76da) #5 0x7f6b0bf0171e in __clone (/lib/x86_64-linux-gnu/libc.so.6+0x12171e)
4 years ago
break;
}
if (metrics.stack.mac.ues[i].tx_errors > metrics.stack.mac.ues[i].tx_pkts) {
printf("tx caution errors %d > %d\n", metrics.stack.mac.ues[i].tx_errors, metrics.stack.mac.ues[i].tx_pkts);
}
if (metrics.stack.mac.ues[i].rx_errors > metrics.stack.mac.ues[i].rx_pkts) {
printf("rx caution errors %d > %d\n", metrics.stack.mac.ues[i].rx_errors, metrics.stack.mac.ues[i].rx_pkts);
}
cout << int_to_hex_string(metrics.stack.mac.ues[i].rnti, 4) << " ";
if (not iszero(metrics.stack.mac.ues[i].dl_cqi)) {
cout << float_to_string(metrics.stack.mac.ues[i].dl_cqi, 1, 3);
} else {
cout << "n/a";
}
cout << float_to_string(metrics.stack.mac.ues[i].dl_ri, 1, 4);
if (not isnan(metrics.phy[i].dl.mcs)) {
cout << float_to_string(metrics.phy[i].dl.mcs, 1, 4);
} else {
cout << float_to_string(0, 2, 4);
}
if (metrics.stack.mac.ues[i].tx_brate > 0) {
cout << float_to_eng_string((float)metrics.stack.mac.ues[i].tx_brate / (metrics.stack.mac.ues[i].nof_tti * 1e-3), 1);
} else {
cout << float_to_string(0, 1, 6) << "";
}
cout << std::setw(5) << metrics.stack.mac.ues[i].tx_pkts - metrics.stack.mac.ues[i].tx_errors;
cout << std::setw(5) << metrics.stack.mac.ues[i].tx_errors;
if (metrics.stack.mac.ues[i].tx_pkts > 0 && metrics.stack.mac.ues[i].tx_errors) {
cout << float_to_string((float)100 * metrics.stack.mac.ues[i].tx_errors / metrics.stack.mac.ues[i].tx_pkts, 1, 4)
<< "%";
} else {
cout << float_to_string(0, 1, 4) << "%";
}
cout << " ";
if (not isnan(metrics.phy[i].ul.pusch_sinr) and not iszero(metrics.phy[i].ul.pusch_sinr)) {
cout << float_to_string(metrics.phy[i].ul.pusch_sinr, 2, 5);
} else {
cout << " n/a";
}
if (not isnan(metrics.phy[i].ul.pucch_sinr) and not iszero(metrics.phy[i].ul.pucch_sinr)) {
cout << float_to_string(metrics.phy[i].ul.pucch_sinr, 2, 6);
} else {
cout << " n/a";
}
cout << " ";
cout << float_to_string(metrics.stack.mac.ues[i].phr, 2, 5);
if (not isnan(metrics.phy[i].ul.mcs)) {
cout << float_to_string(metrics.phy[i].ul.mcs, 1, 4);
} else {
cout << float_to_string(0, 1, 4);
}
if (metrics.stack.mac.ues[i].rx_brate > 0) {
cout << float_to_eng_string((float)metrics.stack.mac.ues[i].rx_brate / (metrics.stack.mac.ues[i].nof_tti * 1e-3), 1);
} else {
cout << float_to_string(0, 1) << "";
}
cout << std::setw(5) << metrics.stack.mac.ues[i].rx_pkts - metrics.stack.mac.ues[i].rx_errors;
cout << std::setw(5) << metrics.stack.mac.ues[i].rx_errors;
if (metrics.stack.mac.ues[i].rx_pkts > 0 && metrics.stack.mac.ues[i].rx_errors > 0) {
cout << float_to_string((float)100 * metrics.stack.mac.ues[i].rx_errors / metrics.stack.mac.ues[i].rx_pkts, 1, 4)
<< "%";
} else {
cout << float_to_string(0, 1, 4) << "%";
}
cout << float_to_eng_string(metrics.stack.mac.ues[i].ul_buffer, 2);
cout << endl;
}
cout.flags(f); // For avoiding Coverity defect: Not restoring ostream format
}
std::string metrics_stdout::float_to_string(float f, int digits, int field_width)
{
std::ostringstream os;
int precision;
if (isnan(f) or fabs(f) < 0.0001) {
f = 0.0;
precision = digits - 1;
} else {
precision = digits - (int)(log10f(fabs(f + 0.0001)) - 2 * DBL_EPSILON);
}
if (precision == -1) {
precision = 0;
}
os << std::setw(field_width) << std::fixed << std::setprecision(precision) << f;
return os.str();
}
std::string metrics_stdout::int_to_hex_string(int value, int field_width)
{
std::ostringstream os;
os << std::hex << std::setw(field_width) << value;
return os.str();
}
std::string metrics_stdout::float_to_eng_string(float f, int digits)
{
const int degree = (f == 0.0) ? 0 : lrint(floor(log10f(fabs(f)) / 3));
std::string factor;
if (abs(degree) < 9) {
if (degree < 0)
factor = prefixes[0][abs(degree)];
else
factor = prefixes[1][abs(degree)];
} else {
return "failed";
}
const double scaled = f * pow(1000.0, -degree);
if (degree != 0) {
return float_to_string(scaled, digits, 5) + factor;
} else {
return " " + float_to_string(scaled, digits, 5 - factor.length()) + factor;
}
}
} // namespace srsenb