Frederic Weisbecker | cd84c2a | 2009-08-12 10:03:49 +0200 | [diff] [blame] | 1 | /* For general debugging purposes */ |
| 2 | |
| 3 | #include "../perf.h" |
Frederic Weisbecker | 8f28827a | 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 | 8f28827a | 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 | 8f28827a | 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 | va_end(args); |
| 29 | } |
| 30 | |
| 31 | return ret; |
| 32 | } |
Frederic Weisbecker | 2cec19d | 2009-08-16 19:24:21 +0200 | [diff] [blame] | 33 | |
Jiri Olsa | f772abc | 2013-12-03 14:09:25 +0100 | [diff] [blame] | 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 | |
Frederic Weisbecker | 2cec19d | 2009-08-16 19:24:21 +0200 | [diff] [blame] | 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 | } |
Frederic Weisbecker | 8f28827a | 2009-08-16 22:05:48 +0200 | [diff] [blame] | 73 | |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 74 | void trace_event(union perf_event *event) |
Frederic Weisbecker | 8f28827a | 2009-08-16 22:05:48 +0200 | [diff] [blame] | 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 | |
Arnaldo Carvalho de Melo | 5b1c144 | 2010-11-30 17:48:53 -0200 | [diff] [blame] | 83 | printf("."); |
| 84 | color_fprintf(stdout, color, "\n. ... raw event: size %d bytes\n", |
| 85 | event->header.size); |
Frederic Weisbecker | 8f28827a | 2009-08-16 22:05:48 +0200 | [diff] [blame] | 86 | |
| 87 | for (i = 0; i < event->header.size; i++) { |
| 88 | if ((i & 15) == 0) { |
Arnaldo Carvalho de Melo | 5b1c144 | 2010-11-30 17:48:53 -0200 | [diff] [blame] | 89 | printf("."); |
| 90 | color_fprintf(stdout, color, " %04x: ", i); |
Frederic Weisbecker | 8f28827a | 2009-08-16 22:05:48 +0200 | [diff] [blame] | 91 | } |
| 92 | |
Arnaldo Carvalho de Melo | 5b1c144 | 2010-11-30 17:48:53 -0200 | [diff] [blame] | 93 | color_fprintf(stdout, color, " %02x", raw_event[i]); |
Frederic Weisbecker | 8f28827a | 2009-08-16 22:05:48 +0200 | [diff] [blame] | 94 | |
| 95 | if (((i & 15) == 15) || i == event->header.size-1) { |
Arnaldo Carvalho de Melo | 5b1c144 | 2010-11-30 17:48:53 -0200 | [diff] [blame] | 96 | color_fprintf(stdout, color, " "); |
Frederic Weisbecker | 8f28827a | 2009-08-16 22:05:48 +0200 | [diff] [blame] | 97 | for (j = 0; j < 15-(i & 15); j++) |
Arnaldo Carvalho de Melo | 5b1c144 | 2010-11-30 17:48:53 -0200 | [diff] [blame] | 98 | color_fprintf(stdout, color, " "); |
Andy Isaacson | 84c104a | 2010-06-11 19:44:04 -0700 | [diff] [blame] | 99 | for (j = i & ~15; j <= i; j++) { |
Arnaldo Carvalho de Melo | 5b1c144 | 2010-11-30 17:48:53 -0200 | [diff] [blame] | 100 | color_fprintf(stdout, color, "%c", |
| 101 | isprint(raw_event[j]) ? |
| 102 | raw_event[j] : '.'); |
Frederic Weisbecker | 8f28827a | 2009-08-16 22:05:48 +0200 | [diff] [blame] | 103 | } |
Arnaldo Carvalho de Melo | 5b1c144 | 2010-11-30 17:48:53 -0200 | [diff] [blame] | 104 | color_fprintf(stdout, color, "\n"); |
Frederic Weisbecker | 8f28827a | 2009-08-16 22:05:48 +0200 | [diff] [blame] | 105 | } |
| 106 | } |
Arnaldo Carvalho de Melo | 5b1c144 | 2010-11-30 17:48:53 -0200 | [diff] [blame] | 107 | printf(".\n"); |
Frederic Weisbecker | 8f28827a | 2009-08-16 22:05:48 +0200 | [diff] [blame] | 108 | } |