From f7ec58662269f08e025b52d83034f73f4975f878 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Tue, 4 Jun 2024 15:52:48 -0400 Subject: kernel: syslog: Print timestamp in kprintf() Signed-off-by: Ian Moffett --- sys/kern/kern_syslog.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'sys') diff --git a/sys/kern/kern_syslog.c b/sys/kern/kern_syslog.c index 5b009e7..6962a69 100644 --- a/sys/kern/kern_syslog.c +++ b/sys/kern/kern_syslog.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -66,6 +67,8 @@ kprintf(const char *fmt, ...) char timestamp[64] = "[ 0.000000] "; const char *fmt_p = fmt; bool use_timestamp = true; + bool has_counter = true; + struct timer tmr; /* * If the first char is OMIT_TIMESTAMP, then we won't @@ -76,6 +79,19 @@ kprintf(const char *fmt, ...) use_timestamp = false; } + /* See if we have a timer */ + if (req_timer(TIMER_GP, &tmr) != TMRR_SUCCESS) { + has_counter = false; + } + + /* If we can use the counter, format the timestamp */ + if (has_counter) { + if (tmr.get_time_sec != NULL && tmr.get_time_usec != NULL) { + snprintf(timestamp, sizeof(timestamp), "[ %d.%06d] ", + tmr.get_time_sec(), tmr.get_time_usec()); + } + } + if (use_timestamp) { syslog_write(timestamp, strlen(timestamp)); } -- cgit v1.2.3