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" |
Frederic Weisbecker | 8f28827 | 2009-08-16 22:05:48 +0200 | [diff] [blame] | 14 | |
Arnaldo Carvalho de Melo | b44308f | 2010-10-26 15:20:09 -0200 | [diff] [blame] | 15 | int verbose; |
| 16 | bool dump_trace = false, quiet = false; |
Frederic Weisbecker | cd84c2a | 2009-08-12 10:03:49 +0200 | [diff] [blame] | 17 | |
Arnaldo Carvalho de Melo | 6beba7a | 2009-10-21 17:34:06 -0200 | [diff] [blame] | 18 | int eprintf(int level, const char *fmt, ...) |
Frederic Weisbecker | cd84c2a | 2009-08-12 10:03:49 +0200 | [diff] [blame] | 19 | { |
| 20 | va_list args; |
| 21 | int ret = 0; |
| 22 | |
Arnaldo Carvalho de Melo | 6beba7a | 2009-10-21 17:34:06 -0200 | [diff] [blame] | 23 | if (verbose >= level) { |
Frederic Weisbecker | cd84c2a | 2009-08-12 10:03:49 +0200 | [diff] [blame] | 24 | va_start(args, fmt); |
Arnaldo Carvalho de Melo | c4fe52a | 2010-05-27 09:53:40 -0300 | [diff] [blame] | 25 | if (use_browser > 0) |
Arnaldo Carvalho de Melo | 1e6dd07 | 2010-08-10 15:58:50 -0300 | [diff] [blame] | 26 | ret = ui_helpline__show_help(fmt, args); |
Arnaldo Carvalho de Melo | f9224c5 | 2010-03-11 20:12:44 -0300 | [diff] [blame] | 27 | else |
| 28 | ret = vfprintf(stderr, fmt, args); |
Frederic Weisbecker | cd84c2a | 2009-08-12 10:03:49 +0200 | [diff] [blame] | 29 | va_end(args); |
| 30 | } |
| 31 | |
| 32 | return ret; |
| 33 | } |
Frederic Weisbecker | 2cec19d | 2009-08-16 19:24:21 +0200 | [diff] [blame] | 34 | |
| 35 | int dump_printf(const char *fmt, ...) |
| 36 | { |
| 37 | va_list args; |
| 38 | int ret = 0; |
| 39 | |
| 40 | if (dump_trace) { |
| 41 | va_start(args, fmt); |
| 42 | ret = vprintf(fmt, args); |
| 43 | va_end(args); |
| 44 | } |
| 45 | |
| 46 | return ret; |
| 47 | } |
Frederic Weisbecker | 8f28827 | 2009-08-16 22:05:48 +0200 | [diff] [blame] | 48 | |
Arnaldo Carvalho de Melo | 068ffaa | 2010-11-27 02:41:01 -0200 | [diff] [blame] | 49 | #ifdef NO_NEWT_SUPPORT |
| 50 | void ui__warning(const char *format, ...) |
| 51 | { |
| 52 | va_list args; |
| 53 | |
| 54 | va_start(args, format); |
| 55 | vfprintf(stderr, format, args); |
| 56 | va_end(args); |
| 57 | } |
| 58 | #endif |
| 59 | |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 60 | void trace_event(union perf_event *event) |
Frederic Weisbecker | 8f28827 | 2009-08-16 22:05:48 +0200 | [diff] [blame] | 61 | { |
| 62 | unsigned char *raw_event = (void *)event; |
| 63 | const char *color = PERF_COLOR_BLUE; |
| 64 | int i, j; |
| 65 | |
| 66 | if (!dump_trace) |
| 67 | return; |
| 68 | |
Arnaldo Carvalho de Melo | 5b1c144 | 2010-11-30 17:48:53 -0200 | [diff] [blame] | 69 | printf("."); |
| 70 | color_fprintf(stdout, color, "\n. ... raw event: size %d bytes\n", |
| 71 | event->header.size); |
Frederic Weisbecker | 8f28827 | 2009-08-16 22:05:48 +0200 | [diff] [blame] | 72 | |
| 73 | for (i = 0; i < event->header.size; i++) { |
| 74 | if ((i & 15) == 0) { |
Arnaldo Carvalho de Melo | 5b1c144 | 2010-11-30 17:48:53 -0200 | [diff] [blame] | 75 | printf("."); |
| 76 | color_fprintf(stdout, color, " %04x: ", i); |
Frederic Weisbecker | 8f28827 | 2009-08-16 22:05:48 +0200 | [diff] [blame] | 77 | } |
| 78 | |
Arnaldo Carvalho de Melo | 5b1c144 | 2010-11-30 17:48:53 -0200 | [diff] [blame] | 79 | color_fprintf(stdout, color, " %02x", raw_event[i]); |
Frederic Weisbecker | 8f28827 | 2009-08-16 22:05:48 +0200 | [diff] [blame] | 80 | |
| 81 | if (((i & 15) == 15) || i == event->header.size-1) { |
Arnaldo Carvalho de Melo | 5b1c144 | 2010-11-30 17:48:53 -0200 | [diff] [blame] | 82 | color_fprintf(stdout, color, " "); |
Frederic Weisbecker | 8f28827 | 2009-08-16 22:05:48 +0200 | [diff] [blame] | 83 | for (j = 0; j < 15-(i & 15); j++) |
Arnaldo Carvalho de Melo | 5b1c144 | 2010-11-30 17:48:53 -0200 | [diff] [blame] | 84 | color_fprintf(stdout, color, " "); |
Andy Isaacson | 84c104a | 2010-06-11 19:44:04 -0700 | [diff] [blame] | 85 | for (j = i & ~15; j <= i; j++) { |
Arnaldo Carvalho de Melo | 5b1c144 | 2010-11-30 17:48:53 -0200 | [diff] [blame] | 86 | color_fprintf(stdout, color, "%c", |
| 87 | isprint(raw_event[j]) ? |
| 88 | raw_event[j] : '.'); |
Frederic Weisbecker | 8f28827 | 2009-08-16 22:05:48 +0200 | [diff] [blame] | 89 | } |
Arnaldo Carvalho de Melo | 5b1c144 | 2010-11-30 17:48:53 -0200 | [diff] [blame] | 90 | color_fprintf(stdout, color, "\n"); |
Frederic Weisbecker | 8f28827 | 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 | printf(".\n"); |
Frederic Weisbecker | 8f28827 | 2009-08-16 22:05:48 +0200 | [diff] [blame] | 94 | } |