fix a kmap leak in virtio_console
[linux/fpc-iii.git] / tools / perf / util / debug.c
blob299b55586502feb8fc57da0e5b452e30d9dfbe9b
1 /* For general debugging purposes */
3 #include "../perf.h"
5 #include <string.h>
6 #include <stdarg.h>
7 #include <stdio.h>
9 #include "cache.h"
10 #include "color.h"
11 #include "event.h"
12 #include "debug.h"
13 #include "util.h"
14 #include "target.h"
16 int verbose;
17 bool dump_trace = false, quiet = false;
19 static int _eprintf(int level, const char *fmt, va_list args)
21 int ret = 0;
23 if (verbose >= level) {
24 if (use_browser >= 1)
25 ui_helpline__vshow(fmt, args);
26 else
27 ret = vfprintf(stderr, fmt, args);
30 return ret;
33 int eprintf(int level, const char *fmt, ...)
35 va_list args;
36 int ret;
38 va_start(args, fmt);
39 ret = _eprintf(level, fmt, args);
40 va_end(args);
42 return ret;
46 * Overloading libtraceevent standard info print
47 * function, display with -v in perf.
49 void pr_stat(const char *fmt, ...)
51 va_list args;
53 va_start(args, fmt);
54 _eprintf(1, fmt, args);
55 va_end(args);
56 eprintf(1, "\n");
59 int dump_printf(const char *fmt, ...)
61 va_list args;
62 int ret = 0;
64 if (dump_trace) {
65 va_start(args, fmt);
66 ret = vprintf(fmt, args);
67 va_end(args);
70 return ret;
73 void trace_event(union perf_event *event)
75 unsigned char *raw_event = (void *)event;
76 const char *color = PERF_COLOR_BLUE;
77 int i, j;
79 if (!dump_trace)
80 return;
82 printf(".");
83 color_fprintf(stdout, color, "\n. ... raw event: size %d bytes\n",
84 event->header.size);
86 for (i = 0; i < event->header.size; i++) {
87 if ((i & 15) == 0) {
88 printf(".");
89 color_fprintf(stdout, color, " %04x: ", i);
92 color_fprintf(stdout, color, " %02x", raw_event[i]);
94 if (((i & 15) == 15) || i == event->header.size-1) {
95 color_fprintf(stdout, color, " ");
96 for (j = 0; j < 15-(i & 15); j++)
97 color_fprintf(stdout, color, " ");
98 for (j = i & ~15; j <= i; j++) {
99 color_fprintf(stdout, color, "%c",
100 isprint(raw_event[j]) ?
101 raw_event[j] : '.');
103 color_fprintf(stdout, color, "\n");
106 printf(".\n");