blob: ca1e33a2203e1b1e8db0448ad08dfdba9993bcbf [file] [log] [blame]
Arnaldo Carvalho de Melof0ce8882015-09-08 13:30:00 -03001#include "env.h"
2#include "util.h"
3
Arnaldo Carvalho de Melob6998692015-09-08 16:58:20 -03004struct perf_env perf_env;
5
Arnaldo Carvalho de Melof0ce8882015-09-08 13:30:00 -03006void perf_env__exit(struct perf_env *env)
7{
8 zfree(&env->hostname);
9 zfree(&env->os_release);
10 zfree(&env->version);
11 zfree(&env->arch);
12 zfree(&env->cpu_desc);
13 zfree(&env->cpuid);
14 zfree(&env->cmdline);
15 zfree(&env->cmdline_argv);
16 zfree(&env->sibling_cores);
17 zfree(&env->sibling_threads);
18 zfree(&env->numa_nodes);
19 zfree(&env->pmu_mappings);
20 zfree(&env->cpu);
21}
Arnaldo Carvalho de Melob6998692015-09-08 16:58:20 -030022
23int perf_env__set_cmdline(struct perf_env *env, int argc, const char *argv[])
24{
25 int i;
26
27 /*
28 * If env->cmdline_argv has already been set, do not override it. This allows
29 * a command to set the cmdline, parse args and then call another
30 * builtin function that implements a command -- e.g, cmd_kvm calling
31 * cmd_record.
32 */
33 if (env->cmdline_argv != NULL)
34 return 0;
35
36 /* do not include NULL termination */
37 env->cmdline_argv = calloc(argc, sizeof(char *));
38 if (env->cmdline_argv == NULL)
39 goto out_enomem;
40
41 /*
42 * Must copy argv contents because it gets moved around during option
43 * parsing:
44 */
45 for (i = 0; i < argc ; i++) {
46 env->cmdline_argv[i] = argv[i];
47 if (env->cmdline_argv[i] == NULL)
48 goto out_free;
49 }
50
51 env->nr_cmdline = argc;
52
53 return 0;
54out_free:
55 zfree(&env->cmdline_argv);
56out_enomem:
57 return -ENOMEM;
58}