Skip to content

Commit

Permalink
Add timestamp to WARN and DEBUG messages
Browse files Browse the repository at this point in the history
This should help debugging test problems.

Signed-off-by: Giuliano Belinassi <[email protected]>
  • Loading branch information
giulianobelinassi committed Dec 7, 2024
1 parent b5be066 commit 3d7112a
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
23 changes: 23 additions & 0 deletions lib/msg_queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

/* 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. */
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
22 changes: 22 additions & 0 deletions tools/introspection.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 3d7112a

Please sign in to comment.