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;
23 static int _eprintf(int level, int var, const char *fmt, va_list args)
29 ui_helpline__vshow(fmt, args);
31 ret = vfprintf(stderr, fmt, args);
37 int eprintf(int level, int var, const char *fmt, ...)
43 ret = _eprintf(level, var, fmt, args);
49 static int __eprintf_time(u64 t, const char *fmt, va_list args)
52 u64 secs, usecs, nsecs = t;
54 secs = nsecs / NSECS_PER_SEC;
55 nsecs -= secs * NSECS_PER_SEC;
56 usecs = nsecs / NSECS_PER_USEC;
58 ret = fprintf(stderr, "[%13" PRIu64 ".%06" PRIu64 "] ",
60 ret += vfprintf(stderr, fmt, args);
64 int eprintf_time(int level, int var, u64 t, const char *fmt, ...)
71 ret = __eprintf_time(t, fmt, args);
79 * Overloading libtraceevent standard info print
80 * function, display with -v in perf.
82 void pr_stat(const char *fmt, ...)
87 _eprintf(1, verbose, fmt, args);
89 eprintf(1, verbose, "\n");
92 int dump_printf(const char *fmt, ...)
99 ret = vprintf(fmt, args);
106 void trace_event(union perf_event *event)
108 unsigned char *raw_event = (void *)event;
109 const char *color = PERF_COLOR_BLUE;
116 color_fprintf(stdout, color, "\n. ... raw event: size %d bytes\n",
119 for (i = 0; i < event->header.size; i++) {
122 color_fprintf(stdout, color, " %04x: ", i);
125 color_fprintf(stdout, color, " %02x", raw_event[i]);
127 if (((i & 15) == 15) || i == event->header.size-1) {
128 color_fprintf(stdout, color, " ");
129 for (j = 0; j < 15-(i & 15); j++)
130 color_fprintf(stdout, color, " ");
131 for (j = i & ~15; j <= i; j++) {
132 color_fprintf(stdout, color, "%c",
133 isprint(raw_event[j]) ?
136 color_fprintf(stdout, color, "\n");
142 static struct debug_variable {
145 } debug_variables[] = {
146 { .name = "verbose", .ptr = &verbose },
147 { .name = "ordered-events", .ptr = &debug_ordered_events},
151 int perf_debug_option(const char *str)
153 struct debug_variable *var = &debug_variables[0];
154 char *vstr, *s = strdup(str);
157 vstr = strchr(s, '=');
162 if (!strcmp(s, var->name))
168 pr_err("Unknown debug variable name '%s'\n", s);
176 * Allow only values in range (0, 10),
179 v = (v < 0) || (v > 10) ? 0 : v;