perf evlist: Move destruction of maps to evlist destructor
authorArnaldo Carvalho de Melo <acme@redhat.com>
Fri, 3 Jan 2014 18:56:06 +0000 (15:56 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 13 Jan 2014 13:06:21 +0000 (10:06 -0300)
Instead of requiring tools to do an extra destructor call just before
calling perf_evlist__delete.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-0jd2ptzyikxb5wp7inzz2ah2@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
15 files changed:
tools/perf/builtin-kvm.c
tools/perf/builtin-record.c
tools/perf/builtin-stat.c
tools/perf/builtin-top.c
tools/perf/builtin-trace.c
tools/perf/tests/code-reading.c
tools/perf/tests/keep-tracking.c
tools/perf/tests/mmap-basic.c
tools/perf/tests/open-syscall-tp-fields.c
tools/perf/tests/perf-record.c
tools/perf/tests/perf-time-to-tsc.c
tools/perf/tests/sw-clock.c
tools/perf/tests/task-exit.c
tools/perf/util/evlist.c
tools/perf/util/evlist.h

index a6ec1052c291a37ac754e9e6333b33261726d665..858b11bf6711b7970b89a8475d2002086502d85e 100644 (file)
@@ -1556,10 +1556,8 @@ out:
        if (kvm->session)
                perf_session__delete(kvm->session);
        kvm->session = NULL;
-       if (kvm->evlist) {
-               perf_evlist__delete_maps(kvm->evlist);
+       if (kvm->evlist)
                perf_evlist__delete(kvm->evlist);
-       }
 
        return err;
 }
index 6dcb8aae908ce0b1d2135421efa913c333e80c4e..5149b41e63d187e0444d4efde1f9cc5fb104707f 100644 (file)
@@ -964,15 +964,13 @@ int cmd_record(int argc, const char **argv, const char *prefix __maybe_unused)
 
        if (record_opts__config(&rec->opts)) {
                err = -EINVAL;
-               goto out_free_fd;
+               goto out_symbol_exit;
        }
 
        err = __cmd_record(&record, argc, argv);
 
        perf_evlist__munmap(rec->evlist);
        perf_evlist__close(rec->evlist);
-out_free_fd:
-       perf_evlist__delete_maps(rec->evlist);
 out_symbol_exit:
        symbol__exit();
        return err;
index f8456cad656db00bec9f74e7c10a69be8b36d354..6ca076660de5f38a282a196225e37b1e1d4ffbd0 100644 (file)
@@ -1782,14 +1782,14 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused)
        if (interval && interval < 100) {
                pr_err("print interval must be >= 100ms\n");
                parse_options_usage(stat_usage, options, "I", 1);
-               goto out_free_maps;
+               goto out;
        }
 
        if (perf_evlist__alloc_stats(evsel_list, interval))
-               goto out_free_maps;
+               goto out;
 
        if (perf_stat_init_aggr_mode())
