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

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