Merge branch 'fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/evalenti/linux...
[linux/fpc-iii.git] / tools / perf / util / env.c
blob49a11d9d8b8f050efa48715cfba9e54731f63eef
1 #include "cpumap.h"
2 #include "env.h"
3 #include "util.h"
5 struct perf_env perf_env;
7 void perf_env__exit(struct perf_env *env)
9 int i;
11 zfree(&env->hostname);
12 zfree(&env->os_release);
13 zfree(&env->version);
14 zfree(&env->arch);
15 zfree(&env->cpu_desc);
16 zfree(&env->cpuid);
17 zfree(&env->cmdline);
18 zfree(&env->cmdline_argv);
19 zfree(&env->sibling_cores);
20 zfree(&env->sibling_threads);
21 zfree(&env->numa_nodes);
22 zfree(&env->pmu_mappings);
23 zfree(&env->cpu);
25 for (i = 0; i < env->caches_cnt; i++)
26 cpu_cache_level__free(&env->caches[i]);
27 zfree(&env->caches);
30 int perf_env__set_cmdline(struct perf_env *env, int argc, const char *argv[])
32 int i;
34 /* do not include NULL termination */
35 env->cmdline_argv = calloc(argc, sizeof(char *));
36 if (env->cmdline_argv == NULL)
37 goto out_enomem;
40 * Must copy argv contents because it gets moved around during option
41 * parsing:
43 for (i = 0; i < argc ; i++) {
44 env->cmdline_argv[i] = argv[i];
45 if (env->cmdline_argv[i] == NULL)
46 goto out_free;
49 env->nr_cmdline = argc;
51 return 0;
52 out_free:
53 zfree(&env->cmdline_argv);
54 out_enomem:
55 return -ENOMEM;
58 int perf_env__read_cpu_topology_map(struct perf_env *env)
60 int cpu, nr_cpus;
62 if (env->cpu != NULL)
63 return 0;
65 if (env->nr_cpus_avail == 0)
66 env->nr_cpus_avail = sysconf(_SC_NPROCESSORS_CONF);
68 nr_cpus = env->nr_cpus_avail;
69 if (nr_cpus == -1)
70 return -EINVAL;
72 env->cpu = calloc(nr_cpus, sizeof(env->cpu[0]));
73 if (env->cpu == NULL)
74 return -ENOMEM;
76 for (cpu = 0; cpu < nr_cpus; ++cpu) {
77 env->cpu[cpu].core_id = cpu_map__get_core_id(cpu);
78 env->cpu[cpu].socket_id = cpu_map__get_socket_id(cpu);
81 env->nr_cpus_avail = nr_cpus;
82 return 0;
85 void cpu_cache_level__free(struct cpu_cache_level *cache)
87 free(cache->type);
88 free(cache->map);
89 free(cache->size);