Added option to log_filter to customize time source

master
Ismael Gomez 7 years ago
parent 88e19ca19d
commit 845fc87945

@ -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);

@ -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);
strftime(buffer,64,"%H:%M:%S",timeinfo); if (time_format == TIME) {
strcat(buffer,"."); strftime(buffer, 64, "%H:%M:%S", timeinfo);
snprintf(us,16,"%06ld",rawtime.tv_usec); strcat(buffer, ".");
strcat(buffer,us); 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); return std::string(buffer);
} }

@ -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"

Loading…
Cancel
Save