perf evlist: Close fds on destructor
authorArnaldo Carvalho de Melo <acme@redhat.com>
Fri, 3 Jan 2014 19:54:12 +0000 (16:54 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 13 Jan 2014 13:06:22 +0000 (10:06 -0300)
Since it is safe to call perf_evlist__close() multiple times, autoclose
it and remove the calls to the close from existing tools, reducing the
tooling boilerplate.

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-2kq9v7p1rude1tqxa0aue2tk@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 5149b41e63d187e0444d4efde1f9cc5fb104707f..b7f5e438276b3d7b11a0fcf9621af52a1b974873 100644 (file)
@@ -970,7 +970,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);
-       perf_evlist__close(rec->evlist);
 out_symbol_exit:
        symbol__exit();
        return err;
index f4ddd14b8a9bfc9c3833383713a29a0a4f8aeca5..aa8a5f46c3610af8d7e8a46edf5fd03a6eb4a2dd 100644 (file)
@@ -1909,7 +1909,7 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
        err = perf_evlist__mmap(evlist, trace->opts.mmap_pages, false);
        if (err < 0) {
                fprintf(trace->output, "Couldn't mmap the events: %s\n", strerror(errno));
-               goto out_close_evlist;
+               goto out_delete_evlist;
        }
 
        perf_evlist__enable(evlist);
@@ -1994,8 +1994,6 @@ out_disable:
        }
 
        perf_evlist__munmap(evlist);
-out_close_evlist:
-       perf_evlist__close(evlist);
 out_delete_evlist:
        perf_evlist__delete(evlist);
 out:
