summaryrefslogtreecommitdiffstats
path: root/mdadm.h
diff options
context:
space:
mode:
authorMateusz Kusiak <mateusz.kusiak@intel.com>2024-11-20 18:20:32 +0100
committerMariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>2024-11-22 09:00:32 +0100
commit655012434b7c059811a5f26001e47dd418f20a36 (patch)
treea5c604c67227b5a65d03b683aff40e04e864eeb1 /mdadm.h
parentCI: assign ret to numeric value (diff)
downloadmdadm-655012434b7c059811a5f26001e47dd418f20a36.tar.xz
mdadm-655012434b7c059811a5f26001e47dd418f20a36.zip
debug: add timestamps for debug messages
Timestamps on debug messages help establish what takes long to process. Debug messages are print only if DDEBUG flag is passed. Add timestamps for debug messages. Remove dead code from dprintf dummies for non-debug builds. Remove timestamps from current debug messages. Signed-off-by: Mateusz Kusiak <mateusz.kusiak@intel.com>
Diffstat (limited to 'mdadm.h')
-rw-r--r--mdadm.h14
1 files changed, 11 insertions, 3 deletions
diff --git a/mdadm.h b/mdadm.h
index 5aa50854..b9945a29 100644
--- a/mdadm.h
+++ b/mdadm.h
@@ -1899,15 +1899,23 @@ static inline sighandler_t signal_s(int sig, sighandler_t handler)
}
#ifdef DEBUG
+#include <time.h>
+
#define dprintf(fmt, arg...) \
- fprintf(stderr, "%s: %s: "fmt, Name, __func__, ##arg)
+ do { \
+ struct timespec ts; \
+ clock_gettime(CLOCK_MONOTONIC, &ts); \
+ double timestamp = ts.tv_sec + ts.tv_nsec / 1e9; \
+ fprintf(stderr, "[%10.5f] %s: %s: " fmt, timestamp, Name, __func__, ##arg); \
+ } while (0)
+
#define dprintf_cont(fmt, arg...) \
fprintf(stderr, fmt, ##arg)
#else
#define dprintf(fmt, arg...) \
- ({ if (0) fprintf(stderr, "%s: %s: " fmt, Name, __func__, ##arg); 0; })
+ do { } while (0)
#define dprintf_cont(fmt, arg...) \
- ({ if (0) fprintf(stderr, fmt, ##arg); 0; })
+ do { } while (0)
#endif
static inline int xasprintf(char **strp, const char *fmt, ...) {