[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20191126143720.10333-2-changbin.du@gmail.com>
Date: Tue, 26 Nov 2019 22:37:19 +0800
From: Changbin Du <changbin.du@...il.com>
To: Jiri Olsa <jolsa@...hat.com>,
Peter Zijlstra <peterz@...radead.org>,
Ingo Molnar <mingo@...hat.com>,
Arnaldo Carvalho de Melo <acme@...nel.org>
Cc: Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
Namhyung Kim <namhyung@...nel.org>,
linux-kernel@...r.kernel.org, Changbin Du <changbin.du@...il.com>
Subject: [PATCH v7 1/2] perf: support multiple debug options separated by ','
This patch adds support for multiple debug options separated by ',' and
non-int values.
--debug verbose=2,stderr
Signed-off-by: Changbin Du <changbin.du@...il.com>
---
tools/perf/Documentation/perf.txt | 18 +++----
tools/perf/util/debug.c | 89 ++++++++++++++++---------------
2 files changed, 56 insertions(+), 51 deletions(-)
diff --git a/tools/perf/Documentation/perf.txt b/tools/perf/Documentation/perf.txt
index 3f37ded13f8c..dcf9d98065f2 100644
--- a/tools/perf/Documentation/perf.txt
+++ b/tools/perf/Documentation/perf.txt
@@ -13,19 +13,19 @@ SYNOPSIS
OPTIONS
-------
--debug::
- Setup debug variable (see list below) in value
- range (0, 10). Use like:
+ Setup debug variable (see list below). The range of 'level' value
+ is (0, 10). Use like:
--debug verbose # sets verbose = 1
--debug verbose=2 # sets verbose = 2
List of debug variables allowed to set:
- verbose - general debug messages
- ordered-events - ordered events object debug messages
- data-convert - data convert command debug messages
- stderr - write debug output (option -v) to stderr
- in browser mode
- perf-event-open - Print perf_event_open() arguments and
- return value
+ verbose[=level] - general debug messages
+ ordered-events[=level]- ordered events object debug messages
+ data-convert[=level] - data convert command debug messages
+ stderr - write debug output (option -v) to stderr
+ in browser mode
+ perf-event-open - Print perf_event_open() arguments and
+ return value
--buildid-dir::
Setup buildid cache directory. It has higher priority than
diff --git a/tools/perf/util/debug.c b/tools/perf/util/debug.c
index adb656745ecc..929da46ece92 100644
--- a/tools/perf/util/debug.c
+++ b/tools/perf/util/debug.c
@@ -27,7 +27,7 @@ int verbose;
int debug_peo_args;
bool dump_trace = false, quiet = false;
int debug_ordered_events;
-static int redirect_to_stderr;
+static bool redirect_to_stderr;
int debug_data_convert;
int veprintf(int level, int var, const char *fmt, va_list args)
@@ -173,42 +173,18 @@ 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 },
- { .name = NULL, }
-};
-
-int perf_debug_option(const char *str)
+static int str2loglevel(const char *vstr)
{
- 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;
- }
+ char *endptr;
if (vstr) {
- v = atoi(vstr);
+ v = strtol(vstr, &endptr,0);
+ if (vstr == endptr) {
+ fprintf(stderr, "warning: '%s' is not a digit\n", vstr);
+ return -1;
+ }
+
/*
* Allow only values in range (0, 10),
* otherwise set 0.
@@ -219,20 +195,49 @@ int perf_debug_option(const char *str)
if (quiet)
v = -1;
- *var->ptr = v;
- free(s);
+ return v;
+}
+
+int perf_debug_option(const char *str)
+{
+ char *sep, *vstr;
+ char *dstr = strdup(str);
+ char *opt = dstr;
+
+ do {
+ if ((sep = strchr(opt, ',')) != NULL)
+ *sep = '\0';
+
+ vstr = strchr(opt, '=');
+ if (vstr)
+ *vstr++ = 0;
+
+ if (!strcmp(opt, "verbose"))
+ verbose = str2loglevel(vstr);
+ else if (!strcmp(opt, "ordered-events"))
+ debug_ordered_events = str2loglevel(vstr);
+ else if (!strcmp(opt, "data-convert"))
+ debug_data_convert = str2loglevel(vstr);
+ else if (!strcmp(opt, "stderr"))
+ redirect_to_stderr = true;
+ else if (!strcmp(opt, "perf-event-open"))
+ debug_peo_args = true;
+ else {
+ fprintf(stderr, "unkown debug option '%s'\n", opt);
+ free(dstr);
+ return -1;
+ }
+
+ opt = sep + 1;
+ } while (sep && sep[1]);
+
+ free(dstr);
return 0;
}
int perf_quiet_option(void)
{
- struct debug_variable *var = &debug_variables[0];
-
- /* disable all debug messages */
- while (var->name) {
- *var->ptr = -1;
- var++;
- }
+ verbose = debug_ordered_events = debug_data_convert = -1;
return 0;
}
--
2.20.1
Powered by blists - more mailing lists