diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2011-11-04 07:10:59 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2011-11-28 07:24:43 -0500 |
commit | 50d08e47bc04eb05502f5c86b70bbd19ef1c2778 (patch) | |
tree | 655bddc48548db3d878ab416fddc13b3e6d34a6c | |
parent | ebf294bf4f147aff29df5a16bfb0f8ebca15feaa (diff) |
perf evlist: Introduce perf_evlist__add_attrs
Replacing the open coded equivalents in 'perf stat'.
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.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-1btwadnf2tds2g07hsccsdse@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r-- | tools/perf/builtin-stat.c | 40 | ||||
-rw-r--r-- | tools/perf/util/evlist.c | 34 | ||||
-rw-r--r-- | tools/perf/util/evlist.h | 7 |
3 files changed, 48 insertions, 33 deletions
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 7d98676808d8..227befbecec8 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c | |||
@@ -1107,22 +1107,13 @@ static const struct option options[] = { | |||
1107 | */ | 1107 | */ |
1108 | static int add_default_attributes(void) | 1108 | static int add_default_attributes(void) |
1109 | { | 1109 | { |
1110 | struct perf_evsel *pos; | ||
1111 | size_t attr_nr = 0; | ||
1112 | size_t c; | ||
1113 | |||
1114 | /* Set attrs if no event is selected and !null_run: */ | 1110 | /* Set attrs if no event is selected and !null_run: */ |
1115 | if (null_run) | 1111 | if (null_run) |
1116 | return 0; | 1112 | return 0; |
1117 | 1113 | ||
1118 | if (!evsel_list->nr_entries) { | 1114 | if (!evsel_list->nr_entries) { |
1119 | for (c = 0; c < ARRAY_SIZE(default_attrs); c++) { | 1115 | if (perf_evlist__add_attrs_array(evsel_list, default_attrs) < 0) |
1120 | pos = perf_evsel__new(default_attrs + c, c + attr_nr); | 1116 | return -1; |
1121 | if (pos == NULL) | ||
1122 | return -1; | ||
1123 | perf_evlist__add(evsel_list, pos); | ||
1124 | } | ||
1125 | attr_nr += c; | ||
1126 | } | 1117 | } |
1127 | 1118 | ||
1128 | /* Detailed events get appended to the event list: */ | 1119 | /* Detailed events get appended to the event list: */ |
@@ -1131,38 +1122,21 @@ static int add_default_attributes(void) | |||
1131 | return 0; | 1122 | return 0; |
1132 | 1123 | ||
1133 | /* Append detailed run extra attributes: */ | 1124 | /* Append detailed run extra attributes: */ |
1134 | for (c = 0; c < ARRAY_SIZE(detailed_attrs); c++) { | 1125 | if (perf_evlist__add_attrs_array(evsel_list, detailed_attrs) < 0) |
1135 | pos = perf_evsel__new(detailed_attrs + c, c + attr_nr); | 1126 | return -1; |
1136 | if (pos == NULL) | ||
1137 | return -1; | ||
1138 | perf_evlist__add(evsel_list, pos); | ||
1139 | } | ||
1140 | attr_nr += c; | ||
1141 | 1127 | ||
1142 | if (detailed_run < 2) | 1128 | if (detailed_run < 2) |
1143 | return 0; | 1129 | return 0; |
1144 | 1130 | ||
1145 | /* Append very detailed run extra attributes: */ | 1131 | /* Append very detailed run extra attributes: */ |
1146 | for (c = 0; c < ARRAY_SIZE(very_detailed_attrs); c++) { | 1132 | if (perf_evlist__add_attrs_array(evsel_list, very_detailed_attrs) < 0) |
1147 | pos = perf_evsel__new(very_detailed_attrs + c, c + attr_nr); | 1133 | return -1; |
1148 | if (pos == NULL) | ||
1149 | return -1; | ||
1150 | perf_evlist__add(evsel_list, pos); | ||
1151 | } | ||
1152 | 1134 | ||
1153 | if (detailed_run < 3) | 1135 | if (detailed_run < 3) |
1154 | return 0; | 1136 | return 0; |
1155 | 1137 | ||
1156 | /* Append very, very detailed run extra attributes: */ | 1138 | /* Append very, very detailed run extra attributes: */ |
1157 | for (c = 0; c < ARRAY_SIZE(very_very_detailed_attrs); c++) { | 1139 | return perf_evlist__add_attrs_array(evsel_list, very_very_detailed_attrs); |
1158 | pos = perf_evsel__new(very_very_detailed_attrs + c, c + attr_nr); | ||
1159 | if (pos == NULL) | ||
1160 | return -1; | ||
1161 | perf_evlist__add(evsel_list, pos); | ||
1162 | } | ||
1163 | |||
1164 | |||
1165 | return 0; | ||
1166 | } | 1140 | } |
1167 | 1141 | ||
1168 | int cmd_stat(int argc, const char **argv, const char *prefix __used) | 1142 | int cmd_stat(int argc, const char **argv, const char *prefix __used) |
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index fbb4b4ab9cc6..58aa1e0092bd 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c | |||
@@ -13,6 +13,8 @@ | |||
13 | #include "evsel.h" | 13 | #include "evsel.h" |
14 | #include "util.h" | 14 | #include "util.h" |
15 | 15 | ||
16 | #include "parse-events.h" | ||
17 | |||
16 | #include <sys/mman.h> | 18 | #include <sys/mman.h> |
17 | 19 | ||
18 | #include <linux/bitops.h> | 20 | #include <linux/bitops.h> |
@@ -76,6 +78,14 @@ void perf_evlist__add(struct perf_evlist *evlist, struct perf_evsel *entry) | |||
76 | ++evlist->nr_entries; | 78 | ++evlist->nr_entries; |
77 | } | 79 | } |
78 | 80 | ||
81 | static void perf_evlist__splice_list_tail(struct perf_evlist *evlist, | ||
82 | struct list_head *list, | ||
83 | int nr_entries) | ||
84 | { | ||
85 | list_splice_tail(list, &evlist->entries); | ||
86 | evlist->nr_entries += nr_entries; | ||
87 | } | ||
88 | |||
79 | int perf_evlist__add_default(struct perf_evlist *evlist) | 89 | int perf_evlist__add_default(struct perf_evlist *evlist) |
80 | { | 90 | { |
81 | struct perf_event_attr attr = { | 91 | struct perf_event_attr attr = { |
@@ -100,6 +110,30 @@ error: | |||
100 | return -ENOMEM; | 110 | return -ENOMEM; |
101 | } | 111 | } |
102 | 112 | ||
113 | int perf_evlist__add_attrs(struct perf_evlist *evlist, | ||
114 | struct perf_event_attr *attrs, size_t nr_attrs) | ||
115 | { | ||
116 | struct perf_evsel *evsel, *n; | ||
117 | LIST_HEAD(head); | ||
118 | size_t i; | ||
119 | |||
120 | for (i = 0; i < nr_attrs; i++) { | ||
121 | evsel = perf_evsel__new(attrs + i, evlist->nr_entries + i); | ||
122 | if (evsel == NULL) | ||
123 | goto out_delete_partial_list; | ||
124 | list_add_tail(&evsel->node, &head); | ||
125 | } | ||
126 | |||
127 | perf_evlist__splice_list_tail(evlist, &head, nr_attrs); | ||
128 | |||
129 | return 0; | ||
130 | |||
131 | out_delete_partial_list: | ||
132 | list_for_each_entry_safe(evsel, n, &head, node) | ||
133 | perf_evsel__delete(evsel); | ||
134 | return -1; | ||
135 | } | ||
136 | |||
103 | void perf_evlist__disable(struct perf_evlist *evlist) | 137 | void perf_evlist__disable(struct perf_evlist *evlist) |
104 | { | 138 | { |
105 | int cpu, thread; | 139 | int cpu, thread; |
diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h index 1779ffef7828..57d91ff2c56a 100644 --- a/tools/perf/util/evlist.h +++ b/tools/perf/util/evlist.h | |||
@@ -2,8 +2,10 @@ | |||
2 | #define __PERF_EVLIST_H 1 | 2 | #define __PERF_EVLIST_H 1 |
3 | 3 | ||
4 | #include <linux/list.h> | 4 | #include <linux/list.h> |
5 | #include <stdio.h> | ||
5 | #include "../perf.h" | 6 | #include "../perf.h" |
6 | #include "event.h" | 7 | #include "event.h" |
8 | #include "util.h" | ||
7 | 9 | ||
8 | struct pollfd; | 10 | struct pollfd; |
9 | struct thread_map; | 11 | struct thread_map; |
@@ -39,6 +41,11 @@ void perf_evlist__delete(struct perf_evlist *evlist); | |||
39 | 41 | ||
40 | void perf_evlist__add(struct perf_evlist *evlist, struct perf_evsel *entry); | 42 | void perf_evlist__add(struct perf_evlist *evlist, struct perf_evsel *entry); |
41 | int perf_evlist__add_default(struct perf_evlist *evlist); | 43 | int perf_evlist__add_default(struct perf_evlist *evlist); |
44 | int perf_evlist__add_attrs(struct perf_evlist *evlist, | ||
45 | struct perf_event_attr *attrs, size_t nr_attrs); | ||
46 | |||
47 | #define perf_evlist__add_attrs_array(evlist, array) \ | ||
48 | perf_evlist__add_attrs(evlist, array, ARRAY_SIZE(array)) | ||
42 | 49 | ||
43 | void perf_evlist__id_add(struct perf_evlist *evlist, struct perf_evsel *evsel, | 50 | void perf_evlist__id_add(struct perf_evlist *evlist, struct perf_evsel *evsel, |
44 | int cpu, int thread, u64 id); | 51 | int cpu, int thread, u64 id); |