Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
awilliam
GitHub Repository: awilliam/linux-vfio
Path: blob/master/tools/perf/util/debug.c
10821 views
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
15
int verbose;
16
bool dump_trace = false, quiet = false;
17
18
int eprintf(int level, const char *fmt, ...)
19
{
20
va_list args;
21
int ret = 0;
22
23
if (verbose >= level) {
24
va_start(args, fmt);
25
if (use_browser > 0)
26
ret = ui_helpline__show_help(fmt, args);
27
else
28
ret = vfprintf(stderr, fmt, args);
29
va_end(args);
30
}
31
32
return ret;
33
}
34
35
int dump_printf(const char *fmt, ...)
36
{
37
va_list args;
38
int ret = 0;
39
40
if (dump_trace) {
41
va_start(args, fmt);
42
ret = vprintf(fmt, args);
43
va_end(args);
44
}
45
46
return ret;
47
}
48
49
#ifdef NO_NEWT_SUPPORT
50
void ui__warning(const char *format, ...)
51
{
52
va_list args;
53
54
va_start(args, format);
55
vfprintf(stderr, format, args);
56
va_end(args);
57
}
58
#endif
59
60
void ui__warning_paranoid(void)
61
{
62
ui__warning("Permission error - are you root?\n"
63
"Consider tweaking /proc/sys/kernel/perf_event_paranoid:\n"
64
" -1 - Not paranoid at all\n"
65
" 0 - Disallow raw tracepoint access for unpriv\n"
66
" 1 - Disallow cpu events for unpriv\n"
67
" 2 - Disallow kernel profiling for unpriv\n");
68
}
69
70
void trace_event(union perf_event *event)
71
{
72
unsigned char *raw_event = (void *)event;
73
const char *color = PERF_COLOR_BLUE;
74
int i, j;
75
76
if (!dump_trace)
77
return;
78
79
printf(".");
80
color_fprintf(stdout, color, "\n. ... raw event: size %d bytes\n",
81
event->header.size);
82
83
for (i = 0; i < event->header.size; i++) {
84
if ((i & 15) == 0) {
85
printf(".");
86
color_fprintf(stdout, color, " %04x: ", i);
87
}
88
89
color_fprintf(stdout, color, " %02x", raw_event[i]);
90
91
if (((i & 15) == 15) || i == event->header.size-1) {
92
color_fprintf(stdout, color, " ");
93
for (j = 0; j < 15-(i & 15); j++)
94
color_fprintf(stdout, color, " ");
95
for (j = i & ~15; j <= i; j++) {
96
color_fprintf(stdout, color, "%c",
97
isprint(raw_event[j]) ?
98
raw_event[j] : '.');
99
}
100
color_fprintf(stdout, color, "\n");
101
}
102
}
103
printf(".\n");
104
}
105
106