diff options
Diffstat (limited to 'tools/perf/util/debug.c')
-rw-r--r-- | tools/perf/util/debug.c | 56 |
1 files changed, 50 insertions, 6 deletions
diff --git a/tools/perf/util/debug.c b/tools/perf/util/debug.c index 299b55586502..71d419362634 100644 --- a/tools/perf/util/debug.c +++ b/tools/perf/util/debug.c | |||
@@ -16,11 +16,11 @@ | |||
16 | int verbose; | 16 | int verbose; |
17 | bool dump_trace = false, quiet = false; | 17 | bool dump_trace = false, quiet = false; |
18 | 18 | ||
19 | static int _eprintf(int level, const char *fmt, va_list args) | 19 | static int _eprintf(int level, int var, const char *fmt, va_list args) |
20 | { | 20 | { |
21 | int ret = 0; | 21 | int ret = 0; |
22 | 22 | ||
23 | if (verbose >= level) { | 23 | if (var >= level) { |
24 | if (use_browser >= 1) | 24 | if (use_browser >= 1) |
25 | ui_helpline__vshow(fmt, args); | 25 | ui_helpline__vshow(fmt, args); |
26 | else | 26 | else |
@@ -30,13 +30,13 @@ static int _eprintf(int level, const char *fmt, va_list args) | |||
30 | return ret; | 30 | return ret; |
31 | } | 31 | } |
32 | 32 | ||
33 | int eprintf(int level, const char *fmt, ...) | 33 | int eprintf(int level, int var, const char *fmt, ...) |
34 | { | 34 | { |
35 | va_list args; | 35 | va_list args; |
36 | int ret; | 36 | int ret; |
37 | 37 | ||
38 | va_start(args, fmt); | 38 | va_start(args, fmt); |
39 | ret = _eprintf(level, fmt, args); | 39 | ret = _eprintf(level, var, fmt, args); |
40 | va_end(args); | 40 | va_end(args); |
41 | 41 | ||
42 | return ret; | 42 | return ret; |
@@ -51,9 +51,9 @@ void pr_stat(const char *fmt, ...) | |||
51 | va_list args; | 51 | va_list args; |
52 | 52 | ||
53 | va_start(args, fmt); | 53 | va_start(args, fmt); |
54 | _eprintf(1, fmt, args); | 54 | _eprintf(1, verbose, fmt, args); |
55 | va_end(args); | 55 | va_end(args); |
56 | eprintf(1, "\n"); | 56 | eprintf(1, verbose, "\n"); |
57 | } | 57 | } |
58 | 58 | ||
59 | int dump_printf(const char *fmt, ...) | 59 | int dump_printf(const char *fmt, ...) |
@@ -105,3 +105,47 @@ void trace_event(union perf_event *event) | |||
105 | } | 105 | } |
106 | printf(".\n"); | 106 | printf(".\n"); |
107 | } | 107 | } |
108 | |||
109 | static struct debug_variable { | ||
110 | const char *name; | ||
111 | int *ptr; | ||
112 | } debug_variables[] = { | ||
113 | { .name = "verbose", .ptr = &verbose }, | ||
114 | { .name = NULL, } | ||
115 | }; | ||
116 | |||
117 | int perf_debug_option(const char *str) | ||
118 | { | ||
119 | struct debug_variable *var = &debug_variables[0]; | ||
120 | char *vstr, *s = strdup(str); | ||
121 | int v = 1; | ||
122 | |||
123 | vstr = strchr(s, '='); | ||
124 | if (vstr) | ||
125 | *vstr++ = 0; | ||
126 | |||
127 | while (var->name) { | ||
128 | if (!strcmp(s, var->name)) | ||
129 | break; | ||
130 | var++; | ||
131 | } | ||
132 | |||
133 | if (!var->name) { | ||
134 | pr_err("Unknown debug variable name '%s'\n", s); | ||
135 | free(s); | ||
136 | return -1; | ||
137 | } | ||
138 | |||
139 | if (vstr) { | ||
140 | v = atoi(vstr); | ||
141 | /* | ||
142 | * Allow only values in range (0, 10), | ||
143 | * otherwise set 0. | ||
144 | */ | ||
145 | v = (v < 0) || (v > 10) ? 0 : v; | ||
146 | } | ||
147 | |||
148 | *var->ptr = v; | ||
149 | free(s); | ||
150 | return 0; | ||
151 | } | ||