]>
git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - tools/perf/util/debug.c
1 /* For general debugging purposes */
9 #include <linux/time64.h>
19 bool dump_trace
= false, quiet
= false;
20 int debug_ordered_events
;
21 static int redirect_to_stderr
;
22 int debug_data_convert
;
24 int veprintf(int level
, int var
, const char *fmt
, va_list args
)
29 if (use_browser
>= 1 && !redirect_to_stderr
)
30 ui_helpline__vshow(fmt
, args
);
32 ret
= vfprintf(stderr
, fmt
, args
);
38 int eprintf(int level
, int var
, const char *fmt
, ...)
44 ret
= veprintf(level
, var
, fmt
, args
);
50 static int veprintf_time(u64 t
, const char *fmt
, va_list args
)
53 u64 secs
, usecs
, nsecs
= t
;
55 secs
= nsecs
/ NSEC_PER_SEC
;
56 nsecs
-= secs
* NSEC_PER_SEC
;
57 usecs
= nsecs
/ NSEC_PER_USEC
;
59 ret
= fprintf(stderr
, "[%13" PRIu64
".%06" PRIu64
"] ",
61 ret
+= vfprintf(stderr
, fmt
, args
);
65 int eprintf_time(int level
, int var
, u64 t
, const char *fmt
, ...)
72 ret
= veprintf_time(t
, fmt
, args
);
80 * Overloading libtraceevent standard info print
81 * function, display with -v in perf.
83 void pr_stat(const char *fmt
, ...)
88 veprintf(1, verbose
, fmt
, args
);
90 eprintf(1, verbose
, "\n");
93 int dump_printf(const char *fmt
, ...)
100 ret
= vprintf(fmt
, args
);
107 static void trace_event_printer(enum binary_printer_ops op
,
108 unsigned int val
, void *extra
)
110 const char *color
= PERF_COLOR_BLUE
;
111 union perf_event
*event
= (union perf_event
*)extra
;
112 unsigned char ch
= (unsigned char)val
;
115 case BINARY_PRINT_DATA_BEGIN
:
117 color_fprintf(stdout
, color
, "\n. ... raw event: size %d bytes\n",
120 case BINARY_PRINT_LINE_BEGIN
:
123 case BINARY_PRINT_ADDR
:
124 color_fprintf(stdout
, color
, " %04x: ", val
);
126 case BINARY_PRINT_NUM_DATA
:
127 color_fprintf(stdout
, color
, " %02x", val
);
129 case BINARY_PRINT_NUM_PAD
:
130 color_fprintf(stdout
, color
, " ");
132 case BINARY_PRINT_SEP
:
133 color_fprintf(stdout
, color
, " ");
135 case BINARY_PRINT_CHAR_DATA
:
136 color_fprintf(stdout
, color
, "%c",
137 isprint(ch
) ? ch
: '.');
139 case BINARY_PRINT_CHAR_PAD
:
140 color_fprintf(stdout
, color
, " ");
142 case BINARY_PRINT_LINE_END
:
143 color_fprintf(stdout
, color
, "\n");
145 case BINARY_PRINT_DATA_END
:
153 void trace_event(union perf_event
*event
)
155 unsigned char *raw_event
= (void *)event
;
160 print_binary(raw_event
, event
->header
.size
, 16,
161 trace_event_printer
, event
);
164 static struct debug_variable
{
167 } debug_variables
[] = {
168 { .name
= "verbose", .ptr
= &verbose
},
169 { .name
= "ordered-events", .ptr
= &debug_ordered_events
},
170 { .name
= "stderr", .ptr
= &redirect_to_stderr
},
171 { .name
= "data-convert", .ptr
= &debug_data_convert
},
175 int perf_debug_option(const char *str
)
177 struct debug_variable
*var
= &debug_variables
[0];
178 char *vstr
, *s
= strdup(str
);
181 vstr
= strchr(s
, '=');
186 if (!strcmp(s
, var
->name
))
192 pr_err("Unknown debug variable name '%s'\n", s
);
200 * Allow only values in range (0, 10),
203 v
= (v
< 0) || (v
> 10) ? 0 : v
;
214 int perf_quiet_option(void)
216 struct debug_variable
*var
= &debug_variables
[0];
218 /* disable all debug messages */
228 #define DEBUG_WRAPPER(__n, __l) \
229 static int pr_ ## __n ## _wrapper(const char *fmt, ...) \
234 va_start(args, fmt); \
235 ret = veprintf(__l, verbose, fmt, args); \
240 DEBUG_WRAPPER(warning
, 0);
241 DEBUG_WRAPPER(debug
, 1);
243 void perf_debug_setup(void)
245 libapi_set_print(pr_warning_wrapper
, pr_warning_wrapper
, pr_debug_wrapper
);