aboutsummaryrefslogtreecommitdiffstats
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
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>
-rw-r--r--tools/perf/util/evlist.c57
-rw-r--r--tools/perf/util/evlist.h5
-rw-r--r--tools/perf/util/setup.py3
3 files changed, 63 insertions, 2 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;
diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h
index 57d91ff2c56a..ec71c82935bd 100644
--- a/tools/perf/util/evlist.h
+++ b/tools/perf/util/evlist.h
@@ -43,10 +43,15 @@ void perf_evlist__add(struct perf_evlist *evlist, struct perf_evsel *entry);
43int perf_evlist__add_default(struct perf_evlist *evlist); 43int perf_evlist__add_default(struct perf_evlist *evlist);
44int perf_evlist__add_attrs(struct perf_evlist *evlist, 44int perf_evlist__add_attrs(struct perf_evlist *evlist,
45 struct perf_event_attr *attrs, size_t nr_attrs); 45 struct perf_event_attr *attrs, size_t nr_attrs);
46int perf_evlist__add_tracepoints(struct perf_evlist *evlist,
47 const char *tracepoints[], size_t nr_tracepoints);
46 48
47#define perf_evlist__add_attrs_array(evlist, array) \ 49#define perf_evlist__add_attrs_array(evlist, array) \
48 perf_evlist__add_attrs(evlist, array, ARRAY_SIZE(array)) 50 perf_evlist__add_attrs(evlist, array, ARRAY_SIZE(array))
49 51
52#define perf_evlist__add_tracepoints_array(evlist, array) \
53 perf_evlist__add_tracepoints(evlist, array, ARRAY_SIZE(array))
54
50void perf_evlist__id_add(struct perf_evlist *evlist, struct perf_evsel *evsel, 55void perf_evlist__id_add(struct perf_evlist *evlist, struct perf_evsel *evsel,
51 int cpu, int thread, u64 id); 56 int cpu, int thread, u64 id);
52 57
diff --git a/tools/perf/util/setup.py b/tools/perf/util/setup.py
index 95d370074928..36d4c5619575 100644
--- a/tools/perf/util/setup.py
+++ b/tools/perf/util/setup.py
@@ -27,7 +27,8 @@ build_tmp = getenv('PYTHON_EXTBUILD_TMP')
27perf = Extension('perf', 27perf = Extension('perf',
28 sources = ['util/python.c', 'util/ctype.c', 'util/evlist.c', 28 sources = ['util/python.c', 'util/ctype.c', 'util/evlist.c',
29 'util/evsel.c', 'util/cpumap.c', 'util/thread_map.c', 29 'util/evsel.c', 'util/cpumap.c', 'util/thread_map.c',
30 'util/util.c', 'util/xyarray.c', 'util/cgroup.c'], 30 'util/util.c', 'util/xyarray.c', 'util/cgroup.c',
31 'util/debugfs.c'],
31 include_dirs = ['util/include'], 32 include_dirs = ['util/include'],
32 extra_compile_args = cflags, 33 extra_compile_args = cflags,
33 ) 34 )