2 * Copyright 2004-2005 Timo Hirvonen
17 #error DEBUG not defined
21 #error DEBUG must be >= 0
24 void debug_init(void);
25 void __debug_bug(const char *function
, const char *fmt
, ...) __FORMAT(2, 3) __NORETURN
;
26 void __debug_print(const char *function
, const char *fmt
, ...) __FORMAT(2, 3);
28 /* ------------------------------------------------------------------------ */
32 #define BUG(...) do { } while (0)
36 #define BUG(...) __debug_bug(__FUNCTION__, __VA_ARGS__)
40 /* ------------------------------------------------------------------------ */
42 #if DEBUG == 0 || DEBUG == 1
44 #define d_print(...) do { } while (0)
46 static inline void timer_get(uint64_t *usec
)
51 static inline void timer_print(const char *what
, uint64_t usec
)
57 #define d_print(...) __debug_print(__FUNCTION__, __VA_ARGS__)
59 static inline void timer_get(uint64_t *usec
)
63 gettimeofday(&tv
, NULL
);
64 *usec
= tv
.tv_sec
* 1e6L
+ tv
.tv_usec
;
67 static inline void timer_print(const char *what
, uint64_t usec
)
69 uint64_t a
= usec
/ 1e6
;
70 uint64_t b
= usec
- a
* 1e6
;
72 __debug_print("TIMER", "%s: %11Lu.%06Lu\n", what
, a
, b
);
77 /* ------------------------------------------------------------------------ */
84 BUG("%s\n", __STR(a)); \