perf evlist: Auto unmap on destructor
authorArnaldo Carvalho de Melo <acme@redhat.com>
Fri, 3 Jan 2014 20:25:49 +0000 (17:25 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 13 Jan 2014 13:06:22 +0000 (10:06 -0300)
Removing further boilerplate after making sure perf_evlist__munmap can
be called multiple times for the same evlist.

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-o0luenuld4abupm4nmrgzm6f@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/builtin-record.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

index b7f5e438276b3d7b11a0fcf9621af52a1b974873..cb00b53c200f24db11bf16e49bb4ecefe3697f97 100644 (file)
@@ -968,8 +968,6 @@ int cmd_record(int argc, const char **argv, const char *prefix __maybe_unused)
        }
 
        err = __cmd_record(&record, argc, argv);
-
-       perf_evlist__munmap(rec->evlist);
 out_symbol_exit:
        symbol__exit();
        return err;
index aa8a5f46c3610af8d7e8a46edf5fd03a6eb4a2dd..399b4b91b4565b4def22434a8f3e19b9bff0eef7 100644 (file)
@@ -1993,7 +1993,6 @@ out_disable:
                }
        }
 
-       perf_evlist__munmap(evlist);
 out_delete_evlist:
        perf_evlist__delete(evlist);
 out:
index 2c0ce723749f4597b298d9552826193e584411f4..653a8fe2db951d0509d41c26aa11e82550207231 100644 (file)
@@ -540,7 +540,6 @@ static int do_test_code_reading(bool try_kcore)
                err = TEST_CODE_READING_OK;
 out_err:
        if (evlist) {
-               perf_evlist__munmap(evlist);
                perf_evlist__delete(evlist);
        } else {
                cpu_map__delete(cpus);
index dd1c677510bd1cb711fdd6f102dfc33c94fc997f..497957f269d8161f54b39574b5145e0dfc86ff4d 100644 (file)
@@ -142,7 +142,6 @@ int test__keep_tracking(void)
 out_err:
        if (evlist) {
                perf_evlist__disable(evlist);
-               perf_evlist__munmap(evlist);
                perf_evlist__delete(evlist);
        } else {
                cpu_map__delete(cpus);
index 111dd4a917ad7c3d277e2520798eaba84cf09e93..aef25f0ff9cc4393f28ecd2dfc968dd3342fa39c 100644 (file)
@@ -105,13 +105,13 @@ int test__basic_mmap(void)
                if (event->header.type != PERF_RECORD_SAMPLE) {
                        pr_debug("unexpected %s event\n",
                                 perf_event__name(event->header.type));
-                       goto out_munmap;
+                       goto out_delete_evlist;
                }
 
                err = perf_evlist__parse_sample(evlist, event, &sample);
                if (err) {
                        pr_err("Can't parse sample, err = %d\n", err);
-                       goto out_munmap;
+                       goto out_delete_evlist;
                }
 
                err = -1;
@@ -119,7 +119,7 @@ int test__basic_mmap(void)
                if (evsel == NULL) {
                        pr_debug("event with id %" PRIu64
                                 " doesn't map to an evsel\n", sample.id);
-                       goto out_munmap;
+                       goto out_delete_evlist;
                }
                nr_events[evsel->idx]++;
                perf_evlist__mmap_consume(evlist, 0);
@@ -132,12 +132,10 @@ int test__basic_mmap(void)
                                 expected_nr_events[evsel->idx],
                                 perf_evsel__name(evsel), nr_events[evsel->idx]);
                        err = -1;
-                       goto out_munmap;
+                       goto out_delete_evlist;
                }
        }
 
-out_munmap:
-       perf_evlist__munmap(evlist);
 out_delete_evlist:
        perf_evlist__delete(evlist);
        cpus    = NULL;
index 0a00638a9ebb560c93991a87e48b343c27a11c4a..5a016f66f5d27a6cd085ccc108b34dbba9e5aa6d 100644 (file)
@@ -85,7 +85,7 @@ int test__syscall_open_tp_fields(void)
                                err = perf_evsel__parse_sample(evsel, event, &sample);
                                if (err) {
                                        pr_err("Can't parse sample, err = %d\n", err);
-                                       goto out_munmap;
+                                       goto out_delete_evlist;
                                }
 
                                tp_flags = perf_evsel__intval(evsel, &sample, "flags");
