aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/evlist.c
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2011-11-05 06:41:51 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2011-11-28 07:25:11 -0500
commita8c9ae18d810e1ae12b6ec960907e9af63171d3a (patch)
treeaaeb04c5a0fa18bbafab7bb548142bca36968f02 /tools/perf/util/evlist.c
parent50d08e47bc04eb05502f5c86b70bbd19ef1c2778 (diff)
perf evlist: Introduce add_tracepoints method
Convenient way of asking for tracepoint events to be added to an existing evlist. 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-0ylj4wrg54791u0baqb9swbb@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/evlist.c')
-rw-r--r--tools/perf/util/evlist.c57
1 files changed, 56 insertions, 1 deletions
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 58aa1e0092bd..3bc5a287a9f9 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -6,12 +6,13 @@
6 * 6 *
7 * Released under the GPL v2. (and only v2, not any later version) 7 * Released under the GPL v2. (and only v2, not any later version)
8 */ 8 */
9#include "util.h"
10#include "debugfs.h"
9#include <poll.h> 11#include <poll.h>
10#include "cpumap.h" 12#include "cpumap.h"
11#include "thread_map.h" 13#include "thread_map.h"
12#include "evlist.h" 14#include "evlist.h"
13#include "evsel.h" 15#include "evsel.h"
14#include "util.h"
15 16
16#include "parse-events.h" 17#include "parse-events.h"
17 18
@@ -134,6 +135,60 @@ out_delete_partial_list:
134 return -1; 135 return -1;
135} 136}
136 137
138static int trace_event__id(const char *evname)
139{
140 char *filename, *colon;
141 int err = -1, fd;
142
143 if (asprintf(&filename, "%s/%s/id", tracing_events_path, evname) < 0)
144 return -1;
145
146 colon = strrchr(filename, ':');
147 if (colon != NULL)
148 *colon = '/';
149
150 fd = open(filename, O_RDONLY);
151 if (fd >= 0) {
152 char id[16];
153 if (read(fd, id, sizeof(id)) > 0)
154 err = atoi(id);
155 close(fd);
156 }
157
158 free(filename);
159 return err;
160}
161
162int perf_evlist__add_tracepoints(struct perf_evlist *evlist,
163 const char *tracepoints[],
164 size_t nr_tracepoints)
165{
166 int err;
167 size_t i;
168 struct perf_event_attr *attrs = zalloc(nr_tracepoints * sizeof(*attrs));
169
170 if (attrs == NULL)
171 return -1;
172
173 for (i = 0; i < nr_tracepoints; i++) {
174 err = trace_event__id(tracepoints[i]);
175
176 if (err < 0)
177 goto out_free_attrs;
178
179 attrs[i].type = PERF_TYPE_TRACEPOINT;
180 attrs[i].config = err;
181 attrs[i].sample_type = (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME |
182 PERF_SAMPLE_CPU);
183 attrs[i].sample_period = 1;
184 }
185
186 err = perf_evlist__add_attrs(evlist, attrs, nr_tracepoints);
187out_free_attrs:
188 free(attrs);
189 return err;
190}
191
137void perf_evlist__disable(struct perf_evlist *evlist) 192void perf_evlist__disable(struct perf_evlist *evlist)
138{ 193{
139 int cpu, thread; 194 int cpu, thread;