Frederic Weisbecker | cd84c2a | 2009-08-12 10:03:49 +0200 | [diff] [blame] | 1 | /* For general debugging purposes */ |
| 2 | |
| 3 | #include "../perf.h" |
Frederic Weisbecker | 8f28827 | 2009-08-16 22:05:48 +0200 | [diff] [blame] | 4 | |
Frederic Weisbecker | cd84c2a | 2009-08-12 10:03:49 +0200 | [diff] [blame] | 5 | #include <string.h> |
| 6 | #include <stdarg.h> |
| 7 | #include <stdio.h> |
| 8 | |
Arnaldo Carvalho de Melo | f9224c5 | 2010-03-11 20:12:44 -0300 | [diff] [blame] | 9 | #include "cache.h" |
Frederic Weisbecker | 8f28827 | 2009-08-16 22:05:48 +0200 | [diff] [blame] | 10 | #include "color.h" |
| 11 | #include "event.h" |
| 12 | #include "debug.h" |
Arnaldo Carvalho de Melo | 4a58e61 | 2009-12-27 21:37:00 -0200 | [diff] [blame] | 13 | #include "util.h" |
Namhyung Kim | 16ad2ff | 2012-05-07 14:09:02 +0900 | [diff] [blame] | 14 | #include "target.h" |
Frederic Weisbecker | 8f28827 | 2009-08-16 22:05:48 +0200 | [diff] [blame] | 15 | |
Arnaldo Carvalho de Melo | b44308f | 2010-10-26 15:20:09 -0200 | [diff] [blame] | 16 | int verbose; |
| 17 | bool dump_trace = false, quiet = false; |
Frederic Weisbecker | cd84c2a | 2009-08-12 10:03:49 +0200 | [diff] [blame] | 18 | |
Jiri Olsa | f772abc | 2013-12-03 14:09:25 +0100 | [diff] [blame] | 19 | static int _eprintf(int level, const char *fmt, va_list args) |
Frederic Weisbecker | cd84c2a | 2009-08-12 10:03:49 +0200 | [diff] [blame] | 20 | { |
Frederic Weisbecker | cd84c2a | 2009-08-12 10:03:49 +0200 | [diff] [blame] | 21 | int ret = 0; |
| 22 | |
Arnaldo Carvalho de Melo | 6beba7a | 2009-10-21 17:34:06 -0200 | [diff] [blame] | 23 | if (verbose >= level) { |
Arnaldo Carvalho de Melo | 044c4f8f | 2012-11-29 16:51:01 -0300 | [diff] [blame] | 24 | if (use_browser >= 1) |
Namhyung Kim | b56e533 | 2012-11-15 01:47:41 +0900 | [diff] [blame] | 25 | ui_helpline__vshow(fmt, args); |
Arnaldo Carvalho de Melo | f9224c5 | 2010-03-11 20:12:44 -0300 | [diff] [blame] | 26 | else |
| 27 | ret = vfprintf(stderr, fmt, args); |
Frederic Weisbecker | cd84c2a | 2009-08-12 10:03:49 +0200 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | return ret; |
| 31 | } |
Frederic Weisbecker | 2cec19d | 2009-08-16 19:24:21 +0200 | [diff] [blame] | 32 | |
Jiri Olsa | f772abc | 2013-12-03 14:09:25 +0100 | [diff] [blame] | 33 | int eprintf(int level, const char *fmt, ...) |
| 34 | { |
| 35 | va_list args; |
| 36 | int ret; |
| 37 | |
| 38 | va_start(args, fmt); |
| 39 | ret = _eprintf(level, fmt, args); |
| 40 | va_end(args); |
| 41 | |
| 42 | return ret; |
| 43 | } |
| 44 | |
| 45 | /* |
| 46 | * Overloading libtraceevent standard info print |
| 47 | * function, display with -v in perf. |
| 48 | */ |
| 49 | void pr_stat(const char *fmt, ...) |
| 50 | { |
| 51 | va_list args; |
| 52 | |
| 53 | va_start(args, fmt); |
| 54 | _eprintf(1, fmt, args); |
| 55 | va_end(args); |
| 56 | eprintf(1, "\n"); |
| 57 | } |
| 58 | |
Frederic Weisbecker | 2cec19d | 2009-08-16 19:24:21 +0200 | [diff] [blame] | 59 | int dump_printf(const char *fmt, ...) |
| 60 | { |
| 61 | va_list args; |
| 62 | int ret = 0; |
| 63 | |
| 64 | if (dump_trace) { |
| 65 | va_start(args, fmt); |
| 66 | ret = vprintf(fmt, args); |
| 67 | va_end(args); |
| 68 | } |
| 69 | |
| 70 | return ret; |
| 71 | } |
Frederic Weisbecker | 8f28827 | 2009-08-16 22:05:48 +0200 | [diff] [blame] | 72 | |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 73 | void trace_event(union perf_event *event) |
Frederic Weisbecker | 8f28827 | 2009-08-16 22:05:48 +0200 | [diff] [blame] | 74 | { |
| 75 | unsigned char *raw_event = (void *)event; |
| 76 | const char *color = PERF_COLOR_BLUE; |
| 77 | int i, j; |
| 78 | |
| 79 | if (!dump_trace) |
| 80 | return; |
| 81 | |
Arnaldo Carvalho de Melo | 5b1c144 | 2010-11-30 17:48:53 -0200 | [diff] [blame] | 82 | printf("."); |
| 83 | color_fprintf(stdout, color, "\n. ... raw event: size %d bytes\n", |
| 84 | event->header.size); |
Frederic Weisbecker | 8f28827 | 2009-08-16 22:05:48 +0200 | [diff] [blame] | 85 | |
| 86 | for (i = 0; i < event->header.size; i++) { |
| 87 | if ((i & 15) == 0) { |
Arnaldo Carvalho de Melo | 5b1c144 | 2010-11-30 17:48:53 -0200 | [diff] [blame] | 88 | printf("."); |
| 89 | color_fprintf(stdout, color, " %04x: ", i); |
Frederic Weisbecker | 8f28827 | 2009-08-16 22:05:48 +0200 | [diff] [blame] | 90 | } |
| 91 | |
Arnaldo Carvalho de Melo | 5b1c144 | 2010-11-30 17:48:53 -0200 | [diff] [blame] | 92 | color_fprintf(stdout, color, " %02x", raw_event[i]); |
Frederic Weisbecker | 8f28827 | 2009-08-16 22:05:48 +0200 | [diff] [blame] | 93 | |
| 94 | if (((i & 15) == 15) || i == event->header.size-1) { |
Arnaldo Carvalho de Melo | 5b1c144 | 2010-11-30 17:48:53 -0200 | [diff] [blame] | 95 | color_fprintf(stdout, color, " "); |
Frederic Weisbecker | 8f28827 | 2009-08-16 22:05:48 +0200 | [diff] [blame] | 96 | for (j = 0; j < 15-(i & 15); j++) |
Arnaldo Carvalho de Melo | 5b1c144 | 2010-11-30 17:48:53 -0200 | [diff] [blame] | 97 | color_fprintf(stdout, color, " "); |
Andy Isaacson | 84c104a | 2010-06-11 19:44:04 -0700 | [diff] [blame] | 98 | for (j = i & ~15; j <= i; j++) { |
Arnaldo Carvalho de Melo | 5b1c144 | 2010-11-30 17:48:53 -0200 | [diff] [blame] | 99 | color_fprintf(stdout, color, "%c", |
| 100 | isprint(raw_event[j]) ? |
| 101 | raw_event[j] : '.'); |
Frederic Weisbecker | 8f28827 | 2009-08-16 22:05:48 +0200 | [diff] [blame] | 102 | } |
Arnaldo Carvalho de Melo | 5b1c144 | 2010-11-30 17:48:53 -0200 | [diff] [blame] | 103 | color_fprintf(stdout, color, "\n"); |
Frederic Weisbecker | 8f28827 | 2009-08-16 22:05:48 +0200 | [diff] [blame] | 104 | } |
| 105 | } |
Arnaldo Carvalho de Melo | 5b1c144 | 2010-11-30 17:48:53 -0200 | [diff] [blame] | 106 | printf(".\n"); |
Frederic Weisbecker | 8f28827 | 2009-08-16 22:05:48 +0200 | [diff] [blame] | 107 | } |