blob: 0905600c3851b51ec6b52f716e33f797c1da1032 [file] [log] [blame]
Frederic Weisbeckercd84c2a2009-08-12 10:03:49 +02001/* For general debugging purposes */
2
3#include "../perf.h"
Frederic Weisbecker8f288272009-08-16 22:05:48 +02004
Frederic Weisbeckercd84c2a2009-08-12 10:03:49 +02005#include <string.h>
6#include <stdarg.h>
7#include <stdio.h>
8
Frederic Weisbecker8f288272009-08-16 22:05:48 +02009#include "color.h"
10#include "event.h"
11#include "debug.h"
Arnaldo Carvalho de Melo4a58e612009-12-27 21:37:00 -020012#include "util.h"
Frederic Weisbecker8f288272009-08-16 22:05:48 +020013
Frederic Weisbeckercd84c2a2009-08-12 10:03:49 +020014int verbose = 0;
Frederic Weisbecker2cec19d2009-08-16 19:24:21 +020015int dump_trace = 0;
Frederic Weisbeckercd84c2a2009-08-12 10:03:49 +020016
Arnaldo Carvalho de Melo6beba7a2009-10-21 17:34:06 -020017int eprintf(int level, const char *fmt, ...)
Frederic Weisbeckercd84c2a2009-08-12 10:03:49 +020018{
19 va_list args;
20 int ret = 0;
21
Arnaldo Carvalho de Melo6beba7a2009-10-21 17:34:06 -020022 if (verbose >= level) {
Frederic Weisbeckercd84c2a2009-08-12 10:03:49 +020023 va_start(args, fmt);
24 ret = vfprintf(stderr, fmt, args);
25 va_end(args);
26 }
27
28 return ret;
29}
Frederic Weisbecker2cec19d2009-08-16 19:24:21 +020030
31int dump_printf(const char *fmt, ...)
32{
33 va_list args;
34 int ret = 0;
35
36 if (dump_trace) {
37 va_start(args, fmt);
38 ret = vprintf(fmt, args);
39 va_end(args);
40 }
41
42 return ret;
43}
Frederic Weisbecker8f288272009-08-16 22:05:48 +020044
45static int dump_printf_color(const char *fmt, const char *color, ...)
46{
47 va_list args;
48 int ret = 0;
49
50 if (dump_trace) {
51 va_start(args, color);
52 ret = color_vfprintf(stdout, color, fmt, args);
53 va_end(args);
54 }
55
56 return ret;
57}
58
59
60void trace_event(event_t *event)
61{
62 unsigned char *raw_event = (void *)event;
63 const char *color = PERF_COLOR_BLUE;
64 int i, j;
65
66 if (!dump_trace)
67 return;
68
69 dump_printf(".");
70 dump_printf_color("\n. ... raw event: size %d bytes\n", color,
71 event->header.size);
72
73 for (i = 0; i < event->header.size; i++) {
74 if ((i & 15) == 0) {
75 dump_printf(".");
76 dump_printf_color(" %04x: ", color, i);
77 }
78
79 dump_printf_color(" %02x", color, raw_event[i]);
80
81 if (((i & 15) == 15) || i == event->header.size-1) {
82 dump_printf_color(" ", color);
83 for (j = 0; j < 15-(i & 15); j++)
84 dump_printf_color(" ", color);
85 for (j = 0; j < (i & 15); j++) {
86 if (isprint(raw_event[i-15+j]))
87 dump_printf_color("%c", color,
88 raw_event[i-15+j]);
89 else
90 dump_printf_color(".", color);
91 }
92 dump_printf_color("\n", color);
93 }
94 }
95 dump_printf(".\n");
96}