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 | |
Arnaldo Carvalho de Melo | 6beba7a | 2009-10-21 17:34:06 -0200 | [diff] [blame] | 19 | int eprintf(int level, const char *fmt, ...) |
Frederic Weisbecker | cd84c2a | 2009-08-12 10:03:49 +0200 | [diff] [blame] | 20 | { |
| 21 | va_list args; |
| 22 | int ret = 0; |
| 23 | |
Arnaldo Carvalho de Melo | 6beba7a | 2009-10-21 17:34:06 -0200 | [diff] [blame] | 24 | if (verbose >= level) { |
Frederic Weisbecker | cd84c2a | 2009-08-12 10:03:49 +0200 | [diff] [blame] | 25 | va_start(args, fmt); |
Namhyung Kim | 0985a94 | 2012-08-16 17:14:54 +0900 | [diff] [blame] | 26 | if (use_browser == 1) |
Arnaldo Carvalho de Melo | 1e6dd07 | 2010-08-10 15:58:50 -0300 | [diff] [blame] | 27 | ret = ui_helpline__show_help(fmt, args); |
Namhyung Kim | 0985a94 | 2012-08-16 17:14:54 +0900 | [diff] [blame] | 28 | else if (use_browser == 2) |
| 29 | ret = perf_gtk__show_helpline(fmt, args); |
Arnaldo Carvalho de Melo | f9224c5 | 2010-03-11 20:12:44 -0300 | [diff] [blame] | 30 | else |
| 31 | ret = vfprintf(stderr, fmt, args); |
Frederic Weisbecker | cd84c2a | 2009-08-12 10:03:49 +0200 | [diff] [blame] | 32 | va_end(args); |
| 33 | } |
| 34 | |
| 35 | return ret; |
| 36 | } |
Frederic Weisbecker | 2cec19d | 2009-08-16 19:24:21 +0200 | [diff] [blame] | 37 | |
| 38 | int dump_printf(const char *fmt, ...) |
| 39 | { |
| 40 | va_list args; |
| 41 | int ret = 0; |
| 42 | |
| 43 | if (dump_trace) { |
| 44 | va_start(args, fmt); |
| 45 | ret = vprintf(fmt, args); |
| 46 | va_end(args); |
| 47 | } |
| 48 | |
| 49 | return ret; |
| 50 | } |
Frederic Weisbecker | 8f28827 | 2009-08-16 22:05:48 +0200 | [diff] [blame] | 51 | |
Namhyung Kim | ba47a14 | 2012-05-29 13:22:58 +0900 | [diff] [blame] | 52 | #if defined(NO_NEWT_SUPPORT) && defined(NO_GTK2_SUPPORT) |
Arnaldo Carvalho de Melo | 4610e41 | 2011-10-26 12:04:37 -0200 | [diff] [blame] | 53 | int ui__warning(const char *format, ...) |
Arnaldo Carvalho de Melo | 068ffaa | 2010-11-27 02:41:01 -0200 | [diff] [blame] | 54 | { |
| 55 | va_list args; |
| 56 | |
| 57 | va_start(args, format); |
| 58 | vfprintf(stderr, format, args); |
| 59 | va_end(args); |
Arnaldo Carvalho de Melo | 4610e41 | 2011-10-26 12:04:37 -0200 | [diff] [blame] | 60 | return 0; |
Arnaldo Carvalho de Melo | 068ffaa | 2010-11-27 02:41:01 -0200 | [diff] [blame] | 61 | } |
| 62 | #endif |
| 63 | |
Arnaldo Carvalho de Melo | 4610e41 | 2011-10-26 12:04:37 -0200 | [diff] [blame] | 64 | int ui__error_paranoid(void) |
Arnaldo Carvalho de Melo | c286c41 | 2011-03-28 09:50:11 -0300 | [diff] [blame] | 65 | { |
Arnaldo Carvalho de Melo | 4610e41 | 2011-10-26 12:04:37 -0200 | [diff] [blame] | 66 | return ui__error("Permission error - are you root?\n" |
Arnaldo Carvalho de Melo | c286c41 | 2011-03-28 09:50:11 -0300 | [diff] [blame] | 67 | "Consider tweaking /proc/sys/kernel/perf_event_paranoid:\n" |
| 68 | " -1 - Not paranoid at all\n" |
| 69 | " 0 - Disallow raw tracepoint access for unpriv\n" |
| 70 | " 1 - Disallow cpu events for unpriv\n" |
| 71 | " 2 - Disallow kernel profiling for unpriv\n"); |
| 72 | } |
| 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 | 8f28827 | 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 | 8f28827 | 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 | 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 | color_fprintf(stdout, color, " %02x", raw_event[i]); |
Frederic Weisbecker | 8f28827 | 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 | 8f28827 | 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 | 8f28827 | 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 | 8f28827 | 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 | 8f28827 | 2009-08-16 22:05:48 +0200 | [diff] [blame] | 108 | } |