-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdebug_printf.c
More file actions
83 lines (60 loc) · 1.96 KB
/
debug_printf.c
File metadata and controls
83 lines (60 loc) · 1.96 KB
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
81
82
83
#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
#include "debug_printf.h"
#include "timestamp.h"
static int filtered_out_count = 0;
static bool should_print(debug_level level, debug_topics topic) {
switch (topic) {
case DEBUG_ALL:
return true;
case DEBUG_NONE:
return false;
case DEBUG_THREADS:
return level <= LEVEL_INFO;
case DEBUG_TIMELINE:
return level <= LEVEL_INFO;
case DEBUG_FIFO:
return level <= LEVEL_INFO; //!!! _LOW;
case DEBUG_MUTEX:
return level <= LEVEL_LOW;
case DEBUG_MSK:
return level <= LEVEL_INFO;
case DEBUG_IIO:
return level <= LEVEL_INFO;
case DEBUG_SESSION:
return level <= LEVEL_INFO;
case DEBUG_FRAMES:
return level <= LEVEL_INFO;
case DEBUG_ENCAP:
return level <= LEVEL_INFO;
case DEBUG_RX:
return level <= LEVEL_INFO;
case DEBUG_REGS:
return level <= LEVEL_INFO;
case DEBUG_FREQS:
return level <= LEVEL_INFO;
default:
printf("Unhandled topic %d in debug_printf.\n", topic);
return true;
}
}
void debug_printf(debug_level level, debug_topics topic, const char *format, ...) {
char extended_format[1000];
if (should_print(level, topic)) {
snprintf(extended_format, sizeof(extended_format), "DBG @ %lld: %s", get_timestamp_us(), format);
va_list args;
va_start(args, format);
vprintf(extended_format, args);
va_end(args);
} else {
filtered_out_count++;
}
}
void debug_printf_summary(void) {
if (filtered_out_count > 0) {
printf("%d messages were filtered out.\n", filtered_out_count);
} else {
printf("No messages were filtered out.\n");
}
}