From 77551e7f4bbb7a64eef71a2108ac709f1b5e848e Mon Sep 17 00:00:00 2001 From: Giuliano Belinassi Date: Fri, 6 Dec 2024 20:35:26 -0300 Subject: [PATCH] Add timestamp to WARN and DEBUG messages This should help debugging test problems. Signed-off-by: Giuliano Belinassi --- lib/msg_queue.c | 23 +++++++++++++++++++++++ tools/introspection.c | 22 ++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/lib/msg_queue.c b/lib/msg_queue.c index 632bc53e..c220f1ac 100644 --- a/lib/msg_queue.c +++ b/lib/msg_queue.c @@ -25,6 +25,7 @@ #include #include #include +#include /* Create an externally visible msg_queue object that will be read with ptrace. * It will be read by ulp_messages (tools/messages.c) using ptrace. */ @@ -139,6 +140,17 @@ msgq_vpush(const char *format, va_list arglist) void ulp_warn(const char *format, ...) { + time_t rawtime; + struct tm *timeinfo, local_tm; + char timestamp[32]; + + time(&rawtime); + timeinfo = localtime_r(&rawtime, &local_tm); + + size_t n = strftime(timestamp, 32, "[%Y-%m-%d %H:%M:%S] ", timeinfo); + if (n > 0) + msgq_strpush(timestamp, n + 1); + va_list args; va_start(args, format); msgq_vpush(format, args); @@ -148,6 +160,17 @@ ulp_warn(const char *format, ...) void ulp_debug(const char *format, ...) { + time_t rawtime; + struct tm *timeinfo, local_tm; + char timestamp[32]; + + time(&rawtime); + timeinfo = localtime_r(&rawtime, &local_tm); + + size_t n = strftime(timestamp, 32, "[%Y-%m-%d %H:%M:%S] ", timeinfo); + if (n > 0) + msgq_strpush(timestamp, n + 1); + va_list args; va_start(args, format); msgq_vpush(format, args); diff --git a/tools/introspection.c b/tools/introspection.c index 59125999..5e86c6c9 100644 --- a/tools/introspection.c +++ b/tools/introspection.c @@ -86,6 +86,17 @@ void ulp_warn(const char *format, ...) { if (!ulp_quiet) { + time_t rawtime; + struct tm *timeinfo, local_tm; + char timestamp[32]; + + time(&rawtime); + timeinfo = localtime_r(&rawtime, &local_tm); + + strftime(timestamp, 32, "[%Y-%m-%d %H:%M:%S] ", timeinfo); + + fputs(timestamp, stderr); + va_list args; va_start(args, format); vfprintf(stderr, format, args); @@ -97,6 +108,17 @@ void ulp_debug(const char *format, ...) { if (ulp_verbose) { + time_t rawtime; + struct tm *timeinfo, local_tm; + char timestamp[32]; + + time(&rawtime); + timeinfo = localtime_r(&rawtime, &local_tm); + + strftime(timestamp, 32, "[%Y-%m-%d %H:%M:%S] ", timeinfo); + + fputs(timestamp, stderr); + va_list args; va_start(args, format); vfprintf(stderr, format, args);