Added option to log_filter to customize time source

This commit is contained in:
Ismael Gomez 2017-12-17 11:01:50 +01:00
parent 88e19ca19d
commit 845fc87945
3 changed files with 52 additions and 12 deletions

View File

@ -37,6 +37,8 @@
#include <stdarg.h> #include <stdarg.h>
#include <string> #include <string>
#include "srslte/phy/common/timestamp.h"
#include "srslte/common/log.h" #include "srslte/common/log.h"
#include "srslte/common/logger.h" #include "srslte/common/logger.h"
#include "srslte/common/logger_stdout.h" #include "srslte/common/logger_stdout.h"
@ -71,10 +73,25 @@ public:
void info_line(std::string file, int line, std::string message, ...); void info_line(std::string file, int line, std::string message, ...);
void debug_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: private:
logger *logger_h; logger *logger_h;
bool do_tti; bool do_tti;
time_itf *time_src;
time_format_t time_format;
logger_stdout def_logger_stdout; logger_stdout def_logger_stdout;
void all_log(srslte::LOG_LEVEL_ENUM level, uint32_t tti, char *msg); void all_log(srslte::LOG_LEVEL_ENUM level, uint32_t tti, char *msg);

View File

@ -38,6 +38,8 @@ namespace srslte{
log_filter::log_filter() log_filter::log_filter()
{ {
do_tti = false; do_tti = false;
time_src = NULL;
time_format = TIME;
} }
log_filter::log_filter(std::string layer) 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() std::string log_filter::now_time()
{ {
@ -287,13 +292,32 @@ std::string log_filter::now_time()
char buffer[64]; char buffer[64];
char us[16]; char us[16];
srslte_timestamp_t now;
uint64_t usec_epoch;
if (!time_src) {
gettimeofday(&rawtime, NULL); gettimeofday(&rawtime, NULL);
timeinfo = localtime(&rawtime.tv_sec); timeinfo = localtime(&rawtime.tv_sec);
if (time_format == TIME) {
strftime(buffer, 64, "%H:%M:%S", timeinfo); strftime(buffer, 64, "%H:%M:%S", timeinfo);
strcat(buffer, "."); strcat(buffer, ".");
snprintf(us, 16, "%06ld", rawtime.tv_usec); snprintf(us, 16, "%06ld", rawtime.tv_usec);
strcat(buffer, us); 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); return std::string(buffer);
} }

View File

@ -25,7 +25,6 @@
*/ */
#include <string.h> #include <string.h>
#include <boost/concept_check.hpp>
#include "srslte/srslte.h" #include "srslte/srslte.h"
#include "srslte/common/pdu.h" #include "srslte/common/pdu.h"