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 | ||
11 | #include "evlist.h" | 11 | #include "evlist.h" |
12 | #include "evsel.h" | ||
12 | #include "util.h" | 13 | #include "util.h" |
13 | #include "header.h" | 14 | #include "header.h" |
14 | #include "../perf.h" | 15 | #include "../perf.h" |
@@ -19,89 +20,6 @@ | |||
19 | 20 | ||
20 | static bool no_buildid_cache = false; | 21 | static bool no_buildid_cache = false; |
21 | 22 | ||
22 | /* | ||
23 | * Create new perf.data header attribute: | ||
24 | */ | ||
25 | struct perf_header_attr *perf_header_attr__new(struct perf_event_attr *attr) | ||
26 | { | ||
27 | struct perf_header_attr *self = malloc(sizeof(*self)); | ||
28 | |||
29 | if (self != NULL) { | ||
30 | self->attr = *attr; | ||
31 | self->ids = 0; | ||
32 | self->size = 1; | ||
33 | self->id = malloc(sizeof(u64)); | ||
34 | if (self->id == NULL) { | ||
35 | free(self); | ||
36 | self = NULL; | ||
37 | } | ||
38 | } | ||
39 | |||
40 | return self; | ||
41 | } | ||
42 | |||
43 | void perf_header_attr__delete(struct perf_header_attr *self) | ||
44 | { | ||
45 | free(self->id); | ||
46 | free(self); | ||
47 | } | ||
48 | |||
49 | int perf_header_attr__add_id(struct perf_header_attr *self, u64 id) | ||
50 | { | ||
51 | int pos = self->ids; | ||
52 | |||
53 | self->ids++; | ||
54 | if (self->ids > self->size) { | ||
55 | int nsize = self->size * 2; | ||
56 | u64 *nid = realloc(self->id, nsize * sizeof(u64)); | ||
57 | |||
58 | if (nid == NULL) | ||
59 | return -1; | ||
60 | |||
61 | self->size = nsize; | ||
62 | self->id = nid; | ||
63 | } | ||
64 | self->id[pos] = id; | ||
65 | return 0; | ||
66 | } | ||
67 | |||
68 | int perf_header__init(struct perf_header *self) | ||
69 | { | ||
70 | self->size = 1; | ||
71 | self->attr = malloc(sizeof(void *)); | ||
72 | return self->attr == NULL ? -ENOMEM : 0; | ||
73 | } | ||
74 | |||
75 | void perf_header__exit(struct perf_header *self) | ||
76 | { | ||
77 | int i; | ||
78 | for (i = 0; i < self->attrs; ++i) | ||
79 | perf_header_attr__delete(self->attr[i]); | ||
80 | free(self->attr); | ||
81 | } | ||
82 | |||
83 | int perf_header__add_attr(struct perf_header *self, | ||
84 | struct perf_header_attr *attr) | ||
85 | { | ||
86 | if (self->frozen) | ||
87 | return -1; | ||
88 | |||
89 | if (self->attrs == self->size) { | ||
90 | int nsize = self->size * 2; | ||
91 | struct perf_header_attr **nattr; | ||
92 | |||
93 | nattr = realloc(self->attr, nsize * sizeof(void *)); | ||
94 | if (nattr == NULL) | ||
95 | return -1; | ||
96 | |||
97 | self->size = nsize; | ||
98 | self->attr = nattr; | ||
99 | } | ||
100 | |||
101 | self->attr[self->attrs++] = attr; | ||
102 | return 0; | ||
103 | } | ||
104 | |||
105 | static int event_count; | 23 | static int event_count; |
106 | static struct perf_trace_event_type *events; | 24 | static struct perf_trace_event_type *events; |
107 | 25 | ||
@@ -515,33 +433,41 @@ int perf_header__write_pipe(int fd) | |||
515 | return 0; | 433 | return 0; |
516 | } | 434 | } |
517 | 435 | ||
518 | int perf_header__write(struct perf_header *self, struct perf_evlist *evlist, | 436 | int perf_session__write_header(struct perf_session *session, |
519 | int fd, bool at_exit) | 437 | struct perf_evlist *evlist, |
438 | int fd, bool at_exit) | ||
520 | { | 439 | { |
521 | struct perf_file_header f_header; | 440 | struct perf_file_header f_header; |
522 | struct perf_file_attr f_attr; | 441 | struct perf_file_attr f_attr; |
523 | struct perf_header_attr *attr; | 442 | struct perf_header *self = &session->header; |
524 | int i, err; | 443 | struct perf_evsel *attr, *pair = NULL; |
444 | int err; | ||
525 | 445 | ||
526 | lseek(fd, sizeof(f_header), SEEK_SET); | 446 | lseek(fd, sizeof(f_header), SEEK_SET); |
527 | 447 | ||
528 | for (i = 0; i < self->attrs; i++) { | 448 | if (session->evlist != evlist) |
529 | attr = self->attr[i]; | 449 | pair = list_entry(session->evlist->entries.next, struct perf_evsel, node); |
530 | 450 | ||
451 | list_for_each_entry(attr, &evlist->entries, node) { | ||
531 | attr->id_offset = lseek(fd, 0, SEEK_CUR); | 452 | attr->id_offset = lseek(fd, 0, SEEK_CUR); |
532 | err = do_write(fd, attr->id, attr->ids * sizeof(u64)); | 453 | err = do_write(fd, attr->id, attr->ids * sizeof(u64)); |
533 | if (err < 0) { | 454 | if (err < 0) { |
455 | out_err_write: | ||
534 | pr_debug("failed to write perf header\n"); | 456 | pr_debug("failed to write perf header\n"); |
535 | return err; | 457 | return err; |
536 | } | 458 | } |
459 | if (session->evlist != evlist) { | ||
460 | err = do_write(fd, pair->id, pair->ids * sizeof(u64)); | ||
461 | if (err < 0) | ||
462 | goto out_err_write; | ||
463 | attr->ids += pair->ids; | ||
464 | pair = list_entry(pair->node.next, struct perf_evsel, node); | ||
465 | } | ||
537 | } | 466 | } |
538 | 467 | ||
539 | |||
540 | self->attr_offset = lseek(fd, 0, SEEK_CUR); | 468 | self->attr_offset = lseek(fd, 0, SEEK_CUR); |
541 | 469 | ||
542 | for (i = 0; i < self->attrs; i++) { | 470 | list_for_each_entry(attr, &evlist->entries, node) { |
543 | attr = self->attr[i]; | ||
544 | |||
545 | f_attr = (struct perf_file_attr){ | 471 | f_attr = (struct perf_file_attr){ |
546 | .attr = attr->attr, | 472 | .attr = attr->attr, |
547 | .ids = { | 473 | .ids = { |
@@ -580,7 +506,7 @@ int perf_header__write(struct perf_header *self, struct perf_evlist *evlist, | |||
580 | .attr_size = sizeof(f_attr), | 506 | .attr_size = sizeof(f_attr), |
581 | .attrs = { | 507 | .attrs = { |
582 | .offset = self->attr_offset, | 508 | .offset = self->attr_offset, |
583 | .size = self->attrs * sizeof(f_attr), | 509 | .size = evlist->nr_entries * sizeof(f_attr), |
584 | }, | 510 | }, |
585 | .data = { | 511 | .data = { |
586 | .offset = self->data_offset, | 512 | .offset = self->data_offset, |
@@ -861,7 +787,7 @@ static int perf_header__read_pipe(struct perf_session *session, int fd) | |||
861 | return 0; | 787 | return 0; |
862 | } | 788 | } |
863 | 789 | ||
864 | int perf_header__read(struct perf_session *session, int fd) | 790 | int perf_session__read_header(struct perf_session *session, int fd) |
865 | { | 791 | { |
866 | struct perf_header *self = &session->header; | 792 | struct perf_header *self = &session->header; |
867 | struct perf_file_header f_header; | 793 | struct perf_file_header f_header; |
@@ -869,6 +795,10 @@ int perf_header__read(struct perf_session *session, int fd) | |||
869 | u64 f_id; | 795 | u64 f_id; |
870 | int nr_attrs, nr_ids, i, j; | 796 | int nr_attrs, nr_ids, i, j; |
871 | 797 | ||
798 | session->evlist = perf_evlist__new(NULL, NULL); | ||
799 | if (session->evlist == NULL) | ||
800 | return -ENOMEM; | ||
801 | |||
872 | if (session->fd_pipe) | 802 | if (session->fd_pipe) |
873 | return perf_header__read_pipe(session, fd); | 803 | return perf_header__read_pipe(session, fd); |
874 | 804 | ||
@@ -881,33 +811,39 @@ int perf_header__read(struct perf_session *session, int fd) | |||
881 | lseek(fd, f_header.attrs.offset, SEEK_SET); | 811 | lseek(fd, f_header.attrs.offset, SEEK_SET); |
882 | 812 | ||
883 | for (i = 0; i < nr_attrs; i++) { | 813 | for (i = 0; i < nr_attrs; i++) { |
884 | struct perf_header_attr *attr; | 814 | struct perf_evsel *evsel; |
885 | off_t tmp; | 815 | off_t tmp; |
886 | 816 | ||
887 | if (perf_header__getbuffer64(self, fd, &f_attr, sizeof(f_attr))) | 817 | if (perf_header__getbuffer64(self, fd, &f_attr, sizeof(f_attr))) |
888 | goto out_errno; | 818 | goto out_errno; |
889 | 819 | ||
890 | tmp = lseek(fd, 0, SEEK_CUR); | 820 | tmp = lseek(fd, 0, SEEK_CUR); |
821 | evsel = perf_evsel__new(&f_attr.attr, i); | ||
891 | 822 | ||
892 | attr = perf_header_attr__new(&f_attr.attr); | 823 | if (evsel == NULL) |
893 | if (attr == NULL) | 824 | goto out_delete_evlist; |
894 | return -ENOMEM; | 825 | /* |
826 | * Do it before so that if perf_evsel__alloc_id fails, this | ||
827 | * entry gets purged too at perf_evlist__delete(). | ||
828 | */ | ||
829 | perf_evlist__add(session->evlist, evsel); | ||
895 | 830 | ||
896 | nr_ids = f_attr.ids.size / sizeof(u64); | 831 | nr_ids = f_attr.ids.size / sizeof(u64); |
832 | /* | ||
833 | * We don't have the cpu and thread maps on the header, so | ||
834 | * for allocating the perf_sample_id table we fake 1 cpu and | ||
835 | * hattr->ids threads. | ||
836 | */ | ||
837 | if (perf_evsel__alloc_id(evsel, 1, nr_ids)) | ||
838 | goto out_delete_evlist; | ||
839 | |||
897 | lseek(fd, f_attr.ids.offset, SEEK_SET); | 840 | lseek(fd, f_attr.ids.offset, SEEK_SET); |
898 | 841 | ||
899 | for (j = 0; j < nr_ids; j++) { | 842 | for (j = 0; j < nr_ids; j++) { |
900 | if (perf_header__getbuffer64(self, fd, &f_id, sizeof(f_id))) | 843 | if (perf_header__getbuffer64(self, fd, &f_id, sizeof(f_id))) |
901 | goto out_errno; | 844 | goto out_errno; |
902 | 845 | ||
903 | if (perf_header_attr__add_id(attr, f_id) < 0) { | 846 | perf_evlist__id_add(session->evlist, evsel, 0, j, f_id); |
904 | perf_header_attr__delete(attr); | ||
905 | return -ENOMEM; | ||
906 | } | ||
907 | } | ||
908 | if (perf_header__add_attr(self, attr) < 0) { | ||
909 | perf_header_attr__delete(attr); | ||
910 | return -ENOMEM; | ||
911 | } | 847 | } |
912 | 848 | ||
913 | lseek(fd, tmp, SEEK_SET); | 849 | lseek(fd, tmp, SEEK_SET); |
@@ -932,37 +868,38 @@ int perf_header__read(struct perf_session *session, int fd) | |||
932 | return 0; | 868 | return 0; |
933 | out_errno: | 869 | out_errno: |
934 | return -errno; | 870 | return -errno; |
871 | |||
872 | out_delete_evlist: | ||
873 | perf_evlist__delete(session->evlist); | ||
874 | session->evlist = NULL; | ||
875 | return -ENOMEM; | ||
935 | } | 876 | } |
936 | 877 | ||
937 | u64 perf_header__sample_type(struct perf_header *header) | 878 | u64 perf_evlist__sample_type(struct perf_evlist *evlist) |
938 | { | 879 | { |
880 | struct perf_evsel *pos; | ||
939 | u64 type = 0; | 881 | u64 type = 0; |
940 | int i; | ||
941 | |||
942 | for (i = 0; i < header->attrs; i++) { | ||
943 | struct perf_header_attr *attr = header->attr[i]; | ||
944 | 882 | ||
883 | list_for_each_entry(pos, &evlist->entries, node) { | ||
945 | if (!type) | 884 | if (!type) |
946 | type = attr->attr.sample_type; | 885 | type = pos->attr.sample_type; |
947 | else if (type != attr->attr.sample_type) | 886 | else if (type != pos->attr.sample_type) |
948 | die("non matching sample_type"); | 887 | die("non matching sample_type"); |
949 | } | 888 | } |
950 | 889 | ||
951 | return type; | 890 | return type; |
952 | } | 891 | } |
953 | 892 | ||
954 | bool perf_header__sample_id_all(const struct perf_header *header) | 893 | bool perf_evlist__sample_id_all(const struct perf_evlist *evlist) |
955 | { | 894 | { |
956 | bool value = false, first = true; | 895 | bool value = false, first = true; |
957 | int i; | 896 | struct perf_evsel *pos; |
958 | |||
959 | for (i = 0; i < header->attrs; i++) { | ||
960 | struct perf_header_attr *attr = header->attr[i]; | ||
961 | 897 | ||
898 | list_for_each_entry(pos, &evlist->entries, node) { | ||
962 | if (first) { | 899 | if (first) { |
963 | value = attr->attr.sample_id_all; | 900 | value = pos->attr.sample_id_all; |
964 | first = false; | 901 | first = false; |
965 | } else if (value != attr->attr.sample_id_all) | 902 | } else if (value != pos->attr.sample_id_all) |
966 | die("non matching sample_id_all"); | 903 | die("non matching sample_id_all"); |
967 | } | 904 | } |
968 | 905 | ||
@@ -1000,16 +937,13 @@ int perf_event__synthesize_attr(struct perf_event_attr *attr, u16 ids, u64 *id, | |||
1000 | return err; | 937 | return err; |
1001 | } | 938 | } |
1002 | 939 | ||
1003 | int perf_event__synthesize_attrs(struct perf_header *self, | 940 | int perf_session__synthesize_attrs(struct perf_session *session, |
1004 | perf_event__handler_t process, | 941 | perf_event__handler_t process) |
1005 | struct perf_session *session) | ||
1006 | { | 942 | { |
1007 | struct perf_header_attr *attr; | 943 | struct perf_evsel *attr; |
1008 | int i, err = 0; | 944 | int err = 0; |
1009 | |||
1010 | for (i = 0; i < self->attrs; i++) { | ||
1011 | attr = self->attr[i]; | ||
1012 | 945 | ||
946 | list_for_each_entry(attr, &session->evlist->entries, node) { | ||
1013 | err = perf_event__synthesize_attr(&attr->attr, attr->ids, | 947 | err = perf_event__synthesize_attr(&attr->attr, attr->ids, |
1014 | attr->id, process, session); | 948 | attr->id, process, session); |
1015 | if (err) { | 949 | if (err) { |
@@ -1024,27 +958,36 @@ int perf_event__synthesize_attrs(struct perf_header *self, | |||
1024 | int perf_event__process_attr(union perf_event *event, | 958 | int perf_event__process_attr(union perf_event *event, |
1025 | struct perf_session *session) | 959 | struct perf_session *session) |
1026 | { | 960 | { |
1027 | struct perf_header_attr *attr; | ||
1028 | unsigned int i, ids, n_ids; | 961 | unsigned int i, ids, n_ids; |
962 | struct perf_evsel *evsel; | ||
1029 | 963 | ||
1030 | attr = perf_header_attr__new(&event->attr.attr); | 964 | if (session->evlist == NULL) { |
1031 | if (attr == NULL) | 965 | session->evlist = perf_evlist__new(NULL, NULL); |
966 | if (session->evlist == NULL) | ||
967 | return -ENOMEM; | ||
968 | } | ||
969 | |||
970 | evsel = perf_evsel__new(&event->attr.attr, | ||
971 | session->evlist->nr_entries); | ||
972 | if (evsel == NULL) | ||
1032 | return -ENOMEM; | 973 | return -ENOMEM; |
1033 | 974 | ||
975 | perf_evlist__add(session->evlist, evsel); | ||
976 | |||
1034 | ids = event->header.size; | 977 | ids = event->header.size; |
1035 | ids -= (void *)&event->attr.id - (void *)event; | 978 | ids -= (void *)&event->attr.id - (void *)event; |
1036 | n_ids = ids / sizeof(u64); | 979 | n_ids = ids / sizeof(u64); |
980 | /* | ||
981 | * We don't have the cpu and thread maps on the header, so | ||
982 | * for allocating the perf_sample_id table we fake 1 cpu and | ||
983 | * hattr->ids threads. | ||
984 | */ | ||
985 | if (perf_evsel__alloc_id(evsel, 1, n_ids)) | ||
986 | return -ENOMEM; | ||
1037 | 987 | ||
1038 | for (i = 0; i < n_ids; i++) { | 988 | for (i = 0; i < n_ids; i++) { |
1039 | if (perf_header_attr__add_id(attr, event->attr.id[i]) < 0) { | 989 | perf_evlist__id_add(session->evlist, evsel, 0, i, |
1040 | perf_header_attr__delete(attr); | 990 | event->attr.id[i]); |
1041 | return -ENOMEM; | ||
1042 | } | ||
1043 | } | ||
1044 | |||
1045 | if (perf_header__add_attr(&session->header, attr) < 0) { | ||
1046 | perf_header_attr__delete(attr); | ||
1047 | return -ENOMEM; | ||
1048 | } | 991 | } |
1049 | 992 | ||
1050 | perf_session__update_sample_type(session); | 993 | perf_session__update_sample_type(session); |
diff --git a/tools/perf/util/header.h b/tools/perf/util/header.h index 2fab13348aab..4cc267559bb6 100644 --- a/tools/perf/util/header.h +++ b/tools/perf/util/header.h | |||
@@ -9,13 +9,6 @@ | |||
9 | 9 | ||
10 | #include <linux/bitmap.h> | 10 | #include <linux/bitmap.h> |
11 | 11 | ||
12 | struct perf_header_attr { | ||
13 | struct perf_event_attr attr; | ||
14 | int ids, size; | ||
15 | u64 *id; | ||
16 | off_t id_offset; | ||
17 | }; | ||
18 | |||
19 | enum { | 12 | enum { |
20 | HEADER_TRACE_INFO = 1, | 13 | HEADER_TRACE_INFO = 1, |
21 | HEADER_BUILD_ID, | 14 | HEADER_BUILD_ID, |
@@ -51,9 +44,7 @@ int perf_file_header__read(struct perf_file_header *self, | |||
51 | 44 | ||
52 | struct perf_header { | 45 | struct perf_header { |
53 | int frozen; | 46 | int frozen; |
54 | int attrs, size; | ||
55 | bool needs_swap; | 47 | bool needs_swap; |
56 | struct perf_header_attr **attr; | ||
57 | s64 attr_offset; | 48 | s64 attr_offset; |
58 | u64 data_offset; | 49 | u64 data_offset; |
59 | u64 data_size; | 50 | u64 data_size; |
@@ -62,29 +53,19 @@ struct perf_header { | |||
62 | DECLARE_BITMAP(adds_features, HEADER_FEAT_BITS); | 53 | DECLARE_BITMAP(adds_features, HEADER_FEAT_BITS); |
63 | }; | 54 | }; |
64 | 55 | ||
65 | int perf_header__init(struct perf_header *self); | ||
66 | void perf_header__exit(struct perf_header *self); | ||
67 | |||
68 | struct perf_evlist; | 56 | struct perf_evlist; |
69 | 57 | ||
70 | int perf_header__read(struct perf_session *session, int fd); | 58 | int perf_session__read_header(struct perf_session *session, int fd); |
71 | int perf_header__write(struct perf_header *self, struct perf_evlist *evlist, | 59 | int perf_session__write_header(struct perf_session *session, |
72 | int fd, bool at_exit); | 60 | struct perf_evlist *evlist, |
61 | int fd, bool at_exit); | ||
73 | int perf_header__write_pipe(int fd); | 62 | int perf_header__write_pipe(int fd); |
74 | 63 | ||
75 | int perf_header__add_attr(struct perf_header *self, | ||
76 | struct perf_header_attr *attr); | ||
77 | |||
78 | int perf_header__push_event(u64 id, const char *name); | 64 | int perf_header__push_event(u64 id, const char *name); |
79 | char *perf_header__find_event(u64 id); | 65 | char *perf_header__find_event(u64 id); |
80 | 66 | ||
81 | struct perf_header_attr *perf_header_attr__new(struct perf_event_attr *attr); | 67 | u64 perf_evlist__sample_type(struct perf_evlist *evlist); |
82 | void perf_header_attr__delete(struct perf_header_attr *self); | 68 | bool perf_evlist__sample_id_all(const struct perf_evlist *evlist); |
83 | |||
84 | int perf_header_attr__add_id(struct perf_header_attr *self, u64 id); | ||
85 | |||
86 | u64 perf_header__sample_type(struct perf_header *header); | ||
87 | bool perf_header__sample_id_all(const struct perf_header *header); | ||
88 | void perf_header__set_feat(struct perf_header *self, int feat); | 69 | void perf_header__set_feat(struct perf_header *self, int feat); |
89 | void perf_header__clear_feat(struct perf_header *self, int feat); | 70 | void perf_header__clear_feat(struct perf_header *self, int feat); |
90 | bool perf_header__has_feat(const struct perf_header *self, int feat); | 71 | bool perf_header__has_feat(const struct perf_header *self, int feat); |
@@ -101,9 +82,8 @@ int build_id_cache__remove_s(const char *sbuild_id, const char *debugdir); | |||
101 | int perf_event__synthesize_attr(struct perf_event_attr *attr, u16 ids, u64 *id, | 82 | int perf_event__synthesize_attr(struct perf_event_attr *attr, u16 ids, u64 *id, |
102 | perf_event__handler_t process, | 83 | perf_event__handler_t process, |
103 | struct perf_session *session); | 84 | struct perf_session *session); |
104 | int perf_event__synthesize_attrs(struct perf_header *self, | 85 | int perf_session__synthesize_attrs(struct perf_session *session, |
105 | perf_event__handler_t process, | 86 | perf_event__handler_t process); |
106 | struct perf_session *session); | ||
107 | int perf_event__process_attr(union perf_event *event, struct perf_session *session); | 87 | int perf_event__process_attr(union perf_event *event, struct perf_session *session); |
108 | 88 | ||
109 | int perf_event__synthesize_event_type(u64 event_id, char *name, | 89 | int perf_event__synthesize_event_type(u64 event_id, char *name, |
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index 0d414199889d..f26639fa0fb3 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c | |||
@@ -13,46 +13,6 @@ | |||
13 | #include "sort.h" | 13 | #include "sort.h" |
14 | #include "util.h" | 14 | #include "util.h" |
15 | 15 | ||
16 | static int perf_session__read_evlist(struct perf_session *session) | ||
17 | { | ||
18 | int i, j; | ||
19 | |||
20 | session->evlist = perf_evlist__new(NULL, NULL); | ||
21 | if (session->evlist == NULL) | ||
22 | return -ENOMEM; | ||
23 | |||
24 | for (i = 0; i < session->header.attrs; ++i) { | ||
25 | struct perf_header_attr *hattr = session->header.attr[i]; | ||
26 | struct perf_evsel *evsel = perf_evsel__new(&hattr->attr, i); | ||
27 | |||
28 | if (evsel == NULL) | ||
29 | goto out_delete_evlist; | ||
30 | /* | ||
31 | * Do it before so that if perf_evsel__alloc_id fails, this | ||
32 | * entry gets purged too at perf_evlist__delete(). | ||
33 | */ | ||
34 | perf_evlist__add(session->evlist, evsel); | ||
35 | /* | ||
36 | * We don't have the cpu and thread maps on the header, so | ||
37 | * for allocating the perf_sample_id table we fake 1 cpu and | ||
38 | * hattr->ids threads. | ||
39 | */ | ||
40 | if (perf_evsel__alloc_id(evsel, 1, hattr->ids)) | ||
41 | goto out_delete_evlist; | ||
42 | |||
43 | for (j = 0; j < hattr->ids; ++j) | ||
44 | perf_evlist__id_hash(session->evlist, evsel, 0, j, | ||
45 | hattr->id[j]); | ||
46 | } | ||
47 | |||
48 | return 0; | ||
49 | |||
50 | out_delete_evlist: | ||
51 | perf_evlist__delete(session->evlist); | ||
52 | session->evlist = NULL; | ||
53 | return -ENOMEM; | ||
54 | } | ||
55 | |||
56 | static int perf_session__open(struct perf_session *self, bool force) | 16 | static int perf_session__open(struct perf_session *self, bool force) |
57 | { | 17 | { |
58 | struct stat input_stat; | 18 | struct stat input_stat; |
@@ -61,7 +21,7 @@ static int perf_session__open(struct perf_session *self, bool force) | |||
61 | self->fd_pipe = true; | 21 | self->fd_pipe = true; |
62 | self->fd = STDIN_FILENO; | 22 | self->fd = STDIN_FILENO; |
63 | 23 | ||
64 | if (perf_header__read(self, self->fd) < 0) | 24 | if (perf_session__read_header(self, self->fd) < 0) |
65 | pr_err("incompatible file format"); | 25 | pr_err("incompatible file format"); |
66 | 26 | ||
67 | return 0; | 27 | return 0; |
@@ -93,16 +53,11 @@ static int perf_session__open(struct perf_session *self, bool force) | |||
93 | goto out_close; | 53 | goto out_close; |
94 | } | 54 | } |
95 | 55 | ||
96 | if (perf_header__read(self, self->fd) < 0) { | 56 | if (perf_session__read_header(self, self->fd) < 0) { |
97 | pr_err("incompatible file format"); | 57 | pr_err("incompatible file format"); |
98 | goto out_close; | 58 | goto out_close; |
99 | } | 59 | } |
100 | 60 | ||
101 | if (perf_session__read_evlist(self) < 0) { | ||
102 | pr_err("Not enough memory to read the event selector list\n"); | ||
103 | goto out_close; | ||
104 | } | ||
105 | |||
106 | self->size = input_stat.st_size; | 61 | self->size = input_stat.st_size; |
107 | return 0; | 62 | return 0; |
108 | 63 | ||
@@ -139,21 +94,10 @@ out: | |||
139 | session->id_hdr_size = size; | 94 | session->id_hdr_size = size; |
140 | } | 95 | } |
141 | 96 | ||
142 | void perf_session__set_sample_id_all(struct perf_session *session, bool value) | ||
143 | { | ||
144 | session->sample_id_all = value; | ||
145 | perf_session__id_header_size(session); | ||
146 | } | ||
147 | |||
148 | void perf_session__set_sample_type(struct perf_session *session, u64 type) | ||
149 | { | ||
150 | session->sample_type = type; | ||
151 | } | ||
152 | |||
153 | void perf_session__update_sample_type(struct perf_session *self) | 97 | void perf_session__update_sample_type(struct perf_session *self) |
154 | { | 98 | { |
155 | self->sample_type = perf_header__sample_type(&self->header); | 99 | self->sample_type = perf_evlist__sample_type(self->evlist); |
156 | self->sample_id_all = perf_header__sample_id_all(&self->header); | 100 | self->sample_id_all = perf_evlist__sample_id_all(self->evlist); |
157 | perf_session__id_header_size(self); | 101 | perf_session__id_header_size(self); |
158 | } | 102 | } |
159 | 103 | ||
@@ -182,9 +126,6 @@ struct perf_session *perf_session__new(const char *filename, int mode, | |||
182 | if (self == NULL) | 126 | if (self == NULL) |
183 | goto out; | 127 | goto out; |
184 | 128 | ||
185 | if (perf_header__init(&self->header) < 0) | ||
186 | goto out_free; | ||
187 | |||
188 | memcpy(self->filename, filename, len); | 129 | memcpy(self->filename, filename, len); |
189 | self->threads = RB_ROOT; | 130 | self->threads = RB_ROOT; |
190 | INIT_LIST_HEAD(&self->dead_threads); | 131 | INIT_LIST_HEAD(&self->dead_threads); |
@@ -208,6 +149,7 @@ struct perf_session *perf_session__new(const char *filename, int mode, | |||
208 | if (mode == O_RDONLY) { | 149 | if (mode == O_RDONLY) { |
209 | if (perf_session__open(self, force) < 0) | 150 | if (perf_session__open(self, force) < 0) |
210 | goto out_delete; | 151 | goto out_delete; |
152 | perf_session__update_sample_type(self); | ||
211 | } else if (mode == O_WRONLY) { | 153 | } else if (mode == O_WRONLY) { |
212 | /* | 154 | /* |
213 | * In O_RDONLY mode this will be performed when reading the | 155 | * In O_RDONLY mode this will be performed when reading the |
@@ -217,8 +159,6 @@ struct perf_session *perf_session__new(const char *filename, int mode, | |||
217 | goto out_delete; | 159 | goto out_delete; |
218 | } | 160 | } |
219 | 161 | ||
220 | perf_session__update_sample_type(self); | ||
221 | |||
222 | if (ops && ops->ordering_requires_timestamps && | 162 | if (ops && ops->ordering_requires_timestamps && |
223 | ops->ordered_samples && !self->sample_id_all) { | 163 | ops->ordered_samples && !self->sample_id_all) { |
224 | dump_printf("WARNING: No sample_id_all support, falling back to unordered processing\n"); | 164 | dump_printf("WARNING: No sample_id_all support, falling back to unordered processing\n"); |
@@ -227,9 +167,6 @@ struct perf_session *perf_session__new(const char *filename, int mode, | |||
227 | 167 | ||
228 | out: | 168 | out: |
229 | return self; | 169 | return self; |
230 | out_free: | ||
231 | free(self); | ||
232 | return NULL; | ||
233 | out_delete: | 170 | out_delete: |
234 | perf_session__delete(self); | 171 | perf_session__delete(self); |
235 | return NULL; | 172 | return NULL; |
@@ -260,7 +197,6 @@ static void perf_session__delete_threads(struct perf_session *self) | |||
260 | 197 | ||
261 | void perf_session__delete(struct perf_session *self) | 198 | void perf_session__delete(struct perf_session *self) |
262 | { | 199 | { |
263 | perf_header__exit(&self->header); | ||
264 | perf_session__destroy_kernel_maps(self); | 200 | perf_session__destroy_kernel_maps(self); |
265 | perf_session__delete_dead_threads(self); | 201 | perf_session__delete_dead_threads(self); |
266 | perf_session__delete_threads(self); | 202 | perf_session__delete_threads(self); |
diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h index 05dd7bcb9453..b5b148b0aaca 100644 --- a/tools/perf/util/session.h +++ b/tools/perf/util/session.h | |||
@@ -112,8 +112,6 @@ void mem_bswap_64(void *src, int byte_size); | |||
112 | int perf_session__create_kernel_maps(struct perf_session *self); | 112 | int perf_session__create_kernel_maps(struct perf_session *self); |
113 | 113 | ||
114 | void perf_session__update_sample_type(struct perf_session *self); | 114 | void perf_session__update_sample_type(struct perf_session *self); |
115 | void perf_session__set_sample_id_all(struct perf_session *session, bool value); | ||
116 | void perf_session__set_sample_type(struct perf_session *session, u64 type); | ||
117 | void perf_session__remove_thread(struct perf_session *self, struct thread *th); | 115 | void perf_session__remove_thread(struct perf_session *self, struct thread *th); |
118 | 116 | ||
119 | static inline | 117 | static inline |