Root/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 "color.h"
10#include "event.h"
11#include "debug.h"
12#include "util.h"
13
14int verbose = 0;
15int dump_trace = 0;
16
17int eprintf(int level, const char *fmt, ...)
18{
19    va_list args;
20    int ret = 0;
21
22    if (verbose >= level) {
23        va_start(args, fmt);
24        ret = vfprintf(stderr, fmt, args);
25        va_end(args);
26    }
27
28    return ret;
29}
30
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}
44
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}
97

Archive Download this file



interactive