Skip to content

Commit

Permalink
perf tools: Save cmdline arguments earlier
Browse files Browse the repository at this point in the history
perf_env__set_cmdline() only saves the arguments the first time it's
called.  It doesn't need to be called every time the options and
suboptions are parsed.  Instead it can just be called once.

This also has the advantage of making the option parsing code less
perf-specific so it can be moved out to a library.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/19b76a5aa1b688bd635bd65d80bbc103a978d75e.1449548395.git.jpoimboe@redhat.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
  • Loading branch information
Josh Poimboeuf authored and Arnaldo Carvalho de Melo committed Dec 9, 2015
1 parent 1fe143c commit 2bdb2c2
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 11 deletions.
1 change: 1 addition & 0 deletions tools/perf/perf.c
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
use_pager = 1;
commit_pager_choice();

perf_env__set_cmdline(&perf_env, argc, argv);
status = p->fn(argc, argv, prefix);
exit_browser(status);
perf_env__exit(&perf_env);
Expand Down
9 changes: 0 additions & 9 deletions tools/perf/util/env.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,6 @@ int perf_env__set_cmdline(struct perf_env *env, int argc, const char *argv[])
{
int i;

/*
* If env->cmdline_argv has already been set, do not override it. This allows
* a command to set the cmdline, parse args and then call another
* builtin function that implements a command -- e.g, cmd_kvm calling
* cmd_record.
*/
if (env->cmdline_argv != NULL)
return 0;

/* do not include NULL termination */
env->cmdline_argv = calloc(argc, sizeof(char *));
if (env->cmdline_argv == NULL)
Expand Down
2 changes: 0 additions & 2 deletions tools/perf/util/parse-options.c
Original file line number Diff line number Diff line change
Expand Up @@ -501,8 +501,6 @@ int parse_options_subcommand(int argc, const char **argv, const struct option *o
{
struct parse_opt_ctx_t ctx;

perf_env__set_cmdline(&perf_env, argc, argv);

/* build usage string if it's not provided */
if (subcommands && !usagestr[0]) {
struct strbuf buf = STRBUF_INIT;
Expand Down

0 comments on commit 2bdb2c2

Please sign in to comment.