aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/session.c
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2011-03-10 09:15:54 -0500
committerArnaldo Carvalho de Melo <acme@redhat.com>2011-03-10 09:15:54 -0500
commita91e5431d54f5359fccb5ec2512f252eb217707e (patch)
tree8f8ba4940d9f4e910b339baee13a710baa920378 /tools/perf/util/session.c
parent6547250381eb315acff3d52b4872ad775359407c (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/session.c')
-rw-r--r--tools/perf/util/session.c74
1 files changed, 5 insertions, 69 deletions
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
16static 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
50out_delete_evlist:
51 perf_evlist__delete(session->evlist);
52 session->evlist = NULL;
53 return -ENOMEM;
54}
55
56static int perf_session__open(struct perf_session *self, bool force) 16static 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
142void 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
148void perf_session__set_sample_type(struct perf_session *session, u64 type)
149{
150 session->sample_type = type;
151}
152
153void perf_session__update_sample_type(struct perf_session *self) 97void 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
228out: 168out:
229 return self; 169 return self;
230out_free:
231 free(self);
232 return NULL;
233out_delete: 170out_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
261void perf_session__delete(struct perf_session *self) 198void 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);