summaryrefslogtreecommitdiff
path: root/sys/kern
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2024-06-04 15:52:48 -0400
committerIan Moffett <ian@osmora.org>2024-06-04 15:53:50 -0400
commitf7ec58662269f08e025b52d83034f73f4975f878 (patch)
tree6aa04ef0549e9fbe4b9f3f77d50034433e5b9de2 /sys/kern
parent7c29fb70b00315bba95fa2a8b044e88a8d0b32d1 (diff)
kernel: syslog: Print timestamp in kprintf()
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'sys/kern')
-rw-r--r--sys/kern/kern_syslog.c16
1 files changed, 16 insertions, 0 deletions
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 <sys/syslog.h>
#include <sys/spinlock.h>
#include <dev/cons/cons.h>
+#include <dev/timer.h>
#include <stdarg.h>
#include <string.h>
@@ -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));
}