diff options
-rw-r--r-- | tools/perf/util/debug.c | 75 | ||||
-rw-r--r-- | tools/perf/util/util.c | 37 | ||||
-rw-r--r-- | tools/perf/util/util.h | 20 |
3 files changed, 105 insertions, 27 deletions
diff --git a/tools/perf/util/debug.c b/tools/perf/util/debug.c index ff7e86ad1b06..8c4212abd19b 100644 --- a/tools/perf/util/debug.c +++ b/tools/perf/util/debug.c | |||
@@ -106,40 +106,61 @@ int dump_printf(const char *fmt, ...) | |||
106 | return ret; | 106 | return ret; |
107 | } | 107 | } |
108 | 108 | ||
109 | static void trace_event_printer(enum binary_printer_ops op, | ||
110 | unsigned int val, void *extra) | ||
111 | { | ||
112 | const char *color = PERF_COLOR_BLUE; | ||
113 | union perf_event *event = (union perf_event *)extra; | ||
114 | unsigned char ch = (unsigned char)val; | ||
115 | |||
116 | switch (op) { | ||
117 | case BINARY_PRINT_DATA_BEGIN: | ||
118 | printf("."); | ||
119 | color_fprintf(stdout, color, "\n. ... raw event: size %d bytes\n", | ||
120 | event->header.size); | ||
121 | break; | ||
122 | case BINARY_PRINT_LINE_BEGIN: | ||
123 | printf("."); | ||
124 | break; | ||
125 | case BINARY_PRINT_ADDR: | ||
126 | color_fprintf(stdout, color, " %04x: ", val); | ||
127 | break; | ||
128 | case BINARY_PRINT_NUM_DATA: | ||
129 | color_fprintf(stdout, color, " %02x", val); | ||
130 | break; | ||
131 | case BINARY_PRINT_NUM_PAD: | ||
132 | color_fprintf(stdout, color, " "); | ||
133 | break; | ||
134 | case BINARY_PRINT_SEP: | ||
135 | color_fprintf(stdout, color, " "); | ||
136 | break; | ||
137 | case BINARY_PRINT_CHAR_DATA: | ||
138 | color_fprintf(stdout, color, "%c", | ||
139 | isprint(ch) ? ch : '.'); | ||
140 | break; | ||
141 | case BINARY_PRINT_CHAR_PAD: | ||
142 | color_fprintf(stdout, color, " "); | ||
143 | break; | ||
144 | case BINARY_PRINT_LINE_END: | ||
145 | color_fprintf(stdout, color, "\n"); | ||
146 | break; | ||
147 | case BINARY_PRINT_DATA_END: | ||
148 | printf("\n"); | ||
149 | break; | ||
150 | default: | ||
151 | break; | ||
152 | } | ||
153 | } | ||
154 | |||
109 | void trace_event(union perf_event *event) | 155 | void trace_event(union perf_event *event) |
110 | { | 156 | { |
111 | unsigned char *raw_event = (void *)event; | 157 | unsigned char *raw_event = (void *)event; |
112 | const char *color = PERF_COLOR_BLUE; | ||
113 | int i, j; | ||
114 | 158 | ||
115 | if (!dump_trace) | 159 | if (!dump_trace) |
116 | return; | 160 | return; |
117 | 161 | ||
118 | printf("."); | 162 | print_binary(raw_event, event->header.size, 16, |
119 | color_fprintf(stdout, color, "\n. ... raw event: size %d bytes\n", | 163 | trace_event_printer, event); |
120 | event->header.size); | ||
121 | |||
122 | for (i = 0; i < event->header.size; i++) { | ||
123 | if ((i & 15) == 0) { | ||
124 | printf("."); | ||
125 | color_fprintf(stdout, color, " %04x: ", i); | ||
126 | } | ||
127 | |||
128 | color_fprintf(stdout, color, " %02x", raw_event[i]); | ||
129 | |||
130 | if (((i & 15) == 15) || i == event->header.size-1) { | ||
131 | color_fprintf(stdout, color, " "); | ||
132 | for (j = 0; j < 15-(i & 15); j++) | ||
133 | color_fprintf(stdout, color, " "); | ||
134 | for (j = i & ~15; j <= i; j++) { | ||
135 | color_fprintf(stdout, color, "%c", | ||
136 | isprint(raw_event[j]) ? | ||
137 | raw_event[j] : '.'); | ||
138 | } | ||
139 | color_fprintf(stdout, color, "\n"); | ||
140 | } | ||
141 | } | ||
142 | printf(".\n"); | ||
143 | } | 164 | } |
144 | 165 | ||
145 | static struct debug_variable { | 166 | static struct debug_variable { |
diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c index 35b20dd454de..b7766c577b01 100644 --- a/tools/perf/util/util.c +++ b/tools/perf/util/util.c | |||
@@ -14,6 +14,7 @@ | |||
14 | #include <limits.h> | 14 | #include <limits.h> |
15 | #include <byteswap.h> | 15 | #include <byteswap.h> |
16 | #include <linux/kernel.h> | 16 | #include <linux/kernel.h> |
17 | #include <linux/log2.h> | ||
17 | #include <unistd.h> | 18 | #include <unistd.h> |
18 | #include "callchain.h" | 19 | #include "callchain.h" |
19 | #include "strlist.h" | 20 | #include "strlist.h" |
@@ -670,3 +671,39 @@ int fetch_current_timestamp(char *buf, size_t sz) | |||
670 | 671 | ||
671 | return 0; | 672 | return 0; |
672 | } | 673 | } |
674 | |||
675 | void print_binary(unsigned char *data, size_t len, | ||
676 | size_t bytes_per_line, print_binary_t printer, | ||
677 | void *extra) | ||
678 | { | ||
679 | size_t i, j, mask; | ||
680 | |||
681 | if (!printer) | ||
682 | return; | ||
683 | |||
684 | bytes_per_line = roundup_pow_of_two(bytes_per_line); | ||
685 | mask = bytes_per_line - 1; | ||
686 | |||
687 | printer(BINARY_PRINT_DATA_BEGIN, 0, extra); | ||
688 | for (i = 0; i < len; i++) { | ||
689 | if ((i & mask) == 0) { | ||
690 | printer(BINARY_PRINT_LINE_BEGIN, -1, extra); | ||
691 | printer(BINARY_PRINT_ADDR, i, extra); | ||
692 | } | ||
693 | |||
694 | printer(BINARY_PRINT_NUM_DATA, data[i], extra); | ||
695 | |||
696 | if (((i & mask) == mask) || i == len - 1) { | ||
697 | for (j = 0; j < mask-(i & mask); j++) | ||
698 | printer(BINARY_PRINT_NUM_PAD, -1, extra); | ||
699 | |||
700 | printer(BINARY_PRINT_SEP, i, extra); | ||
701 | for (j = i & ~mask; j <= i; j++) | ||
702 | printer(BINARY_PRINT_CHAR_DATA, data[j], extra); | ||
703 | for (j = 0; j < mask-(i & mask); j++) | ||
704 | printer(BINARY_PRINT_CHAR_PAD, i, extra); | ||
705 | printer(BINARY_PRINT_LINE_END, -1, extra); | ||
706 | } | ||
707 | } | ||
708 | printer(BINARY_PRINT_DATA_END, -1, extra); | ||
709 | } | ||
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h index 3dd04089e8be..7015019ee5fb 100644 --- a/tools/perf/util/util.h +++ b/tools/perf/util/util.h | |||
@@ -345,4 +345,24 @@ const char *perf_tip(const char *dirpath); | |||
345 | bool is_regular_file(const char *file); | 345 | bool is_regular_file(const char *file); |
346 | int fetch_current_timestamp(char *buf, size_t sz); | 346 | int fetch_current_timestamp(char *buf, size_t sz); |
347 | 347 | ||
348 | enum binary_printer_ops { | ||
349 | BINARY_PRINT_DATA_BEGIN, | ||
350 | BINARY_PRINT_LINE_BEGIN, | ||
351 | BINARY_PRINT_ADDR, | ||
352 | BINARY_PRINT_NUM_DATA, | ||
353 | BINARY_PRINT_NUM_PAD, | ||
354 | BINARY_PRINT_SEP, | ||
355 | BINARY_PRINT_CHAR_DATA, | ||
356 | BINARY_PRINT_CHAR_PAD, | ||
357 | BINARY_PRINT_LINE_END, | ||
358 | BINARY_PRINT_DATA_END, | ||
359 | }; | ||
360 | |||
361 | typedef void (*print_binary_t)(enum binary_printer_ops, | ||
362 | unsigned int val, | ||
363 | void *extra); | ||
364 | |||
365 | void print_binary(unsigned char *data, size_t len, | ||
366 | size_t bytes_per_line, print_binary_t printer, | ||
367 | void *extra); | ||
348 | #endif /* GIT_COMPAT_UTIL_H */ | 368 | #endif /* GIT_COMPAT_UTIL_H */ |