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

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