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 "cache.h"
10 #include "color.h"
11 #include "event.h"
12 #include "debug.h"
13 #include "util.h"
14 #include "target.h"
15 
16 int verbose;
17 bool dump_trace = false, quiet = false;
18 
eprintf(int level,const char * fmt,...)19 int eprintf(int level, const char *fmt, ...)
20 {
21 	va_list args;
22 	int ret = 0;
23 
24 	if (verbose >= level) {
25 		va_start(args, fmt);
26 		if (use_browser >= 1)
27 			ui_helpline__vshow(fmt, args);
28 		else
29 			ret = vfprintf(stderr, fmt, args);
30 		va_end(args);
31 	}
32 
33 	return ret;
34 }
35 
dump_printf(const char * fmt,...)36 int dump_printf(const char *fmt, ...)
37 {
38 	va_list args;
39 	int ret = 0;
40 
41 	if (dump_trace) {
42 		va_start(args, fmt);
43 		ret = vprintf(fmt, args);
44 		va_end(args);
45 	}
46 
47 	return ret;
48 }
49 
trace_event(union perf_event * event)50 void trace_event(union perf_event *event)
51 {
52 	unsigned char *raw_event = (void *)event;
53 	const char *color = PERF_COLOR_BLUE;
54 	int i, j;
55 
56 	if (!dump_trace)
57 		return;
58 
59 	printf(".");
60 	color_fprintf(stdout, color, "\n. ... raw event: size %d bytes\n",
61 		      event->header.size);
62 
63 	for (i = 0; i < event->header.size; i++) {
64 		if ((i & 15) == 0) {
65 			printf(".");
66 			color_fprintf(stdout, color, "  %04x: ", i);
67 		}
68 
69 		color_fprintf(stdout, color, " %02x", raw_event[i]);
70 
71 		if (((i & 15) == 15) || i == event->header.size-1) {
72 			color_fprintf(stdout, color, "  ");
73 			for (j = 0; j < 15-(i & 15); j++)
74 				color_fprintf(stdout, color, "   ");
75 			for (j = i & ~15; j <= i; j++) {
76 				color_fprintf(stdout, color, "%c",
77 					      isprint(raw_event[j]) ?
78 					      raw_event[j] : '.');
79 			}
80 			color_fprintf(stdout, color, "\n");
81 		}
82 	}
83 	printf(".\n");
84 }
85