-               goto out_free_maps;
+               goto out;
 
        /*
         * We dont want to block the signals - that would cause
@@ -1821,8 +1821,6 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused)
                print_stat(argc, argv);
 
        perf_evlist__free_stats(evsel_list);
-out_free_maps:
-       perf_evlist__delete_maps(evsel_list);
 out:
        perf_evlist__delete(evsel_list);
        return status;
index 172e91a9ce6243bab1b617e7a32d45f0b6ed95d2..e0fd0aa57f06b2d3c80e4060420f3d1a0f1dd328 100644 (file)
@@ -1171,7 +1171,7 @@ int cmd_top(int argc, const char **argv, const char *prefix __maybe_unused)
        if (!top.evlist->nr_entries &&
            perf_evlist__add_default(top.evlist) < 0) {
                ui__error("Not enough memory for event selector list\n");
-               goto out_delete_maps;
+               goto out_delete_evlist;
        }
 
        symbol_conf.nr_events = top.evlist->nr_entries;
@@ -1181,7 +1181,7 @@ int cmd_top(int argc, const char **argv, const char *prefix __maybe_unused)
 
        if (record_opts__config(opts)) {
                status = -EINVAL;
-               goto out_delete_maps;
+               goto out_delete_evlist;
        }
 
        top.sym_evsel = perf_evlist__first(top.evlist);
@@ -1206,8 +1206,6 @@ int cmd_top(int argc, const char **argv, const char *prefix __maybe_unused)
 
        status = __cmd_top(&top);
 
-out_delete_maps:
-       perf_evlist__delete_maps(top.evlist);
 out_delete_evlist:
        perf_evlist__delete(top.evlist);
 
index 5498eacf8fc6f0c755043ebf77a25509e20eaaf6..f4ddd14b8a9bfc9c3833383713a29a0a4f8aeca5 100644 (file)
@@ -1885,7 +1885,7 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
        err = trace__symbols_init(trace, evlist);
        if (err < 0) {
                fprintf(trace->output, "Problems initializing symbol libraries!\n");
-               goto out_delete_maps;
+               goto out_delete_evlist;
        }
 
        perf_evlist__config(evlist, &trace->opts);
@@ -1898,7 +1898,7 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
                                                    argv, false, NULL);
                if (err < 0) {
                        fprintf(trace->output, "Couldn't run the workload!\n");
-                       goto out_delete_maps;
+                       goto out_delete_evlist;
                }
        }
 
@@ -1996,8 +1996,6 @@ out_disable:
        perf_evlist__munmap(evlist);
 out_close_evlist:
        perf_evlist__close(evlist);
-out_delete_maps:
-       perf_evlist__delete_maps(evlist);
 out_delete_evlist:
        perf_evlist__delete(evlist);
 out:
index 4248d1e96848dd4ded2d31b46ecf12c9e60a3a3b..ddbc7756620c490d108d38edf6f37a84d376003d 100644 (file)
@@ -543,11 +543,10 @@ out_err:
                perf_evlist__munmap(evlist);
                perf_evlist__close(evlist);
                perf_evlist__delete(evlist);
-       }
-       if (cpus)
+       } else {
                cpu_map__delete(cpus);
-       if (threads)
                thread_map__delete(threads);
+       }
        machines__destroy_kernel_maps(&machines);
        machine__delete_threads(machine);
        machines__exit(&machines);
index 27eb75142b88c0dbd08239307d559d578ee61533..f9bc1fcd17cd1b22acf0ff158f1696546181b129 100644 (file)
@@ -145,11 +145,10 @@ out_err:
                perf_evlist__munmap(evlist);
                perf_evlist__close(evlist);
                perf_evlist__delete(evlist);
-       }
-       if (cpus)
+       } else {
                cpu_map__delete(cpus);
-       if (threads)
                thread_map__delete(threads);
+       }
 
        return err;
 }
index d64ab79c6d35c920917ca2d68cd0d3436ff03912..bbb334d2a8646c60ca4d0007606f4c9fec83d2c1 100644 (file)
@@ -143,6 +143,8 @@ out_close_fd:
                perf_evsel__close_fd(evsels[i], 1, threads->nr);
 out_free_evlist:
        perf_evlist__delete(evlist);
+       cpus    = NULL;
+       threads = NULL;
 out_free_cpus:
        cpu_map__delete(cpus);
 out_free_threads:
index 774620a5aecbbd8bf8686bb6f9feab646fd4c551..595b577172a6e7a323d6cdcc72b11b2a91dd3802 100644 (file)
@@ -48,7 +48,7 @@ int test__syscall_open_tp_fields(void)
        err = perf_evlist__open(evlist);
        if (err < 0) {
                pr_debug("perf_evlist__open: %s\n", strerror(errno));
-               goto out_delete_maps;
+               goto out_delete_evlist;
        }
 
        err = perf_evlist__mmap(evlist, UINT_MAX, false);
@@ -114,8 +114,6 @@ out_munmap:
        perf_evlist__munmap(evlist);
 out_close_evlist:
        perf_evlist__close(evlist);
-out_delete_maps:
-       perf_evlist__delete_maps(evlist);
 out_delete_evlist:
        perf_evlist__delete(evlist);
 out:
index fa0ed35afb9a2e4a384b3de7dd457c59cf73afcc..266da9d413002c62501daa264806afb5a367651e 100644 (file)
@@ -86,7 +86,7 @@ int test__PERF_RECORD(void)
        err = perf_evlist__prepare_workload(evlist, &opts.target, argv, false, NULL);
        if (err < 0) {
                pr_debug("Couldn't run the workload!\n");
-               goto out_delete_maps;
+               goto out_delete_evlist;
        }
 
        /*
@@ -101,7 +101,7 @@ int test__PERF_RECORD(void)
        err = sched__get_first_possible_cpu(evlist->workload.pid, &cpu_mask);
        if (err < 0) {
                pr_debug("sched__get_first_possible_cpu: %s\n", strerror(errno));
-               goto out_delete_maps;
+               goto out_delete_evlist;
        }
 
        cpu = err;
@@ -111,7 +111,7 @@ int test__PERF_RECORD(void)
         */
        if (sched_setaffinity(evlist->workload.pid, cpu_mask_size, &cpu_mask) < 0) {
                pr_debug("sched_setaffinity: %s\n", strerror(errno));
-               goto out_delete_maps;
+               goto out_delete_evlist;
        }
 
        /*
@@ -121,7 +121,7 @@ int test__PERF_RECORD(void)
        err = perf_evlist__open(evlist);
        if (err < 0) {
                pr_debug("perf_evlist__open: %s\n", strerror(errno));
-               goto out_delete_maps;
+               goto out_delete_evlist;
        }
 
        /*
@@ -306,8 +306,6 @@ out_err:
        perf_evlist__munmap(evlist);
 out_close_evlist:
        perf_evlist__close(evlist);
-out_delete_maps:
-       perf_evlist__delete_maps(evlist);
 out_delete_evlist:
        perf_evlist__delete(evlist);
 out:
index c6398b90e8974b4417e8229c74cfe7184cfa1301..97d08fff1f8d53ec22bd366a82fe3920ab24d49b 100644 (file)
@@ -170,10 +170,6 @@ out_err:
                perf_evlist__close(evlist);
                perf_evlist__delete(evlist);
        }
-       if (cpus)
-               cpu_map__delete(cpus);
-       if (threads)
-               thread_map__delete(threads);
 
        return err;
 }
index 6664a7cd828c11585cfa12c7f9104e776ddf100a..266d38127ba6c9efc315618e647148ba69507697 100644 (file)
@@ -45,7 +45,7 @@ static int __test__sw_clock_freq(enum perf_sw_ids clock_id)
        evsel = perf_evsel__new(&attr);
        if (evsel == NULL) {
                pr_debug("perf_evsel__new\n");
-               goto out_free_evlist;
+               goto out_delete_evlist;
        }
        perf_evlist__add(evlist, evsel);
 
@@ -54,7 +54,7 @@ static int __test__sw_clock_freq(enum perf_sw_ids clock_id)
        if (!evlist->cpus || !evlist->threads) {
                err = -ENOMEM;
                pr_debug("Not enough memory to create thread/cpu maps\n");
-               goto out_delete_maps;
+               goto out_delete_evlist;
        }
 
        if (perf_evlist__open(evlist)) {
@@ -63,7 +63,7 @@ static int __test__sw_clock_freq(enum perf_sw_ids clock_id)
                err = -errno;
                pr_debug("Couldn't open evlist: %s\nHint: check %s, using %" PRIu64 " in this test.\n",
                         strerror(errno), knob, (u64)attr.sample_freq);
-               goto out_delete_maps;
+               goto out_delete_evlist;
        }
 
        err = perf_evlist__mmap(evlist, 128, true);
@@ -109,9 +109,7 @@ out_unmap_evlist:
        perf_evlist__munmap(evlist);
 out_close_evlist:
        perf_evlist__close(evlist);
-out_delete_maps:
-       perf_evlist__delete_maps(evlist);
-out_free_evlist:
+out_delete_evlist:
        perf_evlist__delete(evlist);
        return err;
 }
index 44e339d4e297661fefdfa8101b263d0adbeb8b6e..fdeb2aa46a50ed47e39eed514c67937a9d994039 100644 (file)
@@ -62,14 +62,14 @@ int test__task_exit(void)
        if (!evlist->cpus || !evlist->threads) {
                err = -ENOMEM;
                pr_debug("Not enough memory to create thread/cpu maps\n");
-               goto out_delete_maps;
+               goto out_delete_evlist;
        }
 
        err = perf_evlist__prepare_workload(evlist, &target, argv, false,
                                            workload_exec_failed_signal);
        if (err < 0) {
                pr_debug("Couldn't run the workload!\n");
-               goto out_delete_maps;
+               goto out_delete_evlist;
        }
 
        evsel = perf_evlist__first(evlist);
@@ -83,7 +83,7 @@ int test__task_exit(void)
        err = perf_evlist__open(evlist);
        if (err < 0) {
                pr_debug("Couldn't open the evlist: %s\n", strerror(-err));
-               goto out_delete_maps;
+               goto out_delete_evlist;
        }
 
        if (perf_evlist__mmap(evlist, 128, true) < 0) {
@@ -115,8 +115,7 @@ retry:
        perf_evlist__munmap(evlist);
 out_close_evlist:
        perf_evlist__close(evlist);
-out_delete_maps:
-       perf_evlist__delete_maps(evlist);
+out_delete_evlist:
        perf_evlist__delete(evlist);
        return err;
 }
index 96b3ef547db42afb6e1f5d4fbf765a7f521e4f4e..143eaf05178f10414a15fad82bcd9c26ac69df13 100644 (file)
@@ -107,6 +107,10 @@ void perf_evlist__exit(struct perf_evlist *evlist)
 
 void perf_evlist__delete(struct perf_evlist *evlist)
 {
+       cpu_map__delete(evlist->cpus);
+       thread_map__delete(evlist->threads);
+       evlist->cpus = NULL;
+       evlist->threads = NULL;
        perf_evlist__purge(evlist);
        perf_evlist__exit(evlist);
        free(evlist);
@@ -833,14 +837,6 @@ out_delete_threads:
        return -1;
 }
 
-void perf_evlist__delete_maps(struct perf_evlist *evlist)
-{
-       cpu_map__delete(evlist->cpus);
-       thread_map__delete(evlist->threads);
-       evlist->cpus    = NULL;
-       evlist->threads = NULL;
-}
-
 int perf_evlist__apply_filters(struct perf_evlist *evlist)
 {
        struct perf_evsel *evsel;
index 18d1222c0762d5929ebce76cea12fca15dee81b0..518e521c801de765bff0458eb106bd3bd8be4aa7 100644 (file)
@@ -135,7 +135,6 @@ static inline void perf_evlist__set_maps(struct perf_evlist *evlist,
 }
 
 int perf_evlist__create_maps(struct perf_evlist *evlist, struct target *target);
-void perf_evlist__delete_maps(struct perf_evlist *evlist);
 int perf_evlist__apply_filters(struct perf_evlist *evlist);
 
 void __perf_evlist__set_leader(struct list_head *list);