nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

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

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