Blame SOURCES/0320-New-with-debug-timestamps-configure-flag-to-prepend-.patch

3efed6
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
3efed6
From: =?UTF-8?q?Renaud=20M=C3=A9trich?= <rmetrich@redhat.com>
3efed6
Date: Sat, 23 Nov 2019 14:57:41 +0100
3efed6
Subject: [PATCH] New --with-debug-timestamps configure flag to prepend debug
3efed6
 traces with absolute and relative timestamp
3efed6
MIME-Version: 1.0
3efed6
Content-Type: text/plain; charset=UTF-8
3efed6
Content-Transfer-Encoding: 8bit
3efed6
3efed6
Signed-off-by: Renaud Métrich <rmetrich@redhat.com>
3efed6
---
3efed6
 configure.ac          | 18 ++++++++++++++++++
3efed6
 grub-core/kern/misc.c | 20 ++++++++++++++++++++
3efed6
 config.h.in           |  1 +
3efed6
 3 files changed, 39 insertions(+)
3efed6
3efed6
diff --git a/configure.ac b/configure.ac
3efed6
index 9323c125469..0059b938a3a 100644
3efed6
--- a/configure.ac
3efed6
+++ b/configure.ac
3efed6
@@ -1514,6 +1514,17 @@ else
3efed6
 fi
3efed6
 AC_SUBST([BOOT_TIME_STATS])
3efed6
 
3efed6
+AC_ARG_WITH([debug-timestamps],
3efed6
+	   AS_HELP_STRING([--with-debug-timestamps],
3efed6
+                          [prepend debug traces with absolute and relative timestamps]))
3efed6
+
3efed6
+if test x$with_debug_timestamps = xyes; then
3efed6
+  DEBUG_WITH_TIMESTAMPS=1
3efed6
+else
3efed6
+  DEBUG_WITH_TIMESTAMPS=0
3efed6
+fi
3efed6
+AC_SUBST([DEBUG_WITH_TIMESTAMPS])
3efed6
+
3efed6
 AC_ARG_ENABLE([grub-emu-sdl],
3efed6
 	      [AS_HELP_STRING([--enable-grub-emu-sdl],
3efed6
                              [build and install the `grub-emu' debugging utility with SDL support (default=guessed)])])
3efed6
@@ -2092,6 +2103,7 @@ AM_CONDITIONAL([COND_APPLE_LINKER], [test x$TARGET_APPLE_LINKER = x1])
3efed6
 AM_CONDITIONAL([COND_ENABLE_EFIEMU], [test x$enable_efiemu = xyes])
3efed6
 AM_CONDITIONAL([COND_ENABLE_CACHE_STATS], [test x$DISK_CACHE_STATS = x1])
3efed6
 AM_CONDITIONAL([COND_ENABLE_BOOT_TIME_STATS], [test x$BOOT_TIME_STATS = x1])
3efed6
+AM_CONDITIONAL([COND_DEBUG_WITH_TIMESTAMPS], [test x$DEBUG_WITH_TIMESTAMPS = x1])
3efed6
 
3efed6
 AM_CONDITIONAL([COND_HAVE_CXX], [test x$HAVE_CXX = xyes])
3efed6
 
3efed6
@@ -2187,6 +2199,12 @@ else
3efed6
 echo With boot time statistics: No
3efed6
 fi
3efed6
 
3efed6
+if [ x"$with_debug_timestamps" = xyes ]; then
3efed6
+echo Debug traces with timestamps: Yes
3efed6
+else
3efed6
+echo Debug traces with timestamps: No
3efed6
+fi
3efed6
+
3efed6
 if [ x"$efiemu_excuse" = x ]; then
3efed6
 echo efiemu runtime: Yes
3efed6
 else
3efed6
diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c
3efed6
index c034f49f97c..11f2974fce5 100644
3efed6
--- a/grub-core/kern/misc.c
3efed6
+++ b/grub-core/kern/misc.c
3efed6
@@ -25,6 +25,9 @@
3efed6
 #include <grub/env.h>
3efed6
 #include <grub/i18n.h>
3efed6
 #include <grub/backtrace.h>
3efed6
+#if DEBUG_WITH_TIMESTAMPS
3efed6
+#include <grub/time.h>
3efed6
+#endif
3efed6
 
3efed6
 union printf_arg
3efed6
 {
3efed6
@@ -179,9 +182,26 @@ grub_real_dprintf (const char *file, const int line, const char *condition,
3efed6
 		   const char *fmt, ...)
3efed6
 {
3efed6
   va_list args;
3efed6
+#if DEBUG_WITH_TIMESTAMPS
3efed6
+  static long unsigned int last_time = 0;
3efed6
+  static int last_had_cr = 1;
3efed6
+#endif
3efed6
 
3efed6
   if (grub_debug_enabled (condition))
3efed6
     {
3efed6
+#if DEBUG_WITH_TIMESTAMPS
3efed6
+      /* Don't print timestamp if last printed message isn't terminated yet */
3efed6
+      if (last_had_cr) {
3efed6
+        long unsigned int tmabs = (long unsigned int) grub_get_time_ms();
3efed6
+        long unsigned int tmrel = tmabs - last_time;
3efed6
+        last_time = tmabs;
3efed6
+        grub_printf ("%3lu.%03lus +%2lu.%03lus ", tmabs / 1000, tmabs % 1000, tmrel / 1000, tmrel % 1000);
3efed6
+      }
3efed6
+      if (fmt[grub_strlen(fmt)-1] == '\n')
3efed6
+        last_had_cr = 1;
3efed6
+      else
3efed6
+        last_had_cr = 0;
3efed6
+#endif
3efed6
       grub_printf ("%s:%d: ", file, line);
3efed6
       va_start (args, fmt);
3efed6
       grub_vprintf (fmt, args);
3efed6
diff --git a/config.h.in b/config.h.in
3efed6
index 9e8f9911b18..d15480b4163 100644
3efed6
--- a/config.h.in
3efed6
+++ b/config.h.in
3efed6
@@ -12,6 +12,7 @@
3efed6
 /* Define to 1 to enable disk cache statistics.  */
3efed6
 #define DISK_CACHE_STATS @DISK_CACHE_STATS@
3efed6
 #define BOOT_TIME_STATS @BOOT_TIME_STATS@
3efed6
+#define DEBUG_WITH_TIMESTAMPS @DEBUG_WITH_TIMESTAMPS@
3efed6
 
3efed6
 /* We don't need those.  */
3efed6
 #define MINILZO_CFG_SKIP_LZO_PTR 1