1 /* For general debugging purposes */
16 #define NSECS_PER_SEC 1000000000ULL
17 #define NSECS_PER_USEC 1000ULL
20 bool dump_trace
= false, quiet
= false;
21 int debug_ordered_events
;
22 static int redirect_to_stderr
;
23 int debug_data_convert
;
25 static int _eprintf(int level
, int var
, const char *fmt
, va_list args
)
30 if (use_browser
>= 1 && !redirect_to_stderr
)
31 ui_helpline__vshow(fmt
, args
);
33 ret
= vfprintf(stderr
, fmt
, args
);
39 int eprintf(int level
, int var
, const char *fmt
, ...)
45 ret
= _eprintf(level
, var
, fmt
, args
);
51 static int __eprintf_time(u64 t
, const char *fmt
, va_list args
)
54 u64 secs
, usecs
, nsecs
= t
;
56 secs
= nsecs
/ NSECS_PER_SEC
;
57 nsecs
-= secs
* NSECS_PER_SEC
;
58 usecs
= nsecs
/ NSECS_PER_USEC
;
60 ret
= fprintf(stderr
, "[%13" PRIu64
".%06" PRIu64
"] ",
62 ret
+= vfprintf(stderr
, fmt
, args
);
66 int eprintf_time(int level
, int var
, u64 t
, const char *fmt
, ...)
73 ret
= __eprintf_time(t
, fmt
, args
);
81 * Overloading libtraceevent standard info print
82 * function, display with -v in perf.
84 void pr_stat(const char *fmt
, ...)
89 _eprintf(1, verbose
, fmt
, args
);
91 eprintf(1, verbose
, "\n");
94 int dump_printf(const char *fmt
, ...)
101 ret
= vprintf(fmt
, args
);
108 void trace_event(union perf_event
*event
)
110 unsigned char *raw_event
= (void *)event
;
111 const char *color
= PERF_COLOR_BLUE
;
118 color_fprintf(stdout
, color
, "\n. ... raw event: size %d bytes\n",
121 for (i
= 0; i
< event
->header
.size
; i
++) {
124 color_fprintf(stdout
, color
, " %04x: ", i
);
127 color_fprintf(stdout
, color
, " %02x", raw_event
[i
]);
129 if (((i
& 15) == 15) || i
== event
->header
.size
-1) {
130 color_fprintf(stdout
, color
, " ");
131 for (j
= 0; j
< 15-(i
& 15); j
++)
132 color_fprintf(stdout
, color
, " ");
133 for (j
= i
& ~15; j
<= i
; j
++) {
134 color_fprintf(stdout
, color
, "%c",
135 isprint(raw_event
[j
]) ?
138 color_fprintf(stdout
, color
, "\n");
144 static struct debug_variable
{
147 } debug_variables
[] = {
148 { .name
= "verbose", .ptr
= &verbose
},
149 { .name
= "ordered-events", .ptr
= &debug_ordered_events
},
150 { .name
= "stderr", .ptr
= &redirect_to_stderr
},
151 { .name
= "data-convert", .ptr
= &debug_data_convert
},
155 int perf_debug_option(const char *str
)
157 struct debug_variable
*var
= &debug_variables
[0];
158 char *vstr
, *s
= strdup(str
);
161 vstr
= strchr(s
, '=');
166 if (!strcmp(s
, var
->name
))
172 pr_err("Unknown debug variable name '%s'\n", s
);
180 * Allow only values in range (0, 10),
183 v
= (v
< 0) || (v
> 10) ? 0 : v
;