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 | |
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')
-rw-r--r-- | tools/perf/builtin-trace.c | 13 | ||||
-rw-r--r-- | tools/perf/tests/evsel-tp-sched.c | 4 | ||||
-rw-r--r-- | tools/perf/tests/mmap-basic.c | 2 | ||||
-rw-r--r-- | tools/perf/tests/open-syscall-all-cpus.c | 2 | ||||
-rw-r--r-- | tools/perf/tests/open-syscall-tp-fields.c | 2 | ||||
-rw-r--r-- | tools/perf/tests/open-syscall.c | 2 | ||||
-rw-r--r-- | tools/perf/tests/sw-clock.c | 2 | ||||
-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 |
12 files changed, 37 insertions, 28 deletions
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index 329b7832b5da..68943cad70d4 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c | |||
@@ -149,10 +149,9 @@ static void perf_evsel__delete_priv(struct perf_evsel *evsel) | |||
149 | perf_evsel__delete(evsel); | 149 | perf_evsel__delete(evsel); |
150 | } | 150 | } |
151 | 151 | ||
152 | static struct perf_evsel *perf_evsel__syscall_newtp(const char *direction, | 152 | static struct perf_evsel *perf_evsel__syscall_newtp(const char *direction, void *handler) |
153 | void *handler, int idx) | ||
154 | { | 153 | { |
155 | struct perf_evsel *evsel = perf_evsel__newtp("raw_syscalls", direction, idx); | 154 | struct perf_evsel *evsel = perf_evsel__newtp("raw_syscalls", direction); |
156 | 155 | ||
157 | if (evsel) { | 156 | if (evsel) { |
158 | evsel->priv = malloc(sizeof(struct syscall_tp)); | 157 | evsel->priv = malloc(sizeof(struct syscall_tp)); |
@@ -186,17 +185,16 @@ static int perf_evlist__add_syscall_newtp(struct perf_evlist *evlist, | |||
186 | void *sys_exit_handler) | 185 | void *sys_exit_handler) |
187 | { | 186 | { |
188 | int ret = -1; | 187 | int ret = -1; |
189 | int idx = evlist->nr_entries; | ||
190 | struct perf_evsel *sys_enter, *sys_exit; | 188 | struct perf_evsel *sys_enter, *sys_exit; |
191 | 189 | ||
192 | sys_enter = perf_evsel__syscall_newtp("sys_enter", sys_enter_handler, idx++); | 190 | sys_enter = perf_evsel__syscall_newtp("sys_enter", sys_enter_handler); |
193 | if (sys_enter == NULL) | 191 | if (sys_enter == NULL) |
194 | goto out; | 192 | goto out; |
195 | 193 | ||
196 | if (perf_evsel__init_sc_tp_ptr_field(sys_enter, args)) | 194 | if (perf_evsel__init_sc_tp_ptr_field(sys_enter, args)) |
197 | goto out_delete_sys_enter; | 195 | goto out_delete_sys_enter; |
198 | 196 | ||
199 | sys_exit = perf_evsel__syscall_newtp("sys_exit", sys_exit_handler, idx++); | 197 | sys_exit = perf_evsel__syscall_newtp("sys_exit", sys_exit_handler); |
200 | if (sys_exit == NULL) | 198 | if (sys_exit == NULL) |
201 | goto out_delete_sys_enter; | 199 | goto out_delete_sys_enter; |
202 | 200 | ||
@@ -1824,8 +1822,7 @@ static size_t trace__fprintf_thread_summary(struct trace *trace, FILE *fp); | |||
1824 | 1822 | ||
1825 | static void perf_evlist__add_vfs_getname(struct perf_evlist *evlist) | 1823 | static void perf_evlist__add_vfs_getname(struct perf_evlist *evlist) |
1826 | { | 1824 | { |
1827 | struct perf_evsel *evsel = perf_evsel__newtp("probe", "vfs_getname", | 1825 | struct perf_evsel *evsel = perf_evsel__newtp("probe", "vfs_getname"); |
1828 | evlist->nr_entries); | ||
1829 | if (evsel == NULL) | 1826 | if (evsel == NULL) |
1830 | return; | 1827 | return; |
1831 | 1828 | ||
diff --git a/tools/perf/tests/evsel-tp-sched.c b/tools/perf/tests/evsel-tp-sched.c index 9b98c1554833..4774f7fbb758 100644 --- a/tools/perf/tests/evsel-tp-sched.c +++ b/tools/perf/tests/evsel-tp-sched.c | |||
@@ -32,7 +32,7 @@ static int perf_evsel__test_field(struct perf_evsel *evsel, const char *name, | |||
32 | 32 | ||
33 | int test__perf_evsel__tp_sched_test(void) | 33 | int test__perf_evsel__tp_sched_test(void) |
34 | { | 34 | { |
35 | struct perf_evsel *evsel = perf_evsel__newtp("sched", "sched_switch", 0); | 35 | struct perf_evsel *evsel = perf_evsel__newtp("sched", "sched_switch"); |
36 | int ret = 0; | 36 | int ret = 0; |
37 | 37 | ||
38 | if (evsel == NULL) { | 38 | if (evsel == NULL) { |
@@ -63,7 +63,7 @@ int test__perf_evsel__tp_sched_test(void) | |||
63 | 63 | ||
64 | perf_evsel__delete(evsel); | 64 | perf_evsel__delete(evsel); |
65 | 65 | ||
66 | evsel = perf_evsel__newtp("sched", "sched_wakeup", 0); | 66 | evsel = perf_evsel__newtp("sched", "sched_wakeup"); |
67 | 67 | ||
68 | if (perf_evsel__test_field(evsel, "comm", 16, true)) | 68 | if (perf_evsel__test_field(evsel, "comm", 16, true)) |
69 | ret = -1; | 69 | ret = -1; |
diff --git a/tools/perf/tests/mmap-basic.c b/tools/perf/tests/mmap-basic.c index a7232c204eb9..d64ab79c6d35 100644 --- a/tools/perf/tests/mmap-basic.c +++ b/tools/perf/tests/mmap-basic.c | |||
@@ -65,7 +65,7 @@ int test__basic_mmap(void) | |||
65 | char name[64]; | 65 | char name[64]; |
66 | 66 | ||
67 | snprintf(name, sizeof(name), "sys_enter_%s", syscall_names[i]); | 67 | snprintf(name, sizeof(name), "sys_enter_%s", syscall_names[i]); |
68 | evsels[i] = perf_evsel__newtp("syscalls", name, i); | 68 | evsels[i] = perf_evsel__newtp("syscalls", name); |
69 | if (evsels[i] == NULL) { | 69 | if (evsels[i] == NULL) { |
70 | pr_debug("perf_evsel__new\n"); | 70 | pr_debug("perf_evsel__new\n"); |
71 | goto out_free_evlist; | 71 | goto out_free_evlist; |
diff --git a/tools/perf/tests/open-syscall-all-cpus.c b/tools/perf/tests/open-syscall-all-cpus.c index b0657a9ccda6..5fecdbd2f5f7 100644 --- a/tools/perf/tests/open-syscall-all-cpus.c +++ b/tools/perf/tests/open-syscall-all-cpus.c | |||
@@ -26,7 +26,7 @@ int test__open_syscall_event_on_all_cpus(void) | |||
26 | 26 | ||
27 | CPU_ZERO(&cpu_set); | 27 | CPU_ZERO(&cpu_set); |
28 | 28 | ||
29 | evsel = perf_evsel__newtp("syscalls", "sys_enter_open", 0); | 29 | evsel = perf_evsel__newtp("syscalls", "sys_enter_open"); |
30 | if (evsel == NULL) { | 30 | if (evsel == NULL) { |
31 | pr_debug("is debugfs mounted on /sys/kernel/debug?\n"); | 31 | pr_debug("is debugfs mounted on /sys/kernel/debug?\n"); |
32 | goto out_thread_map_delete; | 32 | goto out_thread_map_delete; |
diff --git a/tools/perf/tests/open-syscall-tp-fields.c b/tools/perf/tests/open-syscall-tp-fields.c index 524b221b829b..41cc0badb74b 100644 --- a/tools/perf/tests/open-syscall-tp-fields.c +++ b/tools/perf/tests/open-syscall-tp-fields.c | |||
@@ -27,7 +27,7 @@ int test__syscall_open_tp_fields(void) | |||
27 | goto out; | 27 | goto out; |
28 | } | 28 | } |
29 | 29 | ||
30 | evsel = perf_evsel__newtp("syscalls", "sys_enter_open", 0); | 30 | evsel = perf_evsel__newtp("syscalls", "sys_enter_open"); |
31 | if (evsel == NULL) { | 31 | if (evsel == NULL) { |
32 | pr_debug("%s: perf_evsel__newtp\n", __func__); | 32 | pr_debug("%s: perf_evsel__newtp\n", __func__); |
33 | goto out_delete_evlist; | 33 | goto out_delete_evlist; |
diff --git a/tools/perf/tests/open-syscall.c b/tools/perf/tests/open-syscall.c index befc0671f95d..c1dc7d25f38c 100644 --- a/tools/perf/tests/open-syscall.c +++ b/tools/perf/tests/open-syscall.c | |||
@@ -15,7 +15,7 @@ int test__open_syscall_event(void) | |||
15 | return -1; | 15 | return -1; |
16 | } | 16 | } |
17 | 17 | ||
18 | evsel = perf_evsel__newtp("syscalls", "sys_enter_open", 0); | 18 | evsel = perf_evsel__newtp("syscalls", "sys_enter_open"); |
19 | if (evsel == NULL) { | 19 | if (evsel == NULL) { |
20 | pr_debug("is debugfs mounted on /sys/kernel/debug?\n"); | 20 | pr_debug("is debugfs mounted on /sys/kernel/debug?\n"); |
21 | goto out_thread_map_delete; | 21 | goto out_thread_map_delete; |
diff --git a/tools/perf/tests/sw-clock.c b/tools/perf/tests/sw-clock.c index 6e2b44ec0749..73c5c37cb27b 100644 --- a/tools/perf/tests/sw-clock.c +++ b/tools/perf/tests/sw-clock.c | |||
@@ -42,7 +42,7 @@ static int __test__sw_clock_freq(enum perf_sw_ids clock_id) | |||
42 | return -1; | 42 | return -1; |
43 | } | 43 | } |
44 | 44 | ||
45 | evsel = perf_evsel__new(&attr, 0); | 45 | evsel = perf_evsel__new(&attr); |
46 | if (evsel == NULL) { | 46 | if (evsel == NULL) { |
47 | pr_debug("perf_evsel__new\n"); | 47 | pr_debug("perf_evsel__new\n"); |
48 | goto out_free_evlist; | 48 | goto out_free_evlist; |
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); |