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 veprintf(int level
, int var
, const char *fmt
, va_list args
)
41 return _eprintf(level
, var
, fmt
, args
);
44 int eprintf(int level
, int var
, const char *fmt
, ...)
50 ret
= _eprintf(level
, var
, fmt
, args
);
56 static int __eprintf_time(u64 t
, const char *fmt
, va_list args
)
59 u64 secs
, usecs
, nsecs
= t
;
61 secs
= nsecs
/ NSECS_PER_SEC
;
62 nsecs
-= secs
* NSECS_PER_SEC
;
63 usecs
= nsecs
/ NSECS_PER_USEC
;
65 ret
= fprintf(stderr
, "[%13" PRIu64
".%06" PRIu64
"] ",
67 ret
+= vfprintf(stderr
, fmt
, args
);
71 int eprintf_time(int level
, int var
, u64 t
, const char *fmt
, ...)
78 ret
= __eprintf_time(t
, fmt
, args
);
86 * Overloading libtraceevent standard info print
87 * function, display with -v in perf.
89 void pr_stat(const char *fmt
, ...)
94 _eprintf(1, verbose
, fmt
, args
);
96 eprintf(1, verbose
, "\n");
99 int dump_printf(const char *fmt
, ...)
106 ret
= vprintf(fmt
, args
);
113 void trace_event(union perf_event
*event
)
115 unsigned char *raw_event
= (void *)event
;
116 const char *color
= PERF_COLOR_BLUE
;
123 color_fprintf(stdout
, color
, "\n. ... raw event: size %d bytes\n",
126 for (i
= 0; i
< event
->header
.size
; i
++) {
129 color_fprintf(stdout
, color
, " %04x: ", i
);
132 color_fprintf(stdout
, color
, " %02x", raw_event
[i
]);
134 if (((i
& 15) == 15) || i
== event
->header
.size
-1) {
135 color_fprintf(stdout
, color
, " ");
136 for (j
= 0; j
< 15-(i
& 15); j
++)
137 color_fprintf(stdout
, color
, " ");
138 for (j
= i
& ~15; j
<= i
; j
++) {
139 color_fprintf(stdout
, color
, "%c",
140 isprint(raw_event
[j
]) ?
143 color_fprintf(stdout
, color
, "\n");
149 static struct debug_variable
{
152 } debug_variables
[] = {
153 { .name
= "verbose", .ptr
= &verbose
},
154 { .name
= "ordered-events", .ptr
= &debug_ordered_events
},
155 { .name
= "stderr", .ptr
= &redirect_to_stderr
},
156 { .name
= "data-convert", .ptr
= &debug_data_convert
},
160 int perf_debug_option(const char *str
)
162 struct debug_variable
*var
= &debug_variables
[0];
163 char *vstr
, *s
= strdup(str
);
166 vstr
= strchr(s
, '=');
171 if (!strcmp(s
, var
->name
))
177 pr_err("Unknown debug variable name '%s'\n", s
);
185 * Allow only values in range (0, 10),
188 v
= (v
< 0) || (v
> 10) ? 0 : v
;