From 845fc87945f2f605fee3e4cb969305812ce67c9b Mon Sep 17 00:00:00 2001 From: Ismael Gomez Date: Sun, 17 Dec 2017 11:01:50 +0100 Subject: [PATCH] Added option to log_filter to customize time source --- lib/include/srslte/common/log_filter.h | 17 ++++++++++ lib/src/common/log_filter.cc | 46 ++++++++++++++++++++------ srsenb/src/mac/scheduler_harq.cc | 1 - 3 files changed, 52 insertions(+), 12 deletions(-) diff --git a/lib/include/srslte/common/log_filter.h b/lib/include/srslte/common/log_filter.h index ae232f135..6902b7740 100644 --- a/lib/include/srslte/common/log_filter.h +++ b/lib/include/srslte/common/log_filter.h @@ -37,6 +37,8 @@ #include #include + +#include "srslte/phy/common/timestamp.h" #include "srslte/common/log.h" #include "srslte/common/logger.h" #include "srslte/common/logger_stdout.h" @@ -71,10 +73,25 @@ public: void info_line(std::string file, int line, std::string message, ...); void debug_line(std::string file, int line, std::string message, ...); + class time_itf { + public: + virtual srslte_timestamp_t get_time() = 0; + }; + + typedef enum { + TIME, + EPOCH + } time_format_t; + + void set_time_src(time_itf *source, time_format_t format); + private: logger *logger_h; bool do_tti; + time_itf *time_src; + time_format_t time_format; + logger_stdout def_logger_stdout; void all_log(srslte::LOG_LEVEL_ENUM level, uint32_t tti, char *msg); diff --git a/lib/src/common/log_filter.cc b/lib/src/common/log_filter.cc index 899a224d6..85380e745 100644 --- a/lib/src/common/log_filter.cc +++ b/lib/src/common/log_filter.cc @@ -37,7 +37,9 @@ namespace srslte{ log_filter::log_filter() { - do_tti = false; + do_tti = false; + time_src = NULL; + time_format = TIME; } log_filter::log_filter(std::string layer) @@ -278,7 +280,10 @@ void log_filter::debug_line(std::string file, int line, std::string message, ... } } - +void log_filter::set_time_src(time_itf *source, time_format_t format) { + this->time_src = source; + this->time_format = format; +} std::string log_filter::now_time() { @@ -286,15 +291,34 @@ std::string log_filter::now_time() struct tm * timeinfo; char buffer[64]; char us[16]; - - gettimeofday(&rawtime, NULL); - timeinfo = localtime(&rawtime.tv_sec); - - strftime(buffer,64,"%H:%M:%S",timeinfo); - strcat(buffer,"."); - snprintf(us,16,"%06ld",rawtime.tv_usec); - strcat(buffer,us); - + + srslte_timestamp_t now; + uint64_t usec_epoch; + + if (!time_src) { + gettimeofday(&rawtime, NULL); + timeinfo = localtime(&rawtime.tv_sec); + + if (time_format == TIME) { + strftime(buffer, 64, "%H:%M:%S", timeinfo); + strcat(buffer, "."); + snprintf(us, 16, "%06ld", rawtime.tv_usec); + strcat(buffer, us); + } else { + usec_epoch = rawtime.tv_sec * 1000000 + rawtime.tv_usec; + snprintf(buffer, 64, "%ld", usec_epoch); + } + } else { + now = time_src->get_time(); + + if (time_format == TIME) { + snprintf(buffer, 64, "%ld:%06u", now.full_secs, (uint32_t) (now.frac_secs * 1e6)); + } else { + usec_epoch = now.full_secs * 1000000 + (uint32_t) (now.frac_secs * 1e6); + snprintf(buffer, 64, "%ld", usec_epoch); + } + } + return std::string(buffer); } diff --git a/srsenb/src/mac/scheduler_harq.cc b/srsenb/src/mac/scheduler_harq.cc index 6e1596850..6c97e6f14 100644 --- a/srsenb/src/mac/scheduler_harq.cc +++ b/srsenb/src/mac/scheduler_harq.cc @@ -25,7 +25,6 @@ */ #include -#include #include "srslte/srslte.h" #include "srslte/common/pdu.h"