Re-format the enb stdout metrics and port the code to use the fmt library.

master
faluco 3 years ago committed by faluco
parent ec272061a0
commit 5798f09252

@ -38,7 +38,6 @@ public:
private: private:
std::string float_to_string(float f, int digits, int field_width = 6); std::string float_to_string(float f, int digits, int field_width = 6);
std::string int_to_hex_string(int value, int field_width);
std::string float_to_eng_string(float f, int digits); std::string float_to_eng_string(float f, int digits);
std::atomic<bool> do_print = {false}; std::atomic<bool> do_print = {false};

@ -78,20 +78,18 @@ void metrics_stdout::set_metrics(const enb_metrics_t& metrics, const uint32_t pe
} }
if (metrics.rf.rf_error) { 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); fmt::print("RF status: O={}, U={}, L={}\n", metrics.rf.rf_o, metrics.rf.rf_u, metrics.rf.rf_l);
} }
if (metrics.stack.rrc.ues.size() == 0) { if (metrics.stack.rrc.ues.size() == 0) {
return; return;
} }
std::ios::fmtflags f(cout.flags()); // For avoiding Coverity defect: Not restoring ostream format
if (++n_reports > 10) { if (++n_reports > 10) {
n_reports = 0; n_reports = 0;
cout << endl; fmt::print("\n");
cout << "------DL-------------------------------UL--------------------------------------------" << endl; fmt::print("-------------------DL--------------------|-------------------------UL-------------------------\n");
cout << "rnti cqi ri mcs brate ok nok (%) pusch pucch phr mcs brate ok nok (%) bsr" << endl; fmt::print("rnti cqi ri mcs brate ok nok (%) | pusch pucch phr mcs brate ok nok (%) bsr\n");
} }
for (size_t i = 0; i < metrics.stack.rrc.ues.size(); i++) { for (size_t i = 0; i < metrics.stack.rrc.ues.size(); i++) {
@ -100,77 +98,87 @@ void metrics_stdout::set_metrics(const enb_metrics_t& metrics, const uint32_t pe
break; break;
} }
if (metrics.stack.mac.ues[i].tx_errors > metrics.stack.mac.ues[i].tx_pkts) { 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); fmt::print("tx caution errors {} > {}\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) { 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); fmt::print("rx caution errors {} > {}\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) << " "; fmt::print("{:>4x}", metrics.stack.mac.ues[i].rnti);
if (not iszero(metrics.stack.mac.ues[i].dl_cqi)) { if (not iszero(metrics.stack.mac.ues[i].dl_cqi)) {
cout << float_to_string(metrics.stack.mac.ues[i].dl_cqi, 1, 3); fmt::print(" {:>3}", int(metrics.stack.mac.ues[i].dl_cqi));
} else { } else {
cout << "n/a"; fmt::print(" {:>3.3}", "n/a");
} }
cout << float_to_string(metrics.stack.mac.ues[i].dl_ri, 1, 4); fmt::print(" {:>1}", int(metrics.stack.mac.ues[i].dl_ri));
if (not isnan(metrics.phy[i].dl.mcs)) { if (not isnan(metrics.phy[i].dl.mcs)) {
cout << float_to_string(metrics.phy[i].dl.mcs, 1, 4); fmt::print(" {:>2}", int(metrics.phy[i].dl.mcs));
} else { } else {
cout << float_to_string(0, 2, 4); fmt::print(" {:>2}", 0);
} }
if (metrics.stack.mac.ues[i].tx_brate > 0) { 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); fmt::print(
" {:>6.6}",
float_to_eng_string((float)metrics.stack.mac.ues[i].tx_brate / (metrics.stack.mac.ues[i].nof_tti * 1e-3), 1));
} else { } else {
cout << float_to_string(0, 1, 6) << ""; fmt::print(" {:>6}", 0);
} }
cout << std::setw(5) << metrics.stack.mac.ues[i].tx_pkts - metrics.stack.mac.ues[i].tx_errors; fmt::print(" {:>4}", 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; fmt::print(" {:>4}", metrics.stack.mac.ues[i].tx_errors);
if (metrics.stack.mac.ues[i].tx_pkts > 0 && 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) fmt::print(" {:>3}%", int((float)100 * metrics.stack.mac.ues[i].tx_errors / metrics.stack.mac.ues[i].tx_pkts));
<< "%";
} else { } else {
cout << float_to_string(0, 1, 4) << "%"; fmt::print(" {:>3}%", 0);
} }
cout << " ";
fmt::print(" |");
auto clamp_sinr = [](float sinr) {
if (sinr > 99.9f) {
return 99.9f;
}
if (sinr < -99.9f) {
return -99.9f;
}
return sinr;
};
if (not isnan(metrics.phy[i].ul.pusch_sinr) and not iszero(metrics.phy[i].ul.pusch_sinr)) { 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); fmt::print(" {:>5.1f}", clamp_sinr(metrics.phy[i].ul.pusch_sinr));
} else { } else {
cout << " n/a"; fmt::print(" {:>5.5}", "n/a");
} }
if (not isnan(metrics.phy[i].ul.pucch_sinr) and not iszero(metrics.phy[i].ul.pucch_sinr)) { 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); fmt::print(" {:>5.1f}", clamp_sinr(metrics.phy[i].ul.pucch_sinr));
} else { } else {
cout << " n/a"; fmt::print(" {:>5.5}", "n/a");
} }
cout << " ";
cout << float_to_string(metrics.stack.mac.ues[i].phr, 2, 5); fmt::print(" {:>3}", int(metrics.stack.mac.ues[i].phr));
if (not isnan(metrics.phy[i].ul.mcs)) { if (not isnan(metrics.phy[i].ul.mcs)) {
cout << float_to_string(metrics.phy[i].ul.mcs, 1, 4); fmt::print(" {:>2}", int(metrics.phy[i].ul.mcs));
} else { } else {
cout << float_to_string(0, 1, 4); fmt::print(" {:>2}", 0);
} }
if (metrics.stack.mac.ues[i].rx_brate > 0) { 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); fmt::print(
" {:>6.6}",
float_to_eng_string((float)metrics.stack.mac.ues[i].rx_brate / (metrics.stack.mac.ues[i].nof_tti * 1e-3), 1));
} else { } else {
cout << float_to_string(0, 1) << ""; fmt::print(" {:>6}", 0);
} }
cout << std::setw(5) << metrics.stack.mac.ues[i].rx_pkts - metrics.stack.mac.ues[i].rx_errors; fmt::print(" {:>4}", 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; fmt::print(" {:>4}", metrics.stack.mac.ues[i].rx_errors);
if (metrics.stack.mac.ues[i].rx_pkts > 0 && metrics.stack.mac.ues[i].rx_errors > 0) { 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) fmt::print(" {:>3}%", int((float)100 * metrics.stack.mac.ues[i].rx_errors / metrics.stack.mac.ues[i].rx_pkts));
<< "%";
} else { } else {
cout << float_to_string(0, 1, 4) << "%"; fmt::print(" {:>3}%", 0);
} }
cout << float_to_eng_string(metrics.stack.mac.ues[i].ul_buffer, 2); fmt::print(" {:>6.6}", float_to_eng_string(metrics.stack.mac.ues[i].ul_buffer, 2));
cout << endl; fmt::print("\n");
} }
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::string metrics_stdout::float_to_string(float f, int digits, int field_width)
@ -190,13 +198,6 @@ std::string metrics_stdout::float_to_string(float f, int digits, int field_width
return os.str(); 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) 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)); const int degree = (f == 0.0) ? 0 : lrint(floor(log10f(fabs(f)) / 3));

Loading…
Cancel
Save