perf tools: Add --debug optionto set debug variable
authorJiri Olsa <jolsa@redhat.com>
Thu, 17 Jul 2014 10:55:00 +0000 (12:55 +0200)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 17 Jul 2014 15:58:59 +0000 (12:58 -0300)
Adding --debug option as a way to setup debug variables.  Starting with
support for verbose, more will come.

It's possible to use it now with report command:
  $ perf --debug verbose   ...
  $ perf --debug verbose=2 ...

I'll need this support to add separated debug variable for ordered
events change in order to separate debug output out of standard verbose
stream.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/20140717105500.GG516@krava.redhat.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/Documentation/perf.txt
tools/perf/perf.c
tools/perf/util/debug.c
tools/perf/util/debug.h

index 0eeb247dc7d270dcc3709bbacee67d9d9c0be3c6..d240bb2e5b22348d23d1d7a2f569e074c7b0995e 100644 (file)
@@ -8,7 +8,15 @@ perf - Performance analysis tools for Linux
 SYNOPSIS
 --------
 [verse]
-'perf' [--version] [--help] COMMAND [ARGS]
+'perf' [--version] [--help] [OPTIONS] COMMAND [ARGS]
+
+OPTIONS
+-------
+--debug::
+       Setup debug variable (just verbose for now) in value
+       range (0, 10). Use like:
+         --debug verbose   # sets verbose = 1
+         --debug verbose=2 # sets verbose = 2
 
 DESCRIPTION
 -----------
index 95c58fc15284e58ce4e9d744028e52814b9bde3d..eed3fb2a3af0603e83d0373cee7d858da8887a3a 100644 (file)
 #include "util/quote.h"
 #include "util/run-command.h"
 #include "util/parse-events.h"
+#include "util/debug.h"
 #include <api/fs/debugfs.h>
 #include <pthread.h>
 
 const char perf_usage_string[] =
-       "perf [--version] [--help] COMMAND [ARGS]";
+       "perf [--version] [--debug variable[=VALUE]] [--help] COMMAND [ARGS]";
 
 const char perf_more_info_string[] =
        "See 'perf help COMMAND' for more information on a specific command.";
@@ -212,6 +213,16 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
                                printf("%s ", p->cmd);
                        }
                        exit(0);
+               } else if (!strcmp(cmd, "--debug")) {
+                       if (*argc < 2) {
+                               fprintf(stderr, "No variable specified for --debug.\n");
+                               usage(perf_usage_string);
+                       }
+                       if (perf_debug_option((*argv)[1]))
+                               usage(perf_usage_string);
+
+                       (*argv)++;
+                       (*argc)--;
                } else {
                        fprintf(stderr, "Unknown option: %s\n", cmd);
                        usage(perf_usage_string);
index c208d6f56e637560ec384a4a625cb0d8dcd6cf5d..71d419362634768f32d22862da4a44952e02edd4 100644 (file)
@@ -105,3 +105,47 @@ void trace_event(union perf_event *event)
        }
        printf(".\n");
 }
+
+static struct debug_variable {
+       const char *name;
+       int *ptr;
+} debug_variables[] = {
+       { .name = "verbose", .ptr = &verbose },
+       { .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;
+       }
+
+       if (vstr) {
+               v = atoi(vstr);
+               /*
+                * Allow only values in range (0, 10),
+                * otherwise set 0.
+                */
+               v = (v < 0) || (v > 10) ? 0 : v;
+       }
+
+       *var->ptr = v;
+       free(s);
+       return 0;
+}
index 1cb808123242adad0e81679656d3c82d6458f88c..89fb6b0f7ab221d746163b5bb842ce6bf5416fad 100644 (file)
@@ -39,4 +39,6 @@ void pr_stat(const char *fmt, ...);
 
 int eprintf(int level, int var, const char *fmt, ...) __attribute__((format(printf, 3, 4)));
 
+int perf_debug_option(const char *str);
+
 #endif /* __PERF_DEBUG_H */