[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Minios-devel] [UNIKRAFT PATCH v3 3/4] lib/ukdebug: Add timestamp to debug messages



Add timestamp to the debug messages.
The timestamp is retrieved from the platform's
monotonic clock.
Can be enabled/disabled.

Signed-off-by: Dafna Hirschfeld <dafna3@xxxxxxxxx>
---
 lib/ukdebug/Config.uk |  5 +++++
 lib/ukdebug/print.c   | 20 ++++++++++++++++++++
 2 files changed, 25 insertions(+)

diff --git a/lib/ukdebug/Config.uk b/lib/ukdebug/Config.uk
index d2bc02b..d5e5cdd 100644
--- a/lib/ukdebug/Config.uk
+++ b/lib/ukdebug/Config.uk
@@ -39,6 +39,11 @@ config LIBUKDEBUG_PRINTD_CRIT
        bool "Show critical messages only"
 endchoice
 
+config LIBUKDEBUG_PRINTD_TIME
+       bool "Show timestamp in debug messages"
+       default y
+       depends on LIBUKDEBUG_PRINTD
+
 choice
        prompt "Message redirection"
        default LIBUKDEBUG_NOREDIR
diff --git a/lib/ukdebug/print.c b/lib/ukdebug/print.c
index 175baaf..e5acae6 100644
--- a/lib/ukdebug/print.c
+++ b/lib/ukdebug/print.c
@@ -42,6 +42,7 @@
 #include <stdarg.h>
 
 #include <uk/plat/console.h>
+#include <uk/plat/time.h>
 #include <uk/print.h>
 #include <uk/arch/lcpu.h>
 
@@ -75,6 +76,22 @@ static inline void _vprintk(const char *fmt, va_list ap)
 #define _ukplat_coutd(lbuf, len) ukplat_coutd((lbuf), (len))
 #endif
 
+#if LIBUKDEBUG_PRINTD_TIME
+static void _printd_timestamp(void)
+{
+       char buf[BUFLEN];
+       int len;
+       __nsec nansec =  ukplat_monotonic_clock();
+       __nsec sec = ukarch_time_nsec_to_sec(nansec);
+       __nsec rem_usec = ukarch_time_subsec(nansec);
+
+       rem_usec = ukarch_time_nsec_to_usec(rem_usec);
+       len = snprintf(buf, BUFLEN, "[%5" __PRInsec ".%06" __PRInsec "] ",
+                       sec, rem_usec);
+       _ukplat_coutd((char *)buf, len);
+}
+#endif
+
 static inline void _vprintd(int lvl, const char *libname, const char *srcname,
                            unsigned int srcline, const char *fmt, va_list ap)
 {
@@ -129,6 +146,9 @@ static inline void _vprintd(int lvl, const char *libname, 
const char *srcname,
        lptr = lbuf;
        while (len > 0) {
                if (newline) {
+#if LIBUKDEBUG_PRINTD_TIME
+                       _printd_timestamp();
+#endif
                        _ukplat_coutd(DECONST(char *, msghdr), 6);
                        if (libname) {
                                _ukplat_coutd("[", 1);
-- 
2.7.4


_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.