Skip to content

Commit bbb2cea

Browse files
Jiri Olsaacmel
authored andcommitted
perf tools: Add --debug optionto set debug variable
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>
1 parent c95688a commit bbb2cea

4 files changed

Lines changed: 67 additions & 2 deletions

File tree

‎tools/perf/Documentation/perf.txt‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,15 @@ perf - Performance analysis tools for Linux
88
SYNOPSIS
99
--------
1010
[verse]
11-
'perf' [--version] [--help] COMMAND [ARGS]
11+
'perf' [--version] [--help] [OPTIONS] COMMAND [ARGS]
12+
13+
OPTIONS
14+
-------
15+
--debug::
16+
Setup debug variable (just verbose for now) in value
17+
range (0, 10). Use like:
18+
--debug verbose # sets verbose = 1
19+
--debug verbose=2 # sets verbose = 2
1220

1321
DESCRIPTION
1422
-----------

‎tools/perf/perf.c‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@
1313
#include "util/quote.h"
1414
#include "util/run-command.h"
1515
#include "util/parse-events.h"
16+
#include "util/debug.h"
1617
#include <api/fs/debugfs.h>
1718
#include <pthread.h>
1819

1920
const char perf_usage_string[] =
20-
"perf [--version] [--help] COMMAND [ARGS]";
21+
"perf [--version] [--debug variable[=VALUE]] [--help] COMMAND [ARGS]";
2122

2223
const char perf_more_info_string[] =
2324
"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)
212213
printf("%s ", p->cmd);
213214
}
214215
exit(0);
216+
} else if (!strcmp(cmd, "--debug")) {
217+
if (*argc < 2) {
218+
fprintf(stderr, "No variable specified for --debug.\n");
219+
usage(perf_usage_string);
220+
}
221+
if (perf_debug_option((*argv)[1]))
222+
usage(perf_usage_string);
223+
224+
(*argv)++;
225+
(*argc)--;
215226
} else {
216227
fprintf(stderr, "Unknown option: %s\n", cmd);
217228
usage(perf_usage_string);

‎tools/perf/util/debug.c‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,47 @@ void trace_event(union perf_event *event)
105105
}
106106
printf(".\n");
107107
}
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+
}

‎tools/perf/util/debug.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,6 @@ void pr_stat(const char *fmt, ...);
3939

4040
int eprintf(int level, int var, const char *fmt, ...) __attribute__((format(printf, 3, 4)));
4141

42+
int perf_debug_option(const char *str);
43+
4244
#endif /* __PERF_DEBUG_H */

0 commit comments

Comments
 (0)