OMAP3 SRF: Update OMAP-PM layer
[linux-ginger.git] / tools / perf / util / debug.c
blobe8ca98fe0bd4d856f3444657789af42ef67c00d0
1 /* For general debugging purposes */
3 #include "../perf.h"
5 #include <string.h>
6 #include <stdarg.h>
7 #include <stdio.h>
9 #include "color.h"
10 #include "event.h"
11 #include "debug.h"
13 int verbose = 0;
14 int dump_trace = 0;
16 int eprintf(const char *fmt, ...)
18 va_list args;
19 int ret = 0;
21 if (verbose) {
22 va_start(args, fmt);
23 ret = vfprintf(stderr, fmt, args);
24 va_end(args);
27 return ret;
30 int dump_printf(const char *fmt, ...)
32 va_list args;
33 int ret = 0;
35 if (dump_trace) {
36 va_start(args, fmt);
37 ret = vprintf(fmt, args);
38 va_end(args);
41 return ret;
44 static int dump_printf_color(const char *fmt, const char *color, ...)
46 va_list args;
47 int ret = 0;
49 if (dump_trace) {
50 va_start(args, color);
51 ret = color_vfprintf(stdout, color, fmt, args);
52 va_end(args);
55 return ret;
59 void trace_event(event_t *event)
61 unsigned char *raw_event = (void *)event;
62 const char *color = PERF_COLOR_BLUE;
63 int i, j;
65 if (!dump_trace)
66 return;
68 dump_printf(".");
69 dump_printf_color("\n. ... raw event: size %d bytes\n", color,
70 event->header.size);
72 for (i = 0; i < event->header.size; i++) {
73 if ((i & 15) == 0) {
74 dump_printf(".");
75 dump_printf_color(" %04x: ", color, i);
78 dump_printf_color(" %02x", color, raw_event[i]);
80 if (((i & 15) == 15) || i == event->header.size-1) {
81 dump_printf_color(" ", color);
82 for (j = 0; j < 15-(i & 15); j++)
83 dump_printf_color(" ", color);
84 for (j = 0; j < (i & 15); j++) {
85 if (isprint(raw_event[i-15+j]))
86 dump_printf_color("%c", color,
87 raw_event[i-15+j]);
88 else
89 dump_printf_color(".", color);
91 dump_printf_color("\n", color);
94 dump_printf(".\n");