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 | |
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')
-rw-r--r-- | tools/perf/util/evlist.c | 29 | ||||
-rw-r--r-- | tools/perf/util/evlist.h | 2 | ||||
-rw-r--r-- | tools/perf/util/evsel.c | 22 | ||||
-rw-r--r-- | tools/perf/util/evsel.h | 3 |
4 files changed, 41 insertions, 15 deletions
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index 4b3b84cd71a1..df0610e9c61b 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c | |||
@@ -6,17 +6,21 @@ | |||
6 | #include <linux/bitops.h> | 6 | #include <linux/bitops.h> |
7 | #include <linux/hash.h> | 7 | #include <linux/hash.h> |
8 | 8 | ||
9 | void perf_evlist__init(struct perf_evlist *evlist) | ||
10 | { | ||
11 | int i; | ||
12 | |||
13 | for (i = 0; i < PERF_EVLIST__HLIST_SIZE; ++i) | ||
14 | INIT_HLIST_HEAD(&evlist->heads[i]); | ||
15 | INIT_LIST_HEAD(&evlist->entries); | ||
16 | } | ||
17 | |||
9 | struct perf_evlist *perf_evlist__new(void) | 18 | struct perf_evlist *perf_evlist__new(void) |
10 | { | 19 | { |
11 | struct perf_evlist *evlist = zalloc(sizeof(*evlist)); | 20 | struct perf_evlist *evlist = zalloc(sizeof(*evlist)); |
12 | 21 | ||
13 | if (evlist != NULL) { | 22 | if (evlist != NULL) |
14 | int i; | 23 | perf_evlist__init(evlist); |
15 | |||
16 | for (i = 0; i < PERF_EVLIST__HLIST_SIZE; ++i) | ||
17 | INIT_HLIST_HEAD(&evlist->heads[i]); | ||
18 | INIT_LIST_HEAD(&evlist->entries); | ||
19 | } | ||
20 | 24 | ||
21 | return evlist; | 25 | return evlist; |
22 | } | 26 | } |
@@ -33,11 +37,18 @@ static void perf_evlist__purge(struct perf_evlist *evlist) | |||
33 | evlist->nr_entries = 0; | 37 | evlist->nr_entries = 0; |
34 | } | 38 | } |
35 | 39 | ||
36 | void perf_evlist__delete(struct perf_evlist *evlist) | 40 | void perf_evlist__exit(struct perf_evlist *evlist) |
37 | { | 41 | { |
38 | perf_evlist__purge(evlist); | ||
39 | free(evlist->mmap); | 42 | free(evlist->mmap); |
40 | free(evlist->pollfd); | 43 | free(evlist->pollfd); |
44 | evlist->mmap = NULL; | ||
45 | evlist->pollfd = NULL; | ||
46 | } | ||
47 | |||
48 | void perf_evlist__delete(struct perf_evlist *evlist) | ||
49 | { | ||
50 | perf_evlist__purge(evlist); | ||
51 | perf_evlist__exit(evlist); | ||
41 | free(evlist); | 52 | free(evlist); |
42 | } | 53 | } |
43 | 54 | ||
diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h index 28712063db97..acbe48eac608 100644 --- a/tools/perf/util/evlist.h +++ b/tools/perf/util/evlist.h | |||
@@ -24,6 +24,8 @@ struct perf_evlist { | |||
24 | struct perf_evsel; | 24 | struct perf_evsel; |
25 | 25 | ||
26 | struct perf_evlist *perf_evlist__new(void); | 26 | struct perf_evlist *perf_evlist__new(void); |
27 | void perf_evlist__init(struct perf_evlist *evlist); | ||
28 | void perf_evlist__exit(struct perf_evlist *evlist); | ||
27 | void perf_evlist__delete(struct perf_evlist *evlist); | 29 | void perf_evlist__delete(struct perf_evlist *evlist); |
28 | 30 | ||
29 | void perf_evlist__add(struct perf_evlist *evlist, struct perf_evsel *entry); | 31 | void perf_evlist__add(struct perf_evlist *evlist, struct perf_evsel *entry); |
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 | ||
diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index 667ee4e2e35e..7962e7587dea 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h | |||
@@ -52,6 +52,9 @@ struct thread_map; | |||
52 | struct perf_evlist; | 52 | struct perf_evlist; |
53 | 53 | ||
54 | struct perf_evsel *perf_evsel__new(struct perf_event_attr *attr, int idx); | 54 | struct perf_evsel *perf_evsel__new(struct perf_event_attr *attr, int idx); |
55 | void perf_evsel__init(struct perf_evsel *evsel, | ||
56 | struct perf_event_attr *attr, int idx); | ||
57 | void perf_evsel__exit(struct perf_evsel *evsel); | ||
55 | void perf_evsel__delete(struct perf_evsel *evsel); | 58 | void perf_evsel__delete(struct perf_evsel *evsel); |
56 | 59 | ||
57 | int perf_evsel__alloc_fd(struct perf_evsel *evsel, int ncpus, int nthreads); | 60 | int perf_evsel__alloc_fd(struct perf_evsel *evsel, int ncpus, int nthreads); |