]>
Commit | Line | Data |
---|---|---|
cd84c2ac FW |
1 | /* For general debugging purposes */ |
2 | ||
3 | #include "../perf.h" | |
8f28827a | 4 | |
cd84c2ac FW |
5 | #include <string.h> |
6 | #include <stdarg.h> | |
7 | #include <stdio.h> | |
8 | ||
f9224c5c | 9 | #include "cache.h" |
8f28827a FW |
10 | #include "color.h" |
11 | #include "event.h" | |
12 | #include "debug.h" | |
4a58e611 | 13 | #include "util.h" |
8f28827a | 14 | |
b44308f5 ACM |
15 | int verbose; |
16 | bool dump_trace = false, quiet = false; | |
cd84c2ac | 17 | |
6beba7ad | 18 | int eprintf(int level, const char *fmt, ...) |
cd84c2ac FW |
19 | { |
20 | va_list args; | |
21 | int ret = 0; | |
22 | ||
6beba7ad | 23 | if (verbose >= level) { |
cd84c2ac | 24 | va_start(args, fmt); |
c4fe52a8 | 25 | if (use_browser > 0) |
1e6dd077 | 26 | ret = ui_helpline__show_help(fmt, args); |
f9224c5c ACM |
27 | else |
28 | ret = vfprintf(stderr, fmt, args); | |
cd84c2ac FW |
29 | va_end(args); |
30 | } | |
31 | ||
32 | return ret; | |
33 | } | |
2cec19d9 FW |
34 | |
35 | int dump_printf(const char *fmt, ...) | |
36 | { | |
37 | va_list args; | |
38 | int ret = 0; | |
39 | ||
40 | if (dump_trace) { | |
41 | va_start(args, fmt); | |
42 | ret = vprintf(fmt, args); | |
43 | va_end(args); | |
44 | } | |
45 | ||
46 | return ret; | |
47 | } | |
8f28827a | 48 | |
068ffaa8 ACM |
49 | #ifdef NO_NEWT_SUPPORT |
50 | void ui__warning(const char *format, ...) | |
51 | { | |
52 | va_list args; | |
53 | ||
54 | va_start(args, format); | |
55 | vfprintf(stderr, format, args); | |
56 | va_end(args); | |
57 | } | |
58 | #endif | |
59 | ||
8f28827a FW |
60 | void trace_event(event_t *event) |
61 | { | |
62 | unsigned char *raw_event = (void *)event; | |
63 | const char *color = PERF_COLOR_BLUE; | |
64 | int i, j; | |
65 | ||
66 | if (!dump_trace) | |
67 | return; | |
68 | ||
5b1c1444 ACM |
69 | printf("."); |
70 | color_fprintf(stdout, color, "\n. ... raw event: size %d bytes\n", | |
71 | event->header.size); | |
8f28827a FW |
72 | |
73 | for (i = 0; i < event->header.size; i++) { | |
74 | if ((i & 15) == 0) { | |
5b1c1444 ACM |
75 | printf("."); |
76 | color_fprintf(stdout, color, " %04x: ", i); | |
8f28827a FW |
77 | } |
78 | ||
5b1c1444 | 79 | color_fprintf(stdout, color, " %02x", raw_event[i]); |
8f28827a FW |
80 | |
81 | if (((i & 15) == 15) || i == event->header.size-1) { | |
5b1c1444 | 82 | color_fprintf(stdout, color, " "); |
8f28827a | 83 | for (j = 0; j < 15-(i & 15); j++) |
5b1c1444 | 84 | color_fprintf(stdout, color, " "); |
84c104ad | 85 | for (j = i & ~15; j <= i; j++) { |
5b1c1444 ACM |
86 | color_fprintf(stdout, color, "%c", |
87 | isprint(raw_event[j]) ? | |
88 | raw_event[j] : '.'); | |
8f28827a | 89 | } |
5b1c1444 | 90 | color_fprintf(stdout, color, "\n"); |
8f28827a FW |
91 | } |
92 | } | |
5b1c1444 | 93 | printf(".\n"); |
8f28827a | 94 | } |