perf env: Adopt perf_header__set_cmdline
tip-bot for Arnaldo Carvalho de Melo
merge botCommit-ID: b699869285c4f6949f281ea57ac35ea9b9c6f467 Gitweb: http://git.kernel.org/tip/b699869285c4f6949f281ea57ac35ea9b9c6f467 Author: Arnaldo Carvalho de Melo <[email protected]> AuthorDate: Tue, 8 Sep 2015 16:58:20 -0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Mon, 14 Sep 2015 12:50:21 -0300
perf env: Adopt perf_header__set_cmdline
Move this from two globals to perf_env global, that eventually will be just perf_header->env or something else, to ease the refactoring series, leave it as a global and go on reading more of its fields, not as part of the header writing process but as a perf_env init one that will be used for perf.data-less situations.
Tested-by Wang Nan <[email protected]>
Cc Adrian Hunter <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc David Ahern <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Kan Liang <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Stephane Eranian <[email protected]>
Signed-off-by Arnaldo Carvalho de Melo <[email protected]>
--- tools/perf/util/env.c | 39 ++++++++++++++++++++++++++++++++++++ tools/perf/util/env.h | 4 ++++ tools/perf/util/header.c | 44 +++++------------------------------------ tools/perf/util/parse-options.c | 2 +- 4 files changed, 49 insertions(+), 40 deletions(-)
tools/perf/util/env.c +39 -0
@@ -1,6 +1,8 @@#include "env.h" #include "util.h" +struct perf_env perf_env; +void perf_env__exit (struct perf_env *env) {zfree (&env->hostname);
@@ -17,3 +19,40 @@ void perf_env__exit(struct perf_env *env)zfree (&env->pmu_mappings);zfree (&env->cpu); } + +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 ) + goto out_enomem; + +/* +* Must copy argv contents because it gets moved around during option +* parsing: +*/ +for (i =0 ; i < argc ; i++) { + env->cmdline_argv[i] = argv[i]; +if (env->cmdline_argv[i] ==NULL ) + goto out_free; + } + + env->nr_cmdline = argc; + +return 0 ; +out_free: +zfree (&env->cmdline_argv); +out_enomem: +return -ENOMEM ; +}
tools/perf/util/env.h +4 -0
@@ -32,6 +32,10 @@ struct perf_env { struct cpu_topology_map *cpu; }; +extern struct perf_env perf_env; +void perf_env__exit (struct perf_env *env); +int perf_env__set_cmdline (struct perf_env *env,int argc,const char *argv[]); +#endif /* __PERF_ENV_H */
tools/perf/util/header.c +5 -39
74 lines not on this page · raw message
tools/perf/util/parse-options.c +1 -1
@@ -496,7 +496,7 @@ int parse_options_subcommand(int argc, const char **argv, const struct option *o {struct parse_opt_ctx_t ctx; -perf_header__set_cmdline (argc, argv); +perf_env__set_cmdline (&perf_env, argc, argv);/* build usage string if it's not provided */ if (subcommands && !usagestr[0 ]) {