perf tests: Move test__syscall_open_tp_fields into separate object
[linux-2.6.git] / tools / perf / util / debug.c
blob03f830b48148a7b41f0c4bb1b59b7f1614db035c
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 == 1)
27 ret = ui_helpline__show_help(fmt, args);
28 else if (use_browser == 2)
29 ret = perf_gtk__show_helpline(fmt, args);
30 else
31 ret = vfprintf(stderr, fmt, args);
32 va_end(args);
35 return ret;
38 int dump_printf(const char *fmt, ...)
40 va_list args;
41 int ret = 0;
43 if (dump_trace) {
44 va_start(args, fmt);
45 ret = vprintf(fmt, args);
46 va_end(args);
49 return ret;
52 #if !defined(NEWT_SUPPORT) && !defined(GTK2_SUPPORT)
53 int ui__warning(const char *format, ...)
55 va_list args;
57 va_start(args, format);
58 vfprintf(stderr, format, args);
59 va_end(args);
60 return 0;
62 #endif
64 int ui__error_paranoid(void)
66 return ui__error("Permission error - are you root?\n"
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");
74 void trace_event(union perf_event *event)
76 unsigned char *raw_event = (void *)event;
77 const char *color = PERF_COLOR_BLUE;
78 int i, j;
80 if (!dump_trace)
81 return;
83 printf(".");
84 color_fprintf(stdout, color, "\n. ... raw event: size %d bytes\n",
85 event->header.size);
87 for (i = 0; i < event->header.size; i++) {
88 if ((i & 15) == 0) {
89 printf(".");
90 color_fprintf(stdout, color, " %04x: ", i);
93 color_fprintf(stdout, color, " %02x", raw_event[i]);
95 if (((i & 15) == 15) || i == event->header.size-1) {
96 color_fprintf(stdout, color, " ");
97 for (j = 0; j < 15-(i & 15); j++)
98 color_fprintf(stdout, color, " ");
99 for (j = i & ~15; j <= i; j++) {
100 color_fprintf(stdout, color, "%c",
101 isprint(raw_event[j]) ?
102 raw_event[j] : '.');
104 color_fprintf(stdout, color, "\n");
107 printf(".\n");