@@ -93,7 +93,7 @@ int test__syscall_open_tp_fields(void)
                                if (flags != tp_flags) {
                                        pr_debug("%s: Expected flags=%#x, got %#x\n",
                                                 __func__, flags, tp_flags);
-                                       goto out_munmap;
+                                       goto out_delete_evlist;
                                }
 
                                goto out_ok;
@@ -105,13 +105,11 @@ int test__syscall_open_tp_fields(void)
 
                if (++nr_polls > 5) {
                        pr_debug("%s: no events!\n", __func__);
-                       goto out_munmap;
+                       goto out_delete_evlist;
                }
        }
 out_ok:
        err = 0;
-out_munmap:
-       perf_evlist__munmap(evlist);
 out_delete_evlist:
        perf_evlist__delete(evlist);
 out:
index 682978e66efeb905ba9f8a62dea8f5b8315d00e8..39cc7c3c0d0c0bd56d39cd98e0cd949abf243589 100644 (file)
@@ -165,7 +165,7 @@ int test__PERF_RECORD(void)
                                        if (verbose)
                                                perf_event__fprintf(event, stderr);
                                        pr_debug("Couldn't parse sample\n");
-                                       goto out_err;
+                                       goto out_delete_evlist;
                                }
 
                                if (verbose) {
@@ -302,8 +302,6 @@ found_exit:
                pr_debug("PERF_RECORD_MMAP for %s missing!\n", "[vdso]");
                ++errs;
        }
-out_err:
-       perf_evlist__munmap(evlist);
 out_delete_evlist:
        perf_evlist__delete(evlist);
 out:
index 3d50f2d2a4d5d613ed414f052190a8a73fbc65b9..47146d388dbffac3e6a90b6e1f6595083dfa1839 100644 (file)
@@ -166,7 +166,6 @@ next_event:
 out_err:
        if (evlist) {
                perf_evlist__disable(evlist);
-               perf_evlist__munmap(evlist);
                perf_evlist__delete(evlist);
        }
 
index b366f0edca793082892b803f020d23e4cf61a05f..983d6b8562a89f06f30f0aebd32e8b522f6b35fe 100644 (file)
@@ -90,7 +90,7 @@ static int __test__sw_clock_freq(enum perf_sw_ids clock_id)
                err = perf_evlist__parse_sample(evlist, event, &sample);
                if (err < 0) {
                        pr_debug("Error during parse sample\n");
-                       goto out_unmap_evlist;
+                       goto out_delete_evlist;
                }
 
                total_periods += sample.period;
@@ -105,8 +105,6 @@ next_event:
                err = -1;
        }
 
-out_unmap_evlist:
-       perf_evlist__munmap(evlist);
 out_delete_evlist:
        perf_evlist__delete(evlist);
        return err;
index 5511a0a929cdcdba7095e332d94c665a775c46be..5ff3db318f12ae5971d3916fc49599e14fd51075 100644 (file)
@@ -112,7 +112,6 @@ retry:
                err = -1;
        }
 
-       perf_evlist__munmap(evlist);
 out_delete_evlist:
        perf_evlist__delete(evlist);
        return err;
index a083bdc4680e8f56a88f843eda501dc00cb50fa7..0810f5ca77d7b0f241dacba0019c58d2dfe7580d 100644 (file)
@@ -107,6 +107,7 @@ void perf_evlist__exit(struct perf_evlist *evlist)
 
 void perf_evlist__delete(struct perf_evlist *evlist)
 {
+       perf_evlist__munmap(evlist);
        perf_evlist__close(evlist);
        cpu_map__delete(evlist->cpus);
        thread_map__delete(evlist->threads);
@@ -587,6 +588,9 @@ void perf_evlist__munmap(struct perf_evlist *evlist)
 {
        int i;
 
+       if (evlist->mmap == NULL)
+               return;
+
        for (i = 0; i < evlist->nr_mmaps; i++)
                __perf_evlist__munmap(evlist, i);