kset-example: Spelling fixes.
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / tools / perf / util / debug.c
blob0905600c3851b51ec6b52f716e33f797c1da1032
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"
12 #include "util.h"
14 int verbose = 0;
15 int dump_trace = 0;
17 int eprintf(int level, const char *fmt, ...)
19 va_list args;
20 int ret = 0;
22 if (verbose >= level) {
23 va_start(args, fmt);
24 ret = vfprintf(stderr, fmt, args);
25 va_end(args);
28 return ret;
31 int dump_printf(const char *fmt, ...)
33 va_list args;
34 int ret = 0;
36 if (dump_trace) {
37 va_start(args, fmt);
38 ret = vprintf(fmt, args);
39 va_end(args);
42 return ret;
45 static int dump_printf_color(const char *fmt, const char *color, ...)
47 va_list args;
48 int ret = 0;
50 if (dump_trace) {
51 va_start(args, color);
52 ret = color_vfprintf(stdout, color, fmt, args);
53 va_end(args);
56 return ret;
60 void trace_event(event_t *event)
62 unsigned char *raw_event = (void *)event;
63 const char *color = PERF_COLOR_BLUE;
64 int i, j;
66 if (!dump_trace)
67 return;
69 dump_printf(".");
70 dump_printf_color("\n. ... raw event: size %d bytes\n", color,
71 event->header.size);
73 for (i = 0; i < event->header.size; i++) {
74 if ((i & 15) == 0) {
75 dump_printf(".");
76 dump_printf_color(" %04x: ", color, i);
79 dump_printf_color(" %02x", color, raw_event[i]);
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);
92 dump_printf_color("\n", color);
95 dump_printf(".\n");