Remove extraneous "`"
[cmus.git] / debug.h
bloba0add3f2ad827e82723764e28ac633fc9a4cc177
1 /*
2 * Copyright 2004-2005 Timo Hirvonen
3 */
5 #ifndef DEBUG_H
6 #define DEBUG_H
8 #include "compiler.h"
9 #include "config/debug.h"
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <errno.h>
14 #include <sys/time.h>
15 #include <inttypes.h>
17 void debug_init(void);
18 void __debug_bug(const char *function, const char *fmt, ...) __FORMAT(2, 3) __NORETURN;
19 void __debug_print(const char *function, const char *fmt, ...) __FORMAT(2, 3);
21 /* ------------------------------------------------------------------------ */
23 #if DEBUG <= 0
25 #define BUG(...) do { } while (0)
27 #else /* >0 */
29 #define BUG(...) __debug_bug(__FUNCTION__, __VA_ARGS__)
31 #endif
33 /* ------------------------------------------------------------------------ */
35 #if DEBUG <= 1
37 #define d_print(...) do { } while (0)
39 static inline void timer_get(uint64_t *usec)
41 *usec = 0;
44 static inline void timer_print(const char *what, uint64_t usec)
48 #else /* >1 */
50 #define d_print(...) __debug_print(__FUNCTION__, __VA_ARGS__)
52 static inline void timer_get(uint64_t *usec)
54 struct timeval tv;
56 gettimeofday(&tv, NULL);
57 *usec = tv.tv_sec * 1e6L + tv.tv_usec;
60 static inline void timer_print(const char *what, uint64_t usec)
62 uint64_t a = usec / 1e6;
63 uint64_t b = usec - a * 1e6;
65 __debug_print("TIMER", "%s: %11Lu.%06Lu\n", what, a, b);
68 #endif
70 /* ------------------------------------------------------------------------ */
72 #define __STR(a) #a
74 #define BUG_ON(a) \
75 do { \
76 if (unlikely(a)) \
77 BUG("%s\n", __STR(a)); \
78 } while (0)
80 #endif