diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2009-09-11 16:22:43 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2009-09-11 16:22:43 -0400 |
commit | 4f0ac854167846bd55cd81dbc9a36e03708aa01c (patch) | |
tree | 0eb34d18a667f8e68ad9255f791560b028fed2a6 /tools/perf/util/debug.c | |
parent | b9356c53ba2f593081e5aa45eb67adcce243d1c0 (diff) | |
parent | 6b58e7f146f8d79c08f62087f928e1f01747de71 (diff) |
Merge branch 'perfcounters-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip
* 'perfcounters-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip: (60 commits)
perf tools: Avoid unnecessary work in directory lookups
perf stat: Clean up statistics calculations a bit more
perf stat: More advanced variance computation
perf stat: Use stddev_mean in stead of stddev
perf stat: Remove the limit on repeat
perf stat: Change noise calculation to use stddev
x86, perf_counter, bts: Do not allow kernel BTS tracing for now
x86, perf_counter, bts: Correct pointer-to-u64 casts
x86, perf_counter, bts: Fail if BTS is not available
perf_counter: Fix output-sharing error path
perf trace: Fix read_string()
perf trace: Print out in nanoseconds
perf tools: Seek to the end of the header area
perf trace: Fix parsing of perf.data
perf trace: Sample timestamps as well
perf_counter: Introduce new (non-)paranoia level to allow raw tracepoint access
perf trace: Sample the CPU too
perf tools: Work around strict aliasing related warnings
perf tools: Clean up warnings list in the Makefile
perf tools: Complete support for dynamic strings
...
Diffstat (limited to 'tools/perf/util/debug.c')
-rw-r--r-- | tools/perf/util/debug.c | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/tools/perf/util/debug.c b/tools/perf/util/debug.c new file mode 100644 index 000000000000..e8ca98fe0bd4 --- /dev/null +++ b/tools/perf/util/debug.c | |||
@@ -0,0 +1,95 @@ | |||
1 | /* For general debugging purposes */ | ||
2 | |||
3 | #include "../perf.h" | ||
4 | |||
5 | #include <string.h> | ||
6 | #include <stdarg.h> | ||
7 | #include <stdio.h> | ||
8 | |||
9 | #include "color.h" | ||
10 | #include "event.h" | ||
11 | #include "debug.h" | ||
12 | |||
13 | int verbose = 0; | ||
14 | int dump_trace = 0; | ||
15 | |||
16 | int eprintf(const char *fmt, ...) | ||
17 | { | ||
18 | va_list args; | ||
19 | int ret = 0; | ||
20 | |||
21 | if (verbose) { | ||
22 | va_start(args, fmt); | ||
23 | ret = vfprintf(stderr, fmt, args); | ||
24 | va_end(args); | ||
25 | } | ||
26 | |||
27 | return ret; | ||
28 | } | ||
29 | |||
30 | int dump_printf(const char *fmt, ...) | ||
31 | { | ||
32 | va_list args; | ||
33 | int ret = 0; | ||
34 | |||
35 | if (dump_trace) { | ||
36 | va_start(args, fmt); | ||
37 | ret = vprintf(fmt, args); | ||
38 | va_end(args); | ||
39 | } | ||
40 | |||
41 | return ret; | ||
42 | } | ||
43 | |||
44 | static int dump_printf_color(const char *fmt, const char *color, ...) | ||
45 | { | ||
46 | va_list args; | ||
47 | int ret = 0; | ||
48 | |||
49 | if (dump_trace) { | ||
50 | va_start(args, color); | ||
51 | ret = color_vfprintf(stdout, color, fmt, args); | ||
52 | va_end(args); | ||
53 | } | ||
54 | |||
55 | return ret; | ||
56 | } | ||
57 | |||
58 | |||
59 | void trace_event(event_t *event) | ||
60 | { | ||
61 | unsigned char *raw_event = (void *)event; | ||
62 | const char *color = PERF_COLOR_BLUE; | ||
63 | int i, j; | ||
64 | |||
65 | if (!dump_trace) | ||
66 | return; | ||
67 | |||
68 | dump_printf("."); | ||
69 | dump_printf_color("\n. ... raw event: size %d bytes\n", color, | ||
70 | event->header.size); | ||
71 | |||
72 | for (i = 0; i < event->header.size; i++) { | ||
73 | if ((i & 15) == 0) { | ||
74 | dump_printf("."); | ||
75 | dump_printf_color(" %04x: ", color, i); | ||
76 | } | ||
77 | |||
78 | dump_printf_color(" %02x", color, raw_event[i]); | ||
79 | |||
80 | if (((i & 15) == 15) || i == event->header.size-1) { | ||
81 | dump_printf_color(" ", color); | ||
82 | for (j = 0; j < 15-(i & 15); j++) | ||
83 | dump_printf_color(" ", color); | ||
84 | for (j = 0; j < (i & 15); j++) { | ||
85 | if (isprint(raw_event[i-15+j])) | ||
86 | dump_printf_color("%c", color, | ||
87 | raw_event[i-15+j]); | ||
88 | else | ||
89 | dump_printf_color(".", color); | ||
90 | } | ||
91 | dump_printf_color("\n", color); | ||
92 | } | ||
93 | } | ||
94 | dump_printf(".\n"); | ||
95 | } | ||