mirror of https://github.com/pvnis/srsRAN_4G.git
add CSV metrics for eNB
parent
cd7008a269
commit
db910cb84b
@ -0,0 +1,67 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
* \section COPYRIGHT
|
||||||
|
*
|
||||||
|
* Copyright 2013-2015 Software Radio Systems Limited
|
||||||
|
*
|
||||||
|
* \section LICENSE
|
||||||
|
*
|
||||||
|
* This file is part of the srsUE library.
|
||||||
|
*
|
||||||
|
* srsUE is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of
|
||||||
|
* the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* srsUE is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* A copy of the GNU Affero General Public License can be found in
|
||||||
|
* the LICENSE file in the top-level directory of this distribution
|
||||||
|
* and at http://www.gnu.org/licenses/.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/******************************************************************************
|
||||||
|
* File: metrics_csv.h
|
||||||
|
* Description: Metrics class writing to CSV file.
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef SRSENB_METRICS_CSV_H
|
||||||
|
#define SRSENB_METRICS_CSV_H
|
||||||
|
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <string>
|
||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
#include "srslte/common/metrics_hub.h"
|
||||||
|
#include "srslte/interfaces/enb_metrics_interface.h"
|
||||||
|
|
||||||
|
namespace srsenb {
|
||||||
|
|
||||||
|
class metrics_csv : public srslte::metrics_listener<enb_metrics_t>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
metrics_csv(std::string filename);
|
||||||
|
~metrics_csv();
|
||||||
|
|
||||||
|
void set_metrics(enb_metrics_t &m, const uint32_t period_usec);
|
||||||
|
void set_handle(enb_metrics_interface *enb_);
|
||||||
|
void stop();
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string float_to_string(float f, int digits, bool add_semicolon = true);
|
||||||
|
|
||||||
|
float metrics_report_period;
|
||||||
|
std::ofstream file;
|
||||||
|
enb_metrics_interface* enb;
|
||||||
|
uint32_t n_reports;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace srsenb
|
||||||
|
|
||||||
|
#endif // SRSENB_METRICS_CSV_H
|
@ -0,0 +1,123 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
* \section COPYRIGHT
|
||||||
|
*
|
||||||
|
* Copyright 2015 The srsUE Developers. See the
|
||||||
|
* COPYRIGHT file at the top-level directory of this distribution.
|
||||||
|
*
|
||||||
|
* \section LICENSE
|
||||||
|
*
|
||||||
|
* This file is part of the srsUE library.
|
||||||
|
*
|
||||||
|
* srsUE is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of
|
||||||
|
* the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* srsUE is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* A copy of the GNU Affero General Public License can be found in
|
||||||
|
* the LICENSE file in the top-level directory of this distribution
|
||||||
|
* and at http://www.gnu.org/licenses/.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "srsenb/hdr/metrics_csv.h"
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sstream>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <float.h>
|
||||||
|
#include <iomanip>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
namespace srsenb{
|
||||||
|
|
||||||
|
metrics_csv::metrics_csv(std::string filename)
|
||||||
|
:n_reports(0)
|
||||||
|
,metrics_report_period(1.0)
|
||||||
|
,enb(NULL)
|
||||||
|
{
|
||||||
|
file.open(filename.c_str(), std::ios_base::out);
|
||||||
|
}
|
||||||
|
|
||||||
|
metrics_csv::~metrics_csv()
|
||||||
|
{
|
||||||
|
stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
void metrics_csv::set_handle(enb_metrics_interface *enb_)
|
||||||
|
{
|
||||||
|
enb = enb_;
|
||||||
|
}
|
||||||
|
|
||||||
|
void metrics_csv::stop()
|
||||||
|
{
|
||||||
|
if (file.is_open()) {
|
||||||
|
file << "#eof\n";
|
||||||
|
file.flush();
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void metrics_csv::set_metrics(enb_metrics_t &metrics, const uint32_t period_usec)
|
||||||
|
{
|
||||||
|
if (file.is_open() && enb != NULL) {
|
||||||
|
if(n_reports == 0) {
|
||||||
|
file << "time;nof_ue;dl_brate;ul_brate\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Time
|
||||||
|
file << (metrics_report_period*n_reports) << ";";
|
||||||
|
|
||||||
|
// UEs
|
||||||
|
file << (metrics.rrc.n_ues) << ";";
|
||||||
|
|
||||||
|
// Sum up rates for all UEs
|
||||||
|
float dl_rate_sum = 0.0, ul_rate_sum = 0.0;
|
||||||
|
for (int i = 0; i < metrics.rrc.n_ues; i++) {
|
||||||
|
dl_rate_sum += metrics.mac[i].tx_brate;
|
||||||
|
ul_rate_sum += metrics.mac[i].rx_brate;
|
||||||
|
}
|
||||||
|
|
||||||
|
// DL rate
|
||||||
|
if (dl_rate_sum > 0) {
|
||||||
|
file << float_to_string(SRSLTE_MAX(0.1,(float)dl_rate_sum/period_usec*1e6), 2);
|
||||||
|
} else {
|
||||||
|
file << float_to_string(0, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
// UL rate
|
||||||
|
if (ul_rate_sum > 0) {
|
||||||
|
file << float_to_string(SRSLTE_MAX(0.1,(float)ul_rate_sum/period_usec*1e6), 2, false);
|
||||||
|
} else {
|
||||||
|
file << float_to_string(0, 2, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
file << "\n";
|
||||||
|
|
||||||
|
n_reports++;
|
||||||
|
} else {
|
||||||
|
std::cout << "Error, couldn't write CSV file." << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string metrics_csv::float_to_string(float f, int digits, bool add_semicolon)
|
||||||
|
{
|
||||||
|
std::ostringstream os;
|
||||||
|
const int precision = (f == 0.0) ? digits-1 : digits - log10(fabs(f))-2*DBL_EPSILON;
|
||||||
|
os << std::fixed << std::setprecision(precision) << f;
|
||||||
|
if (add_semicolon)
|
||||||
|
os << ';';
|
||||||
|
return os.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace srsenb
|
Loading…
Reference in New Issue