From fcd086a1c5b87d875299fdd6b6c03c350e735818 Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Thu, 9 May 2019 16:10:49 +0200 Subject: [PATCH] fix metrics_hub compilation for older gcc using std::chrono --- lib/include/srslte/common/metrics_hub.h | 26 +++++++++++-------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/lib/include/srslte/common/metrics_hub.h b/lib/include/srslte/common/metrics_hub.h index 231425935..a14852b25 100644 --- a/lib/include/srslte/common/metrics_hub.h +++ b/lib/include/srslte/common/metrics_hub.h @@ -28,9 +28,10 @@ #ifndef SRSLTE_METRICS_HUB_H #define SRSLTE_METRICS_HUB_H -#include #include "srslte/common/threads.h" #include "srslte/srslte.h" +#include +#include namespace srslte { @@ -53,13 +54,7 @@ template class metrics_hub : public periodic_thread { public: - metrics_hub() - :m(NULL) - { - for (int i = 0; i < 3; ++i) { - sleep_period_start[i] = (struct timeval){}; - } - } + metrics_hub() : m(nullptr), sleep_start(std::chrono::steady_clock::now()) {} bool init(metrics_interface *m_, float report_period_secs_=1.0) { m = m_; // Start with user-default priority @@ -81,24 +76,25 @@ public: } 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; + auto period_usec = + std::chrono::duration_cast(std::chrono::steady_clock::now() - sleep_start); + if (m) { metrics_t metric; m->get_metrics(metric); for (uint32_t i=0;iset_metrics(metric, period); + listeners[i]->set_metrics(metric, period_usec.count()); } } // store start of sleep period - gettimeofday(&sleep_period_start[1], NULL); + sleep_start = std::chrono::steady_clock::now(); } metrics_interface *m; std::vector*> listeners; - struct timeval sleep_period_start[3]; + std::chrono::steady_clock::time_point sleep_start; }; } // namespace srslte