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

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