]>
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" |
16ad2ffb | 14 | #include "target.h" |
8f28827a | 15 | |
b44308f5 ACM |
16 | int verbose; |
17 | bool dump_trace = false, quiet = false; | |
cd84c2ac | 18 | |
f772abc6 | 19 | static int _eprintf(int level, const char *fmt, va_list args) |
cd84c2ac | 20 | { |
cd84c2ac FW |
21 | int ret = 0; |
22 | ||
6beba7ad | 23 | if (verbose >= level) { |
044c4f8f | 24 | if (use_browser >= 1) |
b56e5331 | 25 | ui_helpline__vshow(fmt, args); |
f9224c5c ACM |
26 | else |
27 | ret = vfprintf(stderr, fmt, args); | |
cd84c2ac FW |
28 | va_end(args); |
29 | } | |
30 | ||
31 | return ret; | |
32 | } | |
2cec19d9 | 33 | |
f772abc6 JO |
34 | int eprintf(int level, const char *fmt, ...) |
35 | { | |
36 | va_list args; | |
37 | int ret; | |
38 | ||
39 | va_start(args, fmt); | |
40 | ret = _eprintf(level, fmt, args); | |
41 | va_end(args); | |
42 | ||
43 | return ret; | |
44 | } | |
45 | ||
46 | /* | |
47 | * Overloading libtraceevent standard info print | |
48 | * function, display with -v in perf. | |
49 | */ | |
50 | void pr_stat(const char *fmt, ...) | |
51 | { | |
52 | va_list args; | |
53 | ||
54 | va_start(args, fmt); | |
55 | _eprintf(1, fmt, args); | |
56 | va_end(args); | |
57 | eprintf(1, "\n"); | |
58 | } | |
59 | ||
2cec19d9 FW |
60 | int dump_printf(const char *fmt, ...) |
61 | { | |
62 | va_list args; | |
63 | int ret = 0; | |
64 | ||
65 | if (dump_trace) { | |
66 | va_start(args, fmt); | |
67 | ret = vprintf(fmt, args); | |
68 | va_end(args); | |
69 | } | |
70 | ||
71 | return ret; | |
72 | } | |
8f28827a | 73 | |
8115d60c | 74 | void trace_event(union perf_event *event) |
8f28827a FW |
75 | { |
76 | unsigned char *raw_event = (void *)event; | |
77 | const char *color = PERF_COLOR_BLUE; | |
78 | int i, j; | |
79 | ||
80 | if (!dump_trace) | |
81 | return; | |
82 | ||
5b1c1444 ACM |
83 | printf("."); |
84 | color_fprintf(stdout, color, "\n. ... raw event: size %d bytes\n", | |
85 | event->header.size); | |
8f28827a FW |
86 | |
87 | for (i = 0; i < event->header.size; i++) { | |
88 | if ((i & 15) == 0) { | |
5b1c1444 ACM |
89 | printf("."); |
90 | color_fprintf(stdout, color, " %04x: ", i); | |
8f28827a FW |
91 | } |
92 | ||
5b1c1444 | 93 | color_fprintf(stdout, color, " %02x", raw_event[i]); |
8f28827a FW |
94 | |
95 | if (((i & 15) == 15) || i == event->header.size-1) { | |
5b1c1444 | 96 | color_fprintf(stdout, color, " "); |
8f28827a | 97 | for (j = 0; j < 15-(i & 15); j++) |
5b1c1444 | 98 | color_fprintf(stdout, color, " "); |
84c104ad | 99 | for (j = i & ~15; j <= i; j++) { |
5b1c1444 ACM |
100 | color_fprintf(stdout, color, "%c", |
101 | isprint(raw_event[j]) ? | |
102 | raw_event[j] : '.'); | |
8f28827a | 103 | } |
5b1c1444 | 104 | color_fprintf(stdout, color, "\n"); |
8f28827a FW |
105 | } |
106 | } | |
5b1c1444 | 107 | printf(".\n"); |
8f28827a | 108 | } |