diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2011-01-18 18:41:45 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2011-01-24 10:18:05 -0500 |
commit | ef1d1af28ca37fdbc2745da040529cd2953c1af5 (patch) | |
tree | dff4a86fbc813ca808ce0607e3e041cdcdca5cec /tools/perf/util/evsel.c | |
parent | d0dd74e853a0a6f37e8061d6d50be41c7034c54c (diff) |
perf evsel: Introduce perf_evsel__{in,ex}it
Out of the {con,des}structor, as in interpreted language bindings we will
need to go back from the wrapper object to the real thing. In that case
using container_of will save us to have an extra pointer in the perf_evsel
struct.
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Tom Zanussi <tzanussi@gmail.com>
LKML-Reference: <new-submission>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/evsel.c')
-rw-r--r-- | tools/perf/util/evsel.c | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index a85ae12845ea..76ab553637d6 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c | |||
@@ -14,15 +14,20 @@ | |||
14 | #define FD(e, x, y) (*(int *)xyarray__entry(e->fd, x, y)) | 14 | #define FD(e, x, y) (*(int *)xyarray__entry(e->fd, x, y)) |
15 | #define SID(e, x, y) xyarray__entry(e->id, x, y) | 15 | #define SID(e, x, y) xyarray__entry(e->id, x, y) |
16 | 16 | ||
17 | void perf_evsel__init(struct perf_evsel *evsel, | ||
18 | struct perf_event_attr *attr, int idx) | ||
19 | { | ||
20 | evsel->idx = idx; | ||
21 | evsel->attr = *attr; | ||
22 | INIT_LIST_HEAD(&evsel->node); | ||
23 | } | ||
24 | |||
17 | struct perf_evsel *perf_evsel__new(struct perf_event_attr *attr, int idx) | 25 | struct perf_evsel *perf_evsel__new(struct perf_event_attr *attr, int idx) |
18 | { | 26 | { |
19 | struct perf_evsel *evsel = zalloc(sizeof(*evsel)); | 27 | struct perf_evsel *evsel = zalloc(sizeof(*evsel)); |
20 | 28 | ||
21 | if (evsel != NULL) { | 29 | if (evsel != NULL) |
22 | evsel->idx = idx; | 30 | perf_evsel__init(evsel, attr, idx); |
23 | evsel->attr = *attr; | ||
24 | INIT_LIST_HEAD(&evsel->node); | ||
25 | } | ||
26 | 31 | ||
27 | return evsel; | 32 | return evsel; |
28 | } | 33 | } |
@@ -87,11 +92,16 @@ int perf_evlist__alloc_mmap(struct perf_evlist *evlist, int ncpus) | |||
87 | return evlist->mmap != NULL ? 0 : -ENOMEM; | 92 | return evlist->mmap != NULL ? 0 : -ENOMEM; |
88 | } | 93 | } |
89 | 94 | ||
90 | void perf_evsel__delete(struct perf_evsel *evsel) | 95 | void perf_evsel__exit(struct perf_evsel *evsel) |
91 | { | 96 | { |
92 | assert(list_empty(&evsel->node)); | 97 | assert(list_empty(&evsel->node)); |
93 | xyarray__delete(evsel->fd); | 98 | xyarray__delete(evsel->fd); |
94 | xyarray__delete(evsel->id); | 99 | xyarray__delete(evsel->id); |
100 | } | ||
101 | |||
102 | void perf_evsel__delete(struct perf_evsel *evsel) | ||
103 | { | ||
104 | perf_evsel__exit(evsel); | ||
95 | free(evsel); | 105 | free(evsel); |
96 | } | 106 | } |
97 | 107 | ||