index ddbc7756620c490d108d38edf6f37a84d376003d..2c0ce723749f4597b298d9552826193e584411f4 100644 (file)
@@ -541,7 +541,6 @@ static int do_test_code_reading(bool try_kcore)
 out_err:
        if (evlist) {
                perf_evlist__munmap(evlist);
-               perf_evlist__close(evlist);
                perf_evlist__delete(evlist);
        } else {
                cpu_map__delete(cpus);
index f9bc1fcd17cd1b22acf0ff158f1696546181b129..dd1c677510bd1cb711fdd6f102dfc33c94fc997f 100644 (file)
@@ -143,7 +143,6 @@ out_err:
        if (evlist) {
                perf_evlist__disable(evlist);
                perf_evlist__munmap(evlist);
-               perf_evlist__close(evlist);
                perf_evlist__delete(evlist);
        } else {
                cpu_map__delete(cpus);
index bbb334d2a8646c60ca4d0007606f4c9fec83d2c1..111dd4a917ad7c3d277e2520798eaba84cf09e93 100644 (file)
@@ -68,7 +68,7 @@ int test__basic_mmap(void)
                evsels[i] = perf_evsel__newtp("syscalls", name);
                if (evsels[i] == NULL) {
                        pr_debug("perf_evsel__new\n");
-                       goto out_free_evlist;
+                       goto out_delete_evlist;
                }
 
                evsels[i]->attr.wakeup_events = 1;
@@ -80,7 +80,7 @@ int test__basic_mmap(void)
                        pr_debug("failed to open counter: %s, "
                                 "tweak /proc/sys/kernel/perf_event_paranoid?\n",
                                 strerror(errno));
-                       goto out_close_fd;
+                       goto out_delete_evlist;
                }
 
                nr_events[i] = 0;
@@ -90,7 +90,7 @@ int test__basic_mmap(void)
        if (perf_evlist__mmap(evlist, 128, true) < 0) {
                pr_debug("failed to mmap events: %d (%s)\n", errno,
                         strerror(errno));
-               goto out_close_fd;
+               goto out_delete_evlist;
        }
 
        for (i = 0; i < nsyscalls; ++i)
@@ -138,10 +138,7 @@ int test__basic_mmap(void)
 
 out_munmap:
        perf_evlist__munmap(evlist);
-out_close_fd:
-       for (i = 0; i < nsyscalls; ++i)
-               perf_evsel__close_fd(evsels[i], 1, threads->nr);
-out_free_evlist:
+out_delete_evlist:
        perf_evlist__delete(evlist);
        cpus    = NULL;
        threads = NULL;
index 595b577172a6e7a323d6cdcc72b11b2a91dd3802..0a00638a9ebb560c93991a87e48b343c27a11c4a 100644 (file)
@@ -54,7 +54,7 @@ int test__syscall_open_tp_fields(void)
        err = perf_evlist__mmap(evlist, UINT_MAX, false);
        if (err < 0) {
                pr_debug("perf_evlist__mmap: %s\n", strerror(errno));
-               goto out_close_evlist;
+               goto out_delete_evlist;
        }
 
        perf_evlist__enable(evlist);
@@ -112,8 +112,6 @@ out_ok:
        err = 0;
 out_munmap:
        perf_evlist__munmap(evlist);
-out_close_evlist:
-       perf_evlist__close(evlist);
 out_delete_evlist:
        perf_evlist__delete(evlist);
 out:
index 266da9d413002c62501daa264806afb5a367651e..682978e66efeb905ba9f8a62dea8f5b8315d00e8 100644 (file)
@@ -132,7 +132,7 @@ int test__PERF_RECORD(void)
        err = perf_evlist__mmap(evlist, opts.mmap_pages, false);
        if (err < 0) {
                pr_debug("perf_evlist__mmap: %s\n", strerror(errno));
-               goto out_close_evlist;
+               goto out_delete_evlist;
        }
 
        /*
@@ -304,8 +304,6 @@ found_exit:
        }
 out_err:
        perf_evlist__munmap(evlist);
-out_close_evlist:
-       perf_evlist__close(evlist);
 out_delete_evlist:
        perf_evlist__delete(evlist);
 out:
index 97d08fff1f8d53ec22bd366a82fe3920ab24d49b..3d50f2d2a4d5d613ed414f052190a8a73fbc65b9 100644 (file)
@@ -167,7 +167,6 @@ out_err:
        if (evlist) {
                perf_evlist__disable(evlist);
                perf_evlist__munmap(evlist);
-               perf_evlist__close(evlist);
                perf_evlist__delete(evlist);
        }
 
index 266d38127ba6c9efc315618e647148ba69507697..b366f0edca793082892b803f020d23e4cf61a05f 100644 (file)
@@ -70,7 +70,7 @@ static int __test__sw_clock_freq(enum perf_sw_ids clock_id)
        if (err < 0) {
                pr_debug("failed to mmap event: %d (%s)\n", errno,
                         strerror(errno));
-               goto out_close_evlist;
+               goto out_delete_evlist;
        }
 
        perf_evlist__enable(evlist);
@@ -107,8 +107,6 @@ next_event:
 
 out_unmap_evlist:
        perf_evlist__munmap(evlist);
-out_close_evlist:
-       perf_evlist__close(evlist);
 out_delete_evlist:
        perf_evlist__delete(evlist);
        return err;
index fdeb2aa46a50ed47e39eed514c67937a9d994039..5511a0a929cdcdba7095e332d94c665a775c46be 100644 (file)
@@ -89,7 +89,7 @@ int test__task_exit(void)
        if (perf_evlist__mmap(evlist, 128, true) < 0) {
                pr_debug("failed to mmap events: %d (%s)\n", errno,
                         strerror(errno));
-               goto out_close_evlist;
+               goto out_delete_evlist;
        }
 
        perf_evlist__start_workload(evlist);
@@ -113,8 +113,6 @@ retry:
        }
 
        perf_evlist__munmap(evlist);
-out_close_evlist:
-       perf_evlist__close(evlist);
 out_delete_evlist:
        perf_evlist__delete(evlist);
        return err;
index 143eaf05178f10414a15fad82bcd9c26ac69df13..a083bdc4680e8f56a88f843eda501dc00cb50fa7 100644 (file)
@@ -107,6 +107,7 @@ void perf_evlist__exit(struct perf_evlist *evlist)
 
 void perf_evlist__delete(struct perf_evlist *evlist)
 {
+       perf_evlist__close(evlist);
        cpu_map__delete(evlist->cpus);
        thread_map__delete(evlist->threads);
        evlist->cpus = NULL;