summaryrefslogtreecommitdiff
path: root/tools/perf/util/env.c
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2015-09-08 22:58:20 +0300
committerArnaldo Carvalho de Melo <acme@redhat.com>2015-09-14 18:50:21 +0300
commitb699869285c4f6949f281ea57ac35ea9b9c6f467 (patch)
tree24f5f5f14f02dc35e19abc158478ecafda6a9179 /tools/perf/util/env.c
parenteebd0bfca5cb83f6e1ef0d872a16d45af0422114 (diff)
downloadlinux-b699869285c4f6949f281ea57ac35ea9b9c6f467.tar.xz
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 <wangnan0@huawei.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Borislav Petkov <bp@suse.de> Cc: David Ahern <dsahern@gmail.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Kan Liang <kan.liang@intel.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Stephane Eranian <eranian@google.com> Link: http://lkml.kernel.org/n/tip-2j78tdf8zn1ci0y6ji15bifj@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/env.c')
-rw-r--r--tools/perf/util/env.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/tools/perf/util/env.c b/tools/perf/util/env.c
index 0b3e1b2e5263..ca1e33a2203e 100644
--- a/tools/perf/util/env.c
+++ b/tools/perf/util/env.c
@@ -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;
+}