calculate actual period for metrics logging

master
Andre Puschmann 7 years ago
parent 10fc1855d6
commit dbe0fa6f4e

@ -10,6 +10,7 @@
#include <vector> #include <vector>
#include "srslte/common/threads.h" #include "srslte/common/threads.h"
#include "srslte/srslte.h"
namespace srslte { namespace srslte {
@ -24,7 +25,7 @@ template<typename metrics_t>
class metrics_listener class metrics_listener
{ {
public: public:
virtual void set_metrics(metrics_t &m) = 0; virtual void set_metrics(metrics_t &m, const uint32_t period_usec) = 0;
virtual void stop() = 0; virtual void stop() = 0;
}; };
@ -34,13 +35,12 @@ class metrics_hub : public periodic_thread
public: public:
metrics_hub() metrics_hub()
:m(NULL) :m(NULL)
,report_period_secs(1) ,sleep_period_start()
{} {}
bool init(metrics_interface<metrics_t> *m_, float report_period_secs_=1.0) { bool init(metrics_interface<metrics_t> *m_, float report_period_secs_=1.0) {
m = m_; m = m_;
report_period_secs = report_period_secs_;
// Start with user-default priority // Start with user-default priority
start_periodic(report_period_secs*1e6, -2); start_periodic(report_period_secs_*1e6, -2);
return true; return true;
} }
void stop() { void stop() {
@ -57,18 +57,24 @@ public:
} }
private: private:
void run_period() { void run_period(){
// get current time and check how long we slept
gettimeofday(&sleep_period_start[2], NULL);
get_time_interval(sleep_period_start);
uint32_t period = sleep_period_start[0].tv_sec*1e6 + sleep_period_start[0].tv_usec;
if (m) { if (m) {
metrics_t metric = {}; metrics_t metric = {};
m->get_metrics(metric); m->get_metrics(metric);
for (uint32_t i=0;i<listeners.size();i++) { for (uint32_t i=0;i<listeners.size();i++) {
listeners[i]->set_metrics(metric); listeners[i]->set_metrics(metric, period);
} }
} }
// store start of sleep period
gettimeofday(&sleep_period_start[1], NULL);
} }
metrics_interface<metrics_t> *m; metrics_interface<metrics_t> *m;
std::vector<metrics_listener<metrics_t>*> listeners; std::vector<metrics_listener<metrics_t>*> listeners;
float report_period_secs; struct timeval sleep_period_start[3];
}; };
} // namespace srslte } // namespace srslte

@ -49,8 +49,7 @@ public:
metrics_csv(std::string filename); metrics_csv(std::string filename);
~metrics_csv(); ~metrics_csv();
void set_periodicity(float metrics_report_period_sec); void set_metrics(ue_metrics_t &m, const uint32_t period_usec);
void set_metrics(ue_metrics_t &m);
void set_ue_handle(ue_metrics_interface *ue_); void set_ue_handle(ue_metrics_interface *ue_);
void stop(); void stop();

@ -48,7 +48,7 @@ public:
void set_periodicity(float metrics_report_period_sec); void set_periodicity(float metrics_report_period_sec);
void toggle_print(bool b); void toggle_print(bool b);
void set_metrics(ue_metrics_t &m); void set_metrics(ue_metrics_t &m, const uint32_t period_usec);
void set_ue_handle(ue_metrics_interface *ue_); void set_ue_handle(ue_metrics_interface *ue_);
void stop() {}; void stop() {};

@ -447,13 +447,11 @@ int main(int argc, char *argv[])
metricshub.init(ue, args.expert.metrics_period_secs); metricshub.init(ue, args.expert.metrics_period_secs);
metricshub.add_listener(&metrics_screen); metricshub.add_listener(&metrics_screen);
metrics_screen.set_ue_handle(ue); metrics_screen.set_ue_handle(ue);
metrics_screen.set_periodicity(args.expert.metrics_period_secs);
metrics_csv metrics_file(args.expert.metrics_csv_filename); metrics_csv metrics_file(args.expert.metrics_csv_filename);
if (args.expert.metrics_csv_enable) { if (args.expert.metrics_csv_enable) {
metricshub.add_listener(&metrics_file); metricshub.add_listener(&metrics_file);
metrics_file.set_ue_handle(ue); metrics_file.set_ue_handle(ue);
metrics_file.set_periodicity(args.expert.metrics_period_secs);
} }
pthread_t input; pthread_t input;

