at v2.6.32 1.7 kB view raw
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 13int verbose = 0; 14int dump_trace = 0; 15 16int eprintf(const char *fmt, ...) 17{ 18 va_list args; 19 int ret = 0; 20 21 if (verbose) { 22 va_start(args, fmt); 23 ret = vfprintf(stderr, fmt, args); 24 va_end(args); 25 } 26 27 return ret; 28} 29 30int dump_printf(const char *fmt, ...) 31{ 32 va_list args; 33 int ret = 0; 34 35 if (dump_trace) { 36 va_start(args, fmt); 37 ret = vprintf(fmt, args); 38 va_end(args); 39 } 40 41 return ret; 42} 43 44static int dump_printf_color(const char *fmt, const char *color, ...) 45{ 46 va_list args; 47 int ret = 0; 48 49 if (dump_trace) { 50 va_start(args, color); 51 ret = color_vfprintf(stdout, color, fmt, args); 52 va_end(args); 53 } 54 55 return ret; 56} 57 58 59void trace_event(event_t *event) 60{ 61 unsigned char *raw_event = (void *)event; 62 const char *color = PERF_COLOR_BLUE; 63 int i, j; 64 65 if (!dump_trace) 66 return; 67 68 dump_printf("."); 69 dump_printf_color("\n. ... raw event: size %d bytes\n", color, 70 event->header.size); 71 72 for (i = 0; i < event->header.size; i++) { 73 if ((i & 15) == 0) { 74 dump_printf("."); 75 dump_printf_color(" %04x: ", color, i); 76 } 77 78 dump_printf_color(" %02x", color, raw_event[i]); 79 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); 90 } 91 dump_printf_color("\n", color); 92 } 93 } 94 dump_printf(".\n"); 95}