perf tools: Move pr_* debug macros into debug object
[deliverable/linux.git] / tools / perf / util / debug.c
CommitLineData
cd84c2ac
FW
1/* For general debugging purposes */
2
3#include "../perf.h"
8f28827a 4
cd84c2ac
FW
5#include <string.h>
6#include <stdarg.h>
7#include <stdio.h>
8
f9224c5c 9#include "cache.h"
8f28827a
FW
10#include "color.h"
11#include "event.h"
12#include "debug.h"
4a58e611 13#include "util.h"
16ad2ffb 14#include "target.h"
8f28827a 15
b44308f5
ACM
16int verbose;
17bool dump_trace = false, quiet = false;
cd84c2ac 18
f772abc6 19static int _eprintf(int level, const char *fmt, va_list args)
cd84c2ac 20{
cd84c2ac
FW
21 int ret = 0;
22
6beba7ad 23 if (verbose >= level) {
044c4f8f 24 if (use_browser >= 1)
b56e5331 25 ui_helpline__vshow(fmt, args);
f9224c5c
ACM
26 else
27 ret = vfprintf(stderr, fmt, args);
cd84c2ac
FW
28 }
29
30 return ret;
31}
2cec19d9 32
f772abc6
JO
33int 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 */
49void 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
2cec19d9
FW
59int 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}
8f28827a 72
8115d60c 73void trace_event(union perf_event *event)
8f28827a
FW
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
5b1c1444
ACM
82 printf(".");
83 color_fprintf(stdout, color, "\n. ... raw event: size %d bytes\n",
84 event->header.size);
8f28827a
FW
85
86 for (i = 0; i < event->header.size; i++) {
87 if ((i & 15) == 0) {
5b1c1444
ACM
88 printf(".");
89 color_fprintf(stdout, color, " %04x: ", i);
8f28827a
FW
90 }
91
5b1c1444 92 color_fprintf(stdout, color, " %02x", raw_event[i]);
8f28827a
FW
93
94 if (((i & 15) == 15) || i == event->header.size-1) {
5b1c1444 95 color_fprintf(stdout, color, " ");
8f28827a 96 for (j = 0; j < 15-(i & 15); j++)
5b1c1444 97 color_fprintf(stdout, color, " ");
84c104ad 98 for (j = i & ~15; j <= i; j++) {
5b1c1444
ACM
99 color_fprintf(stdout, color, "%c",
100 isprint(raw_event[j]) ?
101 raw_event[j] : '.');
8f28827a 102 }
5b1c1444 103 color_fprintf(stdout, color, "\n");
8f28827a
FW
104 }
105 }
5b1c1444 106 printf(".\n");
8f28827a 107}
This page took 0.185341 seconds and 5 git commands to generate.