perf tools: Change strlist to use the new rblist
[linux-2.6/btrfs-unstable.git] / tools / perf / util / debug.c
blob4dfe0bb3c3225455e4f0ff3b1cb74a386352db3c
1 /* For general debugging purposes */
3 #include "../perf.h"
5 #include <string.h>
6 #include <stdarg.h>
7 #include <stdio.h>
9 #include "cache.h"
10 #include "color.h"
11 #include "event.h"
12 #include "debug.h"
13 #include "util.h"
14 #include "target.h"
16 int verbose;
17 bool dump_trace = false, quiet = false;
19 int eprintf(int level, const char *fmt, ...)
21 va_list args;
22 int ret = 0;
24 if (verbose >= level) {
25 va_start(args, fmt);
26 if (use_browser > 0)
27 ret = ui_helpline__show_help(fmt, args);
28 else
29 ret = vfprintf(stderr, fmt, args);
30 va_end(args);
33 return ret;
36 int dump_printf(const char *fmt, ...)
38 va_list args;
39 int ret = 0;
41 if (dump_trace) {
42 va_start(args, fmt);
43 ret = vprintf(fmt, args);
44 va_end(args);
47 return ret;
50 #if defined(NO_NEWT_SUPPORT) && defined(NO_GTK2_SUPPORT)
51 int ui__warning(const char *format, ...)
53 va_list args;
55 va_start(args, format);
56 vfprintf(stderr, format, args);
57 va_end(args);
58 return 0;
60 #endif
62 int ui__error_paranoid(void)
64 return ui__error("Permission error - are you root?\n"
65 "Consider tweaking /proc/sys/kernel/perf_event_paranoid:\n"
66 " -1 - Not paranoid at all\n"
67 " 0 - Disallow raw tracepoint access for unpriv\n"
68 " 1 - Disallow cpu events for unpriv\n"
69 " 2 - Disallow kernel profiling for unpriv\n");
72 void trace_event(union perf_event *event)
74 unsigned char *raw_event = (void *)event;
75 const char *color = PERF_COLOR_BLUE;
76 int i, j;
78 if (!dump_trace)
79 return;
81 printf(".");
82 color_fprintf(stdout, color, "\n. ... raw event: size %d bytes\n",
83 event->header.size);
85 for (i = 0; i < event->header.size; i++) {
86 if ((i & 15) == 0) {
87 printf(".");
88 color_fprintf(stdout, color, " %04x: ", i);
91 color_fprintf(stdout, color, " %02x", raw_event[i]);
93 if (((i & 15) == 15) || i == event->header.size-1) {
94 color_fprintf(stdout, color, " ");
95 for (j = 0; j < 15-(i & 15); j++)
96 color_fprintf(stdout, color, " ");
97 for (j = i & ~15; j <= i; j++) {
98 color_fprintf(stdout, color, "%c",
99 isprint(raw_event[j]) ?
100 raw_event[j] : '.');
102 color_fprintf(stdout, color, "\n");
105 printf(".\n");