aboutsummaryrefslogtreecommitdiffstats
path: root/src/vlib/log.c
diff options
context:
space:
mode:
authorDave Barach <dave@barachs.net>2018-09-27 08:46:15 -0400
committerDamjan Marion <dmarion@me.com>2018-09-27 18:31:24 +0000
commit10a690bee9091136e2a4e21e8501ec7a61bd2b5f (patch)
treefe8cbd7ab487a68dfd79ea9369c42f5feb753a66 /src/vlib/log.c
parent45ca73f6af1584a44886d5a13702885be58df1b6 (diff)
"show log": print wall-clock time
Change-Id: I36f42c03f778955dd543da6c878be090d0443922 Signed-off-by: Dave Barach <dave@barachs.net>
Diffstat (limited to 'src/vlib/log.c')
-rw-r--r--src/vlib/log.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/vlib/log.c b/src/vlib/log.c
index 8e205b9b74a..9ab7e08f7b9 100644
--- a/src/vlib/log.c
+++ b/src/vlib/log.c
@@ -62,6 +62,11 @@ typedef struct
int default_syslog_log_level;
int unthrottle_time;
u32 indent;
+
+ /* time zero */
+ struct timeval time_zero_timeval;
+ f64 time_zero;
+
} vlib_log_main_t;
vlib_log_main_t log_main = {
@@ -276,6 +281,10 @@ static clib_error_t *
vlib_log_init (vlib_main_t * vm)
{
vlib_log_main_t *lm = &log_main;
+
+ gettimeofday (&lm->time_zero_timeval, 0);
+ lm->time_zero = vlib_time_now (vm);
+
vec_validate (lm->entries, lm->size);
lm->log_class = vlib_log_register_class ("log", 0);
u8 *tmp = format (NULL, "%U %-10U %-10U ", format_time_float, 0, (f64) 0,
@@ -297,12 +306,16 @@ show_log (vlib_main_t * vm,
vlib_log_entry_t *e;
int i = last_log_entry ();
int count = lm->count;
+ f64 time_offset;
+
+ time_offset = (f64) lm->time_zero_timeval.tv_sec
+ + (((f64) lm->time_zero_timeval.tv_usec) * 1e-6) - lm->time_zero;
while (count--)
{
e = vec_elt_at_index (lm->entries, i);
vlib_cli_output (vm, "%U %-10U %-10U %v",
- format_time_float, 0, e->timestamp,
+ format_time_float, 0, e->timestamp + time_offset,
format_vlib_log_level, e->level,
format_vlib_log_class, e->class, e->string);
i = (i + 1) % lm->size;