bcma: claim only 14e4:4365 PCI Dell card with SoftMAC BCM43142
[linux/fpc-iii.git] / tools / perf / util / debug.c
blob86d9c73025983d0132a4dddc8607161d713bfbf2
1 /* For general debugging purposes */
3 #include "../perf.h"
5 #include <string.h>
6 #include <stdarg.h>
7 #include <stdio.h>
9 #include "cache.h"
10 #include "color.h"
11 #include "event.h"
12 #include "debug.h"
13 #include "util.h"
14 #include "target.h"
16 #define NSECS_PER_SEC 1000000000ULL
17 #define NSECS_PER_USEC 1000ULL
19 int verbose;
20 bool dump_trace = false, quiet = false;
21 int debug_ordered_events;
22 static int redirect_to_stderr;
23 int debug_data_convert;
25 static int _eprintf(int level, int var, const char *fmt, va_list args)
27 int ret = 0;
29 if (var >= level) {
30 if (use_browser >= 1 && !redirect_to_stderr)
31 ui_helpline__vshow(fmt, args);
32 else
33 ret = vfprintf(stderr, fmt, args);
36 return ret;
39 int veprintf(int level, int var, const char *fmt, va_list args)
41 return _eprintf(level, var, fmt, args);
44 int eprintf(int level, int var, const char *fmt, ...)
46 va_list args;
47 int ret;
49 va_start(args, fmt);
50 ret = _eprintf(level, var, fmt, args);
51 va_end(args);
53 return ret;
56 static int __eprintf_time(u64 t, const char *fmt, va_list args)
58 int ret = 0;
59 u64 secs, usecs, nsecs = t;
61 secs = nsecs / NSECS_PER_SEC;
62 nsecs -= secs * NSECS_PER_SEC;
63 usecs = nsecs / NSECS_PER_USEC;
65 ret = fprintf(stderr, "[%13" PRIu64 ".%06" PRIu64 "] ",
66 secs, usecs);
67 ret += vfprintf(stderr, fmt, args);
68 return ret;
71 int eprintf_time(int level, int var, u64 t, const char *fmt, ...)
73 int ret = 0;
74 va_list args;
76 if (var >= level) {
77 va_start(args, fmt);
78 ret = __eprintf_time(t, fmt, args);
79 va_end(args);
82 return ret;
86 * Overloading libtraceevent standard info print
87 * function, display with -v in perf.
89 void pr_stat(const char *fmt, ...)
91 va_list args;
93 va_start(args, fmt);
94 _eprintf(1, verbose, fmt, args);
95 va_end(args);
96 eprintf(1, verbose, "\n");
99 int dump_printf(const char *fmt, ...)
101 va_list args;
102 int ret = 0;
104 if (dump_trace) {
105 va_start(args, fmt);
106 ret = vprintf(fmt, args);
107 va_end(args);
110 return ret;
113 void trace_event(union perf_event *event)
115 unsigned char *raw_event = (void *)event;
116 const char *color = PERF_COLOR_BLUE;
117 int i, j;
119 if (!dump_trace)
120 return;
122 printf(".");
123 color_fprintf(stdout, color, "\n. ... raw event: size %d bytes\n",
124 event->header.size);
126 for (i = 0; i < event->header.size; i++) {
127 if ((i & 15) == 0) {
128 printf(".");
129 color_fprintf(stdout, color, " %04x: ", i);
132 color_fprintf(stdout, color, " %02x", raw_event[i]);
134 if (((i & 15) == 15) || i == event->header.size-1) {
135 color_fprintf(stdout, color, " ");
136 for (j = 0; j < 15-(i & 15); j++)
137 color_fprintf(stdout, color, " ");
138 for (j = i & ~15; j <= i; j++) {
139 color_fprintf(stdout, color, "%c",
140 isprint(raw_event[j]) ?
141 raw_event[j] : '.');
143 color_fprintf(stdout, color, "\n");
146 printf(".\n");
149 static struct debug_variable {
150 const char *name;
151 int *ptr;
152 } debug_variables[] = {
153 { .name = "verbose", .ptr = &verbose },
154 { .name = "ordered-events", .ptr = &debug_ordered_events},
155 { .name = "stderr", .ptr = &redirect_to_stderr},
156 { .name = "data-convert", .ptr = &debug_data_convert },
157 { .name = NULL, }
160 int perf_debug_option(const char *str)
162 struct debug_variable *var = &debug_variables[0];
163 char *vstr, *s = strdup(str);
164 int v = 1;
166 vstr = strchr(s, '=');
167 if (vstr)
168 *vstr++ = 0;
170 while (var->name) {
171 if (!strcmp(s, var->name))
172 break;
173 var++;
176 if (!var->name) {
177 pr_err("Unknown debug variable name '%s'\n", s);
178 free(s);
179 return -1;
182 if (vstr) {
183 v = atoi(vstr);
185 * Allow only values in range (0, 10),
186 * otherwise set 0.
188 v = (v < 0) || (v > 10) ? 0 : v;
191 *var->ptr = v;
192 free(s);
193 return 0;