diff options
Diffstat (limited to 'tools/perf/util/debug.c')
-rw-r--r-- | tools/perf/util/debug.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/tools/perf/util/debug.c b/tools/perf/util/debug.c index c208d6f56e63..71d419362634 100644 --- a/tools/perf/util/debug.c +++ b/tools/perf/util/debug.c | |||
@@ -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 | } | ||