diff options
| author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2011-03-10 09:15:54 -0500 |
|---|---|---|
| committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2011-03-10 09:15:54 -0500 |
| commit | a91e5431d54f5359fccb5ec2512f252eb217707e (patch) | |
| tree | 8f8ba4940d9f4e910b339baee13a710baa920378 /tools/perf/util | |
| parent | 6547250381eb315acff3d52b4872ad775359407c (diff) | |
perf session: Use evlist/evsel for managing perf.data attributes
So that we can reuse things like the id to attr lookup routine
(perf_evlist__id2evsel) that uses a hash table instead of the linear
lookup done in the older perf_header_attr routines, etc.
Also to make evsels/evlist more pervasive an API, simplyfing using the
emerging perf lib.
cc: Arun Sharma <arun@sharma-home.net>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Tom Zanussi <tzanussi@gmail.com>
LKML-Reference: <new-submission>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util')
| -rw-r--r-- | tools/perf/util/evlist.c | 26 | ||||
| -rw-r--r-- | tools/perf/util/evlist.h | 4 | ||||
| -rw-r--r-- | tools/perf/util/evsel.c | 21 | ||||
| -rw-r--r-- | tools/perf/util/evsel.h | 9 | ||||
| -rw-r--r-- | tools/perf/util/header.c | 225 | ||||
| -rw-r--r-- | tools/perf/util/header.h | 36 | ||||
| -rw-r--r-- | tools/perf/util/session.c | 74 | ||||
| -rw-r--r-- | tools/perf/util/session.h | 2 |
8 files changed, 140 insertions, 257 deletions
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index 190c64c6e266..d852cefa20de 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c | |||
| @@ -19,7 +19,7 @@ | |||
| 19 | #include <linux/hash.h> | 19 | #include <linux/hash.h> |
| 20 | 20 | ||
| 21 | #define FD(e, x, y) (*(int *)xyarray__entry(e->fd, x, y)) | 21 | #define FD(e, x, y) (*(int *)xyarray__entry(e->fd, x, y)) |
| 22 | #define SID(e, x, y) xyarray__entry(e->id, x, y) | 22 | #define SID(e, x, y) xyarray__entry(e->sample_id, x, y) |
| 23 | 23 | ||
| 24 | void perf_evlist__init(struct perf_evlist *evlist, struct cpu_map *cpus, | 24 | void perf_evlist__init(struct perf_evlist *evlist, struct cpu_map *cpus, |
| 25 | struct thread_map *threads) | 25 | struct thread_map *threads) |
| @@ -106,8 +106,9 @@ void perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd) | |||
| 106 | evlist->nr_fds++; | 106 | evlist->nr_fds++; |
| 107 | } | 107 | } |
| 108 | 108 | ||
| 109 | void perf_evlist__id_hash(struct perf_evlist *evlist, struct perf_evsel *evsel, | 109 | static void perf_evlist__id_hash(struct perf_evlist *evlist, |
| 110 | int cpu, int thread, u64 id) | 110 | struct perf_evsel *evsel, |
| 111 | int cpu, int thread, u64 id) | ||
| 111 | { | 112 | { |
| 112 | int hash; | 113 | int hash; |
| 113 | struct perf_sample_id *sid = SID(evsel, cpu, thread); | 114 | struct perf_sample_id *sid = SID(evsel, cpu, thread); |
| @@ -118,9 +119,16 @@ void perf_evlist__id_hash(struct perf_evlist *evlist, struct perf_evsel *evsel, | |||
| 118 | hlist_add_head(&sid->node, &evlist->heads[hash]); | 119 | hlist_add_head(&sid->node, &evlist->heads[hash]); |
| 119 | } | 120 | } |
| 120 | 121 | ||
| 121 | static int perf_evlist__id_hash_fd(struct perf_evlist *evlist, | 122 | void perf_evlist__id_add(struct perf_evlist *evlist, struct perf_evsel *evsel, |
| 122 | struct perf_evsel *evsel, | 123 | int cpu, int thread, u64 id) |
| 123 | int cpu, int thread, int fd) | 124 | { |
| 125 | perf_evlist__id_hash(evlist, evsel, cpu, thread, id); | ||
| 126 | evsel->id[evsel->ids++] = id; | ||
| 127 | } | ||
| 128 | |||
| 129 | static int perf_evlist__id_add_fd(struct perf_evlist *evlist, | ||
| 130 | struct perf_evsel *evsel, | ||
| 131 | int cpu, int thread, int fd) | ||
| 124 | { | 132 | { |
| 125 | u64 read_data[4] = { 0, }; | 133 | u64 read_data[4] = { 0, }; |
| 126 | int id_idx = 1; /* The first entry is the counter value */ | 134 | int id_idx = 1; /* The first entry is the counter value */ |
| @@ -134,7 +142,7 @@ static int perf_evlist__id_hash_fd(struct perf_evlist *evlist, | |||
| 134 | if (evsel->attr.read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) | 142 | if (evsel->attr.read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) |
| 135 | ++id_idx; | 143 | ++id_idx; |
| 136 | 144 | ||
| 137 | perf_evlist__id_hash(evlist, evsel, cpu, thread, read_data[id_idx]); | 145 | perf_evlist__id_add(evlist, evsel, cpu, thread, read_data[id_idx]); |
| 138 | return 0; | 146 | return 0; |
| 139 | } | 147 | } |
| 140 | 148 | ||
| @@ -292,7 +300,7 @@ int perf_evlist__mmap(struct perf_evlist *evlist, int pages, bool overwrite) | |||
| 292 | 300 | ||
| 293 | list_for_each_entry(evsel, &evlist->entries, node) { | 301 | list_for_each_entry(evsel, &evlist->entries, node) { |
| 294 | if ((evsel->attr.read_format & PERF_FORMAT_ID) && | 302 | if ((evsel->attr.read_format & PERF_FORMAT_ID) && |
| 295 | evsel->id == NULL && | 303 | evsel->sample_id == NULL && |
| 296 | perf_evsel__alloc_id(evsel, cpus->nr, threads->nr) < 0) | 304 | perf_evsel__alloc_id(evsel, cpus->nr, threads->nr) < 0) |
| 297 | return -ENOMEM; | 305 | return -ENOMEM; |
| 298 | 306 | ||
| @@ -308,7 +316,7 @@ int perf_evlist__mmap(struct perf_evlist *evlist, int pages, bool overwrite) | |||
| 308 | goto out_unmap; | 316 | goto out_unmap; |
| 309 | 317 | ||
| 310 | if ((evsel->attr.read_format & PERF_FORMAT_ID) && | 318 | if ((evsel->attr.read_format & PERF_FORMAT_ID) && |
| 311 | perf_evlist__id_hash_fd(evlist, evsel, cpu, thread, fd) < 0) | 319 | perf_evlist__id_add_fd(evlist, evsel, cpu, thread, fd) < 0) |
| 312 | goto out_unmap; | 320 | goto out_unmap; |
| 313 | } | 321 | } |
| 314 | } | 322 | } |
diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h index 078d51256085..8b1cb7a4c5f1 100644 --- a/tools/perf/util/evlist.h +++ b/tools/perf/util/evlist.h | |||
| @@ -38,8 +38,8 @@ void perf_evlist__delete(struct perf_evlist *evlist); | |||
| 38 | void perf_evlist__add(struct perf_evlist *evlist, struct perf_evsel *entry); | 38 | void perf_evlist__add(struct perf_evlist *evlist, struct perf_evsel *entry); |
| 39 | int perf_evlist__add_default(struct perf_evlist *evlist); | 39 | int perf_evlist__add_default(struct perf_evlist *evlist); |
| 40 | 40 | ||
| 41 | void perf_evlist__id_hash(struct perf_evlist *evlist, struct perf_evsel *evsel, | 41 | void perf_evlist__id_add(struct perf_evlist *evlist, struct perf_evsel *evsel, |
| 42 | int cpu, int thread, u64 id); | 42 | int cpu, int thread, u64 id); |
| 43 | 43 | ||
| 44 | int perf_evlist__alloc_pollfd(struct perf_evlist *evlist); | 44 | int perf_evlist__alloc_pollfd(struct perf_evlist *evlist); |
| 45 | void perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd); | 45 | void perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd); |
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 8083d5126fca..662596afd7f1 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c | |||
| @@ -41,8 +41,18 @@ int perf_evsel__alloc_fd(struct perf_evsel *evsel, int ncpus, int nthreads) | |||
| 41 | 41 | ||
| 42 | int perf_evsel__alloc_id(struct perf_evsel *evsel, int ncpus, int nthreads) | 42 | int perf_evsel__alloc_id(struct perf_evsel *evsel, int ncpus, int nthreads) |
| 43 | { | 43 | { |
| 44 | evsel->id = xyarray__new(ncpus, nthreads, sizeof(struct perf_sample_id)); | 44 | evsel->sample_id = xyarray__new(ncpus, nthreads, sizeof(struct perf_sample_id)); |
| 45 | return evsel->id != NULL ? 0 : -ENOMEM; | 45 | if (evsel->sample_id == NULL) |
| 46 | return -ENOMEM; | ||
| 47 | |||
| 48 | evsel->id = zalloc(ncpus * nthreads * sizeof(u64)); | ||
| 49 | if (evsel->id == NULL) { | ||
| 50 | xyarray__delete(evsel->sample_id); | ||
| 51 | evsel->sample_id = NULL; | ||
| 52 | return -ENOMEM; | ||
| 53 | } | ||
| 54 | |||
| 55 | return 0; | ||
| 46 | } | 56 | } |
| 47 | 57 | ||
| 48 | int perf_evsel__alloc_counts(struct perf_evsel *evsel, int ncpus) | 58 | int perf_evsel__alloc_counts(struct perf_evsel *evsel, int ncpus) |
| @@ -60,7 +70,9 @@ void perf_evsel__free_fd(struct perf_evsel *evsel) | |||
| 60 | 70 | ||
| 61 | void perf_evsel__free_id(struct perf_evsel *evsel) | 71 | void perf_evsel__free_id(struct perf_evsel *evsel) |
| 62 | { | 72 | { |
| 63 | xyarray__delete(evsel->id); | 73 | xyarray__delete(evsel->sample_id); |
| 74 | evsel->sample_id = NULL; | ||
| 75 | free(evsel->id); | ||
| 64 | evsel->id = NULL; | 76 | evsel->id = NULL; |
| 65 | } | 77 | } |
| 66 | 78 | ||
| @@ -79,7 +91,8 @@ void perf_evsel__exit(struct perf_evsel *evsel) | |||
| 79 | { | 91 | { |
| 80 | assert(list_empty(&evsel->node)); | 92 | assert(list_empty(&evsel->node)); |
| 81 | xyarray__delete(evsel->fd); | 93 | xyarray__delete(evsel->fd); |
| 82 | xyarray__delete(evsel->id); | 94 | xyarray__delete(evsel->sample_id); |
| 95 | free(evsel->id); | ||
| 83 | } | 96 | } |
| 84 | 97 | ||
| 85 | void perf_evsel__delete(struct perf_evsel *evsel) | 98 | void perf_evsel__delete(struct perf_evsel *evsel) |
diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index 281b60e5fc7b..6710ab538342 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h | |||
| @@ -49,12 +49,17 @@ struct perf_evsel { | |||
| 49 | struct perf_event_attr attr; | 49 | struct perf_event_attr attr; |
| 50 | char *filter; | 50 | char *filter; |
| 51 | struct xyarray *fd; | 51 | struct xyarray *fd; |
| 52 | struct xyarray *id; | 52 | struct xyarray *sample_id; |
| 53 | u64 *id; | ||
| 53 | struct perf_counts *counts; | 54 | struct perf_counts *counts; |
| 54 | int idx; | 55 | int idx; |
| 56 | int ids; | ||
| 55 | struct hists hists; | 57 | struct hists hists; |
| 56 | char *name; | 58 | char *name; |
| 57 | void *priv; | 59 | union { |
| 60 | void *priv; | ||
| 61 | off_t id_offset; | ||
| 62 | }; | ||
| 58 | struct cgroup_sel *cgrp; | 63 | struct cgroup_sel *cgrp; |
| 59 | }; | 64 | }; |
| 60 | 65 | ||
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index 108b0db7bbef..40b10e4d3927 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c | |||
| @@ -9,6 +9,7 @@ | |||
| 9 | #include <linux/kernel.h> | 9 | #include <linux/kernel.h> |
| 10 | 10 | ||