@ -68,11 +68,7 @@ void metrics_csv::stop()
} }
} }
void metrics_csv::set_periodicity(float metrics_report_period_sec) { void metrics_csv::set_metrics(ue_metrics_t &metrics, const uint32_t period_usec)
this->metrics_report_period = metrics_report_period_sec;
}
void metrics_csv::set_metrics(ue_metrics_t &metrics)
{ {
if (file.is_open() && ue != NULL) { if (file.is_open() && ue != NULL) {
if(n_reports == 0) { if(n_reports == 0) {
@ -85,7 +81,7 @@ void metrics_csv::set_metrics(ue_metrics_t &metrics)
file << float_to_string(metrics.phy.dl.mcs, 2); file << float_to_string(metrics.phy.dl.mcs, 2);
file << float_to_string(metrics.phy.dl.sinr, 2); file << float_to_string(metrics.phy.dl.sinr, 2);
file << float_to_string(metrics.phy.dl.turbo_iters, 2); file << float_to_string(metrics.phy.dl.turbo_iters, 2);
file << float_to_string((float) metrics.mac.rx_brate/metrics_report_period, 2); file << float_to_string((float) metrics.mac.rx_brate/period_usec*1e6, 2);
if (metrics.mac.rx_pkts > 0) { if (metrics.mac.rx_pkts > 0) {
file << float_to_string((float) 100*metrics.mac.rx_errors/metrics.mac.rx_pkts, 1); file << float_to_string((float) 100*metrics.mac.rx_errors/metrics.mac.rx_pkts, 1);
} else { } else {
@ -93,7 +89,7 @@ void metrics_csv::set_metrics(ue_metrics_t &metrics)
} }
file << float_to_string(metrics.phy.ul.mcs, 2); file << float_to_string(metrics.phy.ul.mcs, 2);
file << float_to_string((float) metrics.mac.ul_buffer, 2); file << float_to_string((float) metrics.mac.ul_buffer, 2);
file << float_to_string((float) metrics.mac.tx_brate/metrics_report_period, 2); file << float_to_string((float) metrics.mac.tx_brate/period_usec*1e6, 2);
if (metrics.mac.tx_pkts > 0) { if (metrics.mac.tx_pkts > 0) {
file << float_to_string((float) 100*metrics.mac.tx_errors/metrics.mac.tx_pkts, 1); file << float_to_string((float) 100*metrics.mac.tx_errors/metrics.mac.tx_pkts, 1);
} else { } else {

@ -50,7 +50,6 @@ char const * const prefixes[2][9] =
metrics_stdout::metrics_stdout() metrics_stdout::metrics_stdout()
:do_print(false) :do_print(false)
,n_reports(10) ,n_reports(10)
,metrics_report_period(1.0)
,ue(NULL) ,ue(NULL)
{ {
} }
@ -65,11 +64,7 @@ void metrics_stdout::toggle_print(bool b)
do_print = b; do_print = b;
} }
void metrics_stdout::set_periodicity(float metrics_report_period_sec) { void metrics_stdout::set_metrics(ue_metrics_t &metrics, const uint32_t period_usec)
this->metrics_report_period = metrics_report_period_sec;
}
void metrics_stdout::set_metrics(ue_metrics_t &metrics)
{ {
if(!do_print || ue == NULL) if(!do_print || ue == NULL)
return; return;
@ -92,7 +87,7 @@ void metrics_stdout::set_metrics(ue_metrics_t &metrics)
cout << float_to_string(metrics.phy.dl.mcs, 2); cout << float_to_string(metrics.phy.dl.mcs, 2);
cout << float_to_string(metrics.phy.dl.sinr, 2); cout << float_to_string(metrics.phy.dl.sinr, 2);
cout << float_to_string(metrics.phy.dl.turbo_iters, 2); cout << float_to_string(metrics.phy.dl.turbo_iters, 2);
cout << float_to_eng_string((float) metrics.mac.rx_brate/metrics_report_period, 2); cout << float_to_eng_string((float) metrics.mac.rx_brate/period_usec*1e6, 2);
if (metrics.mac.rx_pkts > 0) { if (metrics.mac.rx_pkts > 0) {
cout << float_to_string((float) 100*metrics.mac.rx_errors/metrics.mac.rx_pkts, 1) << "%"; cout << float_to_string((float) 100*metrics.mac.rx_errors/metrics.mac.rx_pkts, 1) << "%";
} else { } else {
@ -100,7 +95,7 @@ void metrics_stdout::set_metrics(ue_metrics_t &metrics)
} }
cout << float_to_string(metrics.phy.ul.mcs, 2); cout << float_to_string(metrics.phy.ul.mcs, 2);
cout << float_to_eng_string((float) metrics.mac.ul_buffer, 2); cout << float_to_eng_string((float) metrics.mac.ul_buffer, 2);
cout << float_to_eng_string((float) metrics.mac.tx_brate/metrics_report_period, 2); cout << float_to_eng_string((float) metrics.mac.tx_brate/period_usec*1e6, 2);
if (metrics.mac.tx_pkts > 0) { if (metrics.mac.tx_pkts > 0) {
cout << float_to_string((float) 100*metrics.mac.tx_errors/metrics.mac.tx_pkts, 1) << "%"; cout << float_to_string((float) 100*metrics.mac.tx_errors/metrics.mac.tx_pkts, 1) << "%";
} else { } else {

Loading…
Cancel
Save