perf tools: Move pr_* debug macros into debug object
[deliverable/linux.git] / tools / perf / util / debug.c
1 /* For general debugging purposes */
2
3 #include "../perf.h"
4
5 #include <string.h>
6 #include <stdarg.h>
7 #include <stdio.h>
8
9 #include "cache.h"
10 #include "color.h"
11 #include "event.h"
12 #include "debug.h"
13 #include "util.h"
14 #include "target.h"
15
16 int verbose;
17 bool dump_trace = false, quiet = false;
18
19 static int _eprintf(int level, const char *fmt, va_list args)
20 {
21 int ret = 0;
22
23 if (verbose >= level) {
24 if (use_browser >= 1)
25 ui_helpline__vshow(fmt, args);
26 else
27 ret = vfprintf(stderr, fmt, args);
28 }
29
30 return ret;
31 }
32
33 int eprintf(int level, const char *fmt, ...)
34 {
35 va_list args;
36 int ret;
37
38 va_start(args, fmt);
39 ret = _eprintf(level, fmt, args);
40 va_end(args);
41
42 return ret;
43 }
44
45 /*
46 * Overloading libtraceevent standard info print
47 * function, display with -v in perf.
48 */
49 void pr_stat(const char *fmt, ...)
50 {
51 va_list args;
52
53 va_start(args, fmt);
54 _eprintf(1, fmt, args);
55 va_end(args);
56 eprintf(1, "\n");
57 }
58
59 int dump_printf(const char *fmt, ...)
60 {
61 va_list args;
62 int ret = 0;
63
64 if (dump_trace) {
65 va_start(args, fmt);
66 ret = vprintf(fmt, args);
67 va_end(args);
68 }
69
70 return ret;
71 }
72
73 void trace_event(union perf_event *event)
74 {
75 unsigned char *raw_event = (void *)event;
76 const char *color = PERF_COLOR_BLUE;
77 int i, j;
78
79 if (!dump_trace)
80 return;
81
82 printf(".");
83 color_fprintf(stdout, color, "\n. ... raw event: size %d bytes\n",
84 event->header.size);
85
86 for (i = 0; i < event->header.size; i++) {
87 if ((i & 15) == 0) {
88 printf(".");
89 color_fprintf(stdout, color, " %04x: ", i);
90 }
91
92 color_fprintf(stdout, color, " %02x", raw_event[i]);
93
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] : '.');
102 }
103 color_fprintf(stdout, color, "\n");
104 }
105 }
106 printf(".\n");
107 }
This page took 0.056183 seconds and 6 git commands to generate.