1 /* For general debugging purposes */
10 #include <linux/time64.h>
16 #include "print_binary.h"
20 #include "sane_ctype.h"
23 bool dump_trace = false, quiet = false;
24 int debug_ordered_events;
25 static int redirect_to_stderr;
26 int debug_data_convert;
28 int veprintf(int level, int var, const char *fmt, va_list args)
33 if (use_browser >= 1 && !redirect_to_stderr)
34 ui_helpline__vshow(fmt, args);
36 ret = vfprintf(stderr, fmt, args);
42 int eprintf(int level, int var, const char *fmt, ...)
48 ret = veprintf(level, var, fmt, args);
54 static int veprintf_time(u64 t, const char *fmt, va_list args)
57 u64 secs, usecs, nsecs = t;
59 secs = nsecs / NSEC_PER_SEC;
60 nsecs -= secs * NSEC_PER_SEC;
61 usecs = nsecs / NSEC_PER_USEC;
63 ret = fprintf(stderr, "[%13" PRIu64 ".%06" PRIu64 "] ",
65 ret += vfprintf(stderr, fmt, args);
69 int eprintf_time(int level, int var, u64 t, const char *fmt, ...)
76 ret = veprintf_time(t, fmt, args);
84 * Overloading libtraceevent standard info print
85 * function, display with -v in perf.
87 void pr_stat(const char *fmt, ...)
92 veprintf(1, verbose, fmt, args);
94 eprintf(1, verbose, "\n");
97 int dump_printf(const char *fmt, ...)
104 ret = vprintf(fmt, args);
111 static void trace_event_printer(enum binary_printer_ops op,
112 unsigned int val, void *extra)
114 const char *color = PERF_COLOR_BLUE;
115 union perf_event *event = (union perf_event *)extra;
116 unsigned char ch = (unsigned char)val;
119 case BINARY_PRINT_DATA_BEGIN:
121 color_fprintf(stdout, color, "\n. ... raw event: size %d bytes\n",
124 case BINARY_PRINT_LINE_BEGIN:
127 case BINARY_PRINT_ADDR:
128 color_fprintf(stdout, color, " %04x: ", val);
130 case BINARY_PRINT_NUM_DATA:
131 color_fprintf(stdout, color, " %02x", val);
133 case BINARY_PRINT_NUM_PAD:
134 color_fprintf(stdout, color, " ");
136 case BINARY_PRINT_SEP:
137 color_fprintf(stdout, color, " ");
139 case BINARY_PRINT_CHAR_DATA:
140 color_fprintf(stdout, color, "%c",
141 isprint(ch) ? ch : '.');
143 case BINARY_PRINT_CHAR_PAD:
144 color_fprintf(stdout, color, " ");
146 case BINARY_PRINT_LINE_END:
147 color_fprintf(stdout, color, "\n");
149 case BINARY_PRINT_DATA_END:
157 void trace_event(union perf_event *event)
159 unsigned char *raw_event = (void *)event;
164 print_binary(raw_event, event->header.size, 16,
165 trace_event_printer, event);
168 static struct debug_variable {
171 } debug_variables[] = {
172 { .name = "verbose", .ptr = &verbose },
173 { .name = "ordered-events", .ptr = &debug_ordered_events},
174 { .name = "stderr", .ptr = &redirect_to_stderr},
175 { .name = "data-convert", .ptr = &debug_data_convert },
179 int perf_debug_option(const char *str)
181 struct debug_variable *var = &debug_variables[0];
182 char *vstr, *s = strdup(str);
185 vstr = strchr(s, '=');
190 if (!strcmp(s, var->name))
196 pr_err("Unknown debug variable name '%s'\n", s);
204 * Allow only values in range (0, 10),
207 v = (v < 0) || (v > 10) ? 0 : v;
218 int perf_quiet_option(void)
220 struct debug_variable *var = &debug_variables[0];
222 /* disable all debug messages */
232 #define DEBUG_WRAPPER(__n, __l) \
233 static int pr_ ## __n ## _wrapper(const char *fmt, ...) \
238 va_start(args, fmt); \
239 ret = veprintf(__l, verbose, fmt, args); \
244 DEBUG_WRAPPER(warning, 0);
245 DEBUG_WRAPPER(debug, 1);
247 void perf_debug_setup(void)
249 libapi_set_print(pr_warning_wrapper, pr_warning_wrapper, pr_debug_wrapper);