Merge tag 'amd-drm-fixes-5.9-2020-08-12' of git://people.freedesktop.org/~agd5f/linux...
[linux-2.6-microblaze.git] / tools / perf / util / debug.c
index adb6567..5cda556 100644 (file)
@@ -20,6 +20,7 @@
 #include "target.h"
 #include "ui/helpline.h"
 #include "ui/ui.h"
+#include "util/parse-sublevel-options.h"
 
 #include <linux/ctype.h>
 
@@ -173,65 +174,37 @@ void trace_event(union perf_event *event)
                     trace_event_printer, event);
 }
 
-static struct debug_variable {
-       const char *name;
-       int *ptr;
-} debug_variables[] = {
-       { .name = "verbose",            .ptr = &verbose },
-       { .name = "ordered-events",     .ptr = &debug_ordered_events},
-       { .name = "stderr",             .ptr = &redirect_to_stderr},
-       { .name = "data-convert",       .ptr = &debug_data_convert },
-       { .name = "perf-event-open",    .ptr = &debug_peo_args },
+static struct sublevel_option debug_opts[] = {
+       { .name = "verbose",            .value_ptr = &verbose },
+       { .name = "ordered-events",     .value_ptr = &debug_ordered_events},
+       { .name = "stderr",             .value_ptr = &redirect_to_stderr},
+       { .name = "data-convert",       .value_ptr = &debug_data_convert },
+       { .name = "perf-event-open",    .value_ptr = &debug_peo_args },
        { .name = NULL, }
 };
 
 int perf_debug_option(const char *str)
 {
-       struct debug_variable *var = &debug_variables[0];
-       char *vstr, *s = strdup(str);
-       int v = 1;
-
-       vstr = strchr(s, '=');
-       if (vstr)
-               *vstr++ = 0;
-
-       while (var->name) {
-               if (!strcmp(s, var->name))
-                       break;
-               var++;
-       }
-
-       if (!var->name) {
-               pr_err("Unknown debug variable name '%s'\n", s);
-               free(s);
-               return -1;
-       }
+       int ret;
 
-       if (vstr) {
-               v = atoi(vstr);
-               /*
-                * Allow only values in range (0, 10),
-                * otherwise set 0.
-                */
-               v = (v < 0) || (v > 10) ? 0 : v;
-       }
+       ret = perf_parse_sublevel_options(str, debug_opts);
+       if (ret)
+               return ret;
 
-       if (quiet)
-               v = -1;
+       /* Allow only verbose value in range (0, 10), otherwise set 0. */
+       verbose = (verbose < 0) || (verbose > 10) ? 0 : verbose;
 
-       *var->ptr = v;
-       free(s);
        return 0;
 }
 
 int perf_quiet_option(void)
 {
-       struct debug_variable *var = &debug_variables[0];
+       struct sublevel_option *opt = &debug_opts[0];
 
        /* disable all debug messages */
-       while (var->name) {
-               *var->ptr = -1;
-               var++;
+       while (opt->name) {
+               *opt->value_ptr = -1;
+               opt++;
        }
 
        return 0;