diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2013-11-07 14:41:19 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2013-11-11 13:56:39 -0500 |
commit | ef503831d8d64e12c6dad5547875cfcd4c5d043c (patch) | |
tree | 6c41b275c13b663260eefb5166d2b0527faaaea8 /tools/perf/util | |
parent | d53e57d039c323fe3a43630e9f729df48134e2c9 (diff) |
perf evsel: Remove idx parm from constructor
Most uses of the evsel constructor are followed by a call to
perf_evlist__add with an idex of evlist->nr_entries, so make rename
the current constructor to perf_evsel__new_idx and remove the need
for passing the constructor for the common case.
We still need the new_idx variant because the way groups are handled,
with evsel->nr_members holding the number of entries in an evlist,
partitioning the evlist into sublists inside a single linked list.
This asks for a clarifying refactoring, but for now simplify the non
parser cases, so that tool writers don't have to bother with evsel idx
setting.
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: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-zy9tskx6jqm2rmw7468zze2a@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util')
-rw-r--r-- | tools/perf/util/evlist.c | 9 | ||||
-rw-r--r-- | tools/perf/util/evsel.c | 4 | ||||
-rw-r--r-- | tools/perf/util/evsel.h | 15 | ||||
-rw-r--r-- | tools/perf/util/header.c | 4 | ||||
-rw-r--r-- | tools/perf/util/parse-events.c | 6 |
5 files changed, 25 insertions, 13 deletions
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index b939221efd8d..99dc58e5dcc3 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c | |||
@@ -117,6 +117,8 @@ void perf_evlist__delete(struct perf_evlist *evlist) | |||
117 | void perf_evlist__add(struct perf_evlist *evlist, struct perf_evsel *entry) | 117 | void perf_evlist__add(struct perf_evlist *evlist, struct perf_evsel *entry) |
118 | { | 118 | { |
119 | list_add_tail(&entry->node, &evlist->entries); | 119 | list_add_tail(&entry->node, &evlist->entries); |
120 | entry->idx = evlist->nr_entries; | ||
121 | |||
120 | if (!evlist->nr_entries++) | 122 | if (!evlist->nr_entries++) |
121 | perf_evlist__set_id_pos(evlist); | 123 | perf_evlist__set_id_pos(evlist); |
122 | } | 124 | } |
@@ -165,7 +167,7 @@ int perf_evlist__add_default(struct perf_evlist *evlist) | |||
165 | 167 | ||
166 | event_attr_init(&attr); | 168 | event_attr_init(&attr); |
167 | 169 | ||
168 | evsel = perf_evsel__new(&attr, 0); | 170 | evsel = perf_evsel__new(&attr); |
169 | if (evsel == NULL) | 171 | if (evsel == NULL) |
170 | goto error; | 172 | goto error; |
171 | 173 | ||
@@ -190,7 +192,7 @@ static int perf_evlist__add_attrs(struct perf_evlist *evlist, | |||
190 | size_t i; | 192 | size_t i; |
191 | 193 | ||
192 | for (i = 0; i < nr_attrs; i++) { | 194 | for (i = 0; i < nr_attrs; i++) { |
193 | evsel = perf_evsel__new(attrs + i, evlist->nr_entries + i); | 195 | evsel = perf_evsel__new_idx(attrs + i, evlist->nr_entries + i); |
194 | if (evsel == NULL) | 196 | if (evsel == NULL) |
195 | goto out_delete_partial_list; | 197 | goto out_delete_partial_list; |
196 | list_add_tail(&evsel->node, &head); | 198 | list_add_tail(&evsel->node, &head); |
@@ -249,9 +251,8 @@ perf_evlist__find_tracepoint_by_name(struct perf_evlist *evlist, | |||
249 | int perf_evlist__add_newtp(struct perf_evlist *evlist, | 251 | int perf_evlist__add_newtp(struct perf_evlist *evlist, |
250 | const char *sys, const char *name, void *handler) | 252 | const char *sys, const char *name, void *handler) |
251 | { | 253 | { |
252 | struct perf_evsel *evsel; | 254 | struct perf_evsel *evsel = perf_evsel__newtp(sys, name); |
253 | 255 | ||
254 | evsel = perf_evsel__newtp(sys, name, evlist->nr_entries); | ||
255 | if (evsel == NULL) | 256 | if (evsel == NULL) |
256 | return -1; | 257 | return -1; |
257 | 258 | ||
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 5280820ed389..f95653a639a6 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c | |||
@@ -168,7 +168,7 @@ void perf_evsel__init(struct perf_evsel *evsel, | |||
168 | perf_evsel__calc_id_pos(evsel); | 168 | perf_evsel__calc_id_pos(evsel); |
169 | } | 169 | } |
170 | 170 | ||
171 | struct perf_evsel *perf_evsel__new(struct perf_event_attr *attr, int idx) | 171 | struct perf_evsel *perf_evsel__new_idx(struct perf_event_attr *attr, int idx) |
172 | { | 172 | { |
173 | struct perf_evsel *evsel = zalloc(sizeof(*evsel)); | 173 | struct perf_evsel *evsel = zalloc(sizeof(*evsel)); |
174 | 174 | ||
@@ -219,7 +219,7 @@ out: | |||
219 | return format; | 219 | return format; |
220 | } | 220 | } |
221 | 221 | ||
222 | struct perf_evsel *perf_evsel__newtp(const char *sys, const char *name, int idx) | 222 | struct perf_evsel *perf_evsel__newtp_idx(const char *sys, const char *name, int idx) |
223 | { | 223 | { |
224 | struct perf_evsel *evsel = zalloc(sizeof(*evsel)); | 224 | struct perf_evsel *evsel = zalloc(sizeof(*evsel)); |
225 | 225 | ||
diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index 64ec8e1a7a28..0178233abd64 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h | |||
@@ -96,8 +96,19 @@ struct thread_map; | |||
96 | struct perf_evlist; | 96 | struct perf_evlist; |
97 | struct perf_record_opts; | 97 | struct perf_record_opts; |
98 | 98 | ||
99 | struct perf_evsel *perf_evsel__new(struct perf_event_attr *attr, int idx); | 99 | struct perf_evsel *perf_evsel__new_idx(struct perf_event_attr *attr, int idx); |
100 | struct perf_evsel *perf_evsel__newtp(const char *sys, const char *name, int idx); | 100 | |
101 | static inline struct perf_evsel *perf_evsel__new(struct perf_event_attr *attr) | ||
102 | { | ||
103 | return perf_evsel__new_idx(attr, 0); | ||
104 | } | ||
105 | |||
106 | struct perf_evsel *perf_evsel__newtp_idx(const char *sys, const char *name, int idx); | ||
107 | |||
108 | static inline struct perf_evsel *perf_evsel__newtp(const char *sys, const char *name) | ||
109 | { | ||
110 | return perf_evsel__newtp_idx(sys, name, 0); | ||
111 | } | ||
101 | 112 | ||
102 | struct event_format *event_format__new(const char *sys, const char *name); | 113 | struct event_format *event_format__new(const char *sys, const char *name); |
103 | 114 | ||
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index 26d9520a0c1b..369c03648f88 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c | |||
@@ -2797,7 +2797,7 @@ int perf_session__read_header(struct perf_session *session) | |||
2797 | perf_event__attr_swap(&f_attr.attr); | 2797 | perf_event__attr_swap(&f_attr.attr); |
2798 | 2798 | ||
2799 | tmp = lseek(fd, 0, SEEK_CUR); | 2799 | tmp = lseek(fd, 0, SEEK_CUR); |
2800 | evsel = perf_evsel__new(&f_attr.attr, i); | 2800 | evsel = perf_evsel__new(&f_attr.attr); |
2801 | 2801 | ||
2802 | if (evsel == NULL) | 2802 | if (evsel == NULL) |
2803 | goto out_delete_evlist; | 2803 | goto out_delete_evlist; |
@@ -2916,7 +2916,7 @@ int perf_event__process_attr(struct perf_tool *tool __maybe_unused, | |||
2916 | return -ENOMEM; | 2916 | return -ENOMEM; |
2917 | } | 2917 | } |
2918 | 2918 | ||
2919 | evsel = perf_evsel__new(&event->attr.attr, evlist->nr_entries); | 2919 | evsel = perf_evsel__new(&event->attr.attr); |
2920 | if (evsel == NULL) | 2920 | if (evsel == NULL) |
2921 | return -ENOMEM; | 2921 | return -ENOMEM; |
2922 | 2922 | ||
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index c90e55cf7e82..6de6f89c2a61 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c | |||
@@ -277,7 +277,7 @@ static int __add_event(struct list_head *list, int *idx, | |||
277 | 277 | ||
278 | event_attr_init(attr); | 278 | event_attr_init(attr); |
279 | 279 | ||
280 | evsel = perf_evsel__new(attr, (*idx)++); | 280 | evsel = perf_evsel__new_idx(attr, (*idx)++); |
281 | if (!evsel) | 281 | if (!evsel) |
282 | return -ENOMEM; | 282 | return -ENOMEM; |
283 | 283 | ||
@@ -378,7 +378,7 @@ static int add_tracepoint(struct list_head *list, int *idx, | |||
378 | { | 378 | { |
379 | struct perf_evsel *evsel; | 379 | struct perf_evsel *evsel; |
380 | 380 | ||
381 | evsel = perf_evsel__newtp(sys_name, evt_name, (*idx)++); | 381 | evsel = perf_evsel__newtp_idx(sys_name, evt_name, (*idx)++); |
382 | if (!evsel) | 382 | if (!evsel) |
383 | return -ENOMEM; | 383 | return -ENOMEM; |
384 | 384 | ||
@@ -1097,7 +1097,7 @@ static bool is_event_supported(u8 type, unsigned config) | |||
1097 | .threads = { 0 }, | 1097 | .threads = { 0 }, |
1098 | }; | 1098 | }; |
1099 | 1099 | ||
1100 | evsel = perf_evsel__new(&attr, 0); | 1100 | evsel = perf_evsel__new(&attr); |
1101 | if (evsel) { | 1101 | if (evsel) { |
1102 | ret = perf_evsel__open(evsel, NULL, &tmap.map) >= 0; | 1102 | ret = perf_evsel__open(evsel, NULL, &tmap.map) >= 0; |
1103 | perf_evsel__delete(evsel); | 1103 | perf_evsel__delete(evsel); |