-
Notifications
You must be signed in to change notification settings - Fork 0
/
debug.h
80 lines (54 loc) · 1.47 KB
/
debug.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
* Copyright 2004-2005 Timo Hirvonen
*/
#ifndef DEBUG_H
#define DEBUG_H
#include "compiler.h"
#include "config/debug.h"
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/time.h>
#include <inttypes.h>
void debug_init(void);
void __debug_bug(const char *function, const char *fmt, ...) __FORMAT(2, 3) __NORETURN;
void __debug_print(const char *function, const char *fmt, ...) __FORMAT(2, 3);
/* ------------------------------------------------------------------------ */
#if DEBUG <= 0
#define BUG(...) do { } while (0)
#else /* >0 */
#define BUG(...) __debug_bug(__FUNCTION__, __VA_ARGS__)
#endif
/* ------------------------------------------------------------------------ */
#if DEBUG <= 1
#define d_print(...) do { } while (0)
static inline void timer_get(uint64_t *usec)
{
*usec = 0;
}
static inline void timer_print(const char *what, uint64_t usec)
{
}
#else /* >1 */
#define d_print(...) __debug_print(__FUNCTION__, __VA_ARGS__)
static inline void timer_get(uint64_t *usec)
{
struct timeval tv;
gettimeofday(&tv, NULL);
*usec = tv.tv_sec * 1e6L + tv.tv_usec;
}
static inline void timer_print(const char *what, uint64_t usec)
{
uint64_t a = usec / 1e6;
uint64_t b = usec - a * 1e6;
__debug_print("TIMER", "%s: %11Lu.%06Lu\n", what, a, b);
}
#endif
/* ------------------------------------------------------------------------ */
#define __STR(a) #a
#define BUG_ON(a) \
do { \
if (unlikely(a)) \
BUG("%s\n", __STR(a)); \
} while (0)
#endif