From 43b0f57f1747994437a954af94acee5c126e1a86 Mon Sep 17 00:00:00 2001 From: Arnaldo Carvalho de Melo Date: Sat, 5 Nov 2011 08:41:51 -0200 Subject: [PATCH] --- yaml --- r: 277279 b: refs/heads/master c: a8c9ae18d810e1ae12b6ec960907e9af63171d3a h: refs/heads/master i: 277277: b867489b26632c4eb5662b89d7b3fc00a0573f69 277275: 033803bc1cfa27ec7bfa9330fcf91f0c091ba235 277271: 1f522cf5dad48420c1972665d6f252519704f077 277263: 8c427ec12d4fe7c08a77e07b0a5a80bc1b2b7f99 277247: 62e164e0e57e929349f32a3829dc504874908abe v: v3 --- [refs] | 2 +- trunk/tools/perf/util/evlist.c | 57 +++++++++++++++++++++++++++++++++- trunk/tools/perf/util/evlist.h | 5 +++ trunk/tools/perf/util/setup.py | 3 +- 4 files changed, 64 insertions(+), 3 deletions(-) diff --git a/[refs] b/[refs] index e6c932a2e1a2..ed2cdad2c2ba 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: 50d08e47bc04eb05502f5c86b70bbd19ef1c2778 +refs/heads/master: a8c9ae18d810e1ae12b6ec960907e9af63171d3a diff --git a/trunk/tools/perf/util/evlist.c b/trunk/tools/perf/util/evlist.c index 58aa1e0092bd..3bc5a287a9f9 100644 --- a/trunk/tools/perf/util/evlist.c +++ b/trunk/tools/perf/util/evlist.c @@ -6,12 +6,13 @@ * * Released under the GPL v2. (and only v2, not any later version) */ +#include "util.h" +#include "debugfs.h" #include #include "cpumap.h" #include "thread_map.h" #include "evlist.h" #include "evsel.h" -#include "util.h" #include "parse-events.h" @@ -134,6 +135,60 @@ int perf_evlist__add_attrs(struct perf_evlist *evlist, return -1; } +static int trace_event__id(const char *evname) +{ + char *filename, *colon; + int err = -1, fd; + + if (asprintf(&filename, "%s/%s/id", tracing_events_path, evname) < 0) + return -1; + + colon = strrchr(filename, ':'); + if (colon != NULL) + *colon = '/'; + + fd = open(filename, O_RDONLY); + if (fd >= 0) { + char id[16]; + if (read(fd, id, sizeof(id)) > 0) + err = atoi(id); + close(fd); + } + + free(filename); + return err; +} + +int perf_evlist__add_tracepoints(struct perf_evlist *evlist, + const char *tracepoints[], + size_t nr_tracepoints) +{ + int err; + size_t i; + struct perf_event_attr *attrs = zalloc(nr_tracepoints * sizeof(*attrs)); + + if (attrs == NULL) + return -1; + + for (i = 0; i < nr_tracepoints; i++) { + err = trace_event__id(tracepoints[i]); + + if (err < 0) + goto out_free_attrs; + + attrs[i].type = PERF_TYPE_TRACEPOINT; + attrs[i].config = err; + attrs[i].sample_type = (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME | + PERF_SAMPLE_CPU); + attrs[i].sample_period = 1; + } + + err = perf_evlist__add_attrs(evlist, attrs, nr_tracepoints); +out_free_attrs: + free(attrs); + return err; +} + void perf_evlist__disable(struct perf_evlist *evlist) { int cpu, thread; diff --git a/trunk/tools/perf/util/evlist.h b/trunk/tools/perf/util/evlist.h index 57d91ff2c56a..ec71c82935bd 100644 --- a/trunk/tools/perf/util/evlist.h +++ b/trunk/tools/perf/util/evlist.h @@ -43,10 +43,15 @@ void perf_evlist__add(struct perf_evlist *evlist, struct perf_evsel *entry); int perf_evlist__add_default(struct perf_evlist *evlist); int perf_evlist__add_attrs(struct perf_evlist *evlist, struct perf_event_attr *attrs, size_t nr_attrs); +int perf_evlist__add_tracepoints(struct perf_evlist *evlist, + const char *tracepoints[], size_t nr_tracepoints); #define perf_evlist__add_attrs_array(evlist, array) \ perf_evlist__add_attrs(evlist, array, ARRAY_SIZE(array)) +#define perf_evlist__add_tracepoints_array(evlist, array) \ + perf_evlist__add_tracepoints(evlist, array, ARRAY_SIZE(array)) + void perf_evlist__id_add(struct perf_evlist *evlist, struct perf_evsel *evsel, int cpu, int thread, u64 id); diff --git a/trunk/tools/perf/util/setup.py b/trunk/tools/perf/util/setup.py index 95d370074928..36d4c5619575 100644 --- a/trunk/tools/perf/util/setup.py +++ b/trunk/tools/perf/util/setup.py @@ -27,7 +27,8 @@ def finalize_options(self): perf = Extension('perf', sources = ['util/python.c', 'util/ctype.c', 'util/evlist.c', 'util/evsel.c', 'util/cpumap.c', 'util/thread_map.c', - 'util/util.c', 'util/xyarray.c', 'util/cgroup.c'], + 'util/util.c', 'util/xyarray.c', 'util/cgroup.c', + 'util/debugfs.c'], include_dirs = ['util/include'], extra_compile_args = cflags, )