aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf
diff options
context:
space:
mode:
authorFrederic Weisbecker <fweisbec@gmail.com>2009-08-16 14:56:37 -0400
committerIngo Molnar <mingo@elte.hu>2009-08-16 17:06:44 -0400
commit0d3a5c885971de1e3124d85bfadf818abac9ba12 (patch)
treeeb1a76270a7e749609ff9627838f1d9eb6571bd4 /tools/perf
parent0f25bfc8d8b31a4ac8e4ff6cbc3911fb7092a4a7 (diff)
perf tools: Librarize sample type and attr finding from headers
Librarize the sample type and attr fetching from perf data file headers so that we can also use it from perf trace. Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Mike Galbraith <efault@gmx.de> LKML-Reference: <1250448997-30715-1-git-send-email-fweisbec@gmail.com> Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'tools/perf')
-rw-r--r--tools/perf/builtin-report.c44
-rw-r--r--tools/perf/util/header.c35
-rw-r--r--tools/perf/util/header.h4
3 files changed, 45 insertions, 38 deletions
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 05d52ff4c33d..c6326deb1636 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -70,6 +70,8 @@ static int cwdlen;
70static struct rb_root threads; 70static struct rb_root threads;
71static struct thread *last_match; 71static struct thread *last_match;
72 72
73static struct perf_header *header;
74
73static 75static
74struct callchain_param callchain_param = { 76struct callchain_param callchain_param = {
75 .mode = CHAIN_GRAPH_REL, 77 .mode = CHAIN_GRAPH_REL,
@@ -1319,29 +1321,12 @@ static void trace_event(event_t *event)
1319 dump_printf(".\n"); 1321 dump_printf(".\n");
1320} 1322}
1321 1323
1322static struct perf_header *header;
1323
1324static struct perf_counter_attr *perf_header__find_attr(u64 id)
1325{
1326 int i;
1327
1328 for (i = 0; i < header->attrs; i++) {
1329 struct perf_header_attr *attr = header->attr[i];
1330 int j;
1331
1332 for (j = 0; j < attr->ids; j++) {
1333 if (attr->id[j] == id)
1334 return &attr->attr;
1335 }
1336 }
1337
1338 return NULL;
1339}
1340
1341static int 1324static int
1342process_read_event(event_t *event, unsigned long offset, unsigned long head) 1325process_read_event(event_t *event, unsigned long offset, unsigned long head)
1343{ 1326{
1344 struct perf_counter_attr *attr = perf_header__find_attr(event->read.id); 1327 struct perf_counter_attr *attr;
1328
1329 attr = perf_header__find_attr(event->read.id, header);
1345 1330
1346 if (show_threads) { 1331 if (show_threads) {
1347 const char *name = attr ? __event_name(attr->type, attr->config) 1332 const char *name = attr ? __event_name(attr->type, attr->config)
@@ -1405,23 +1390,6 @@ process_event(event_t *event, unsigned long offset, unsigned long head)
1405 return 0; 1390 return 0;
1406} 1391}
1407 1392
1408static u64 perf_header__sample_type(void)
1409{
1410 u64 type = 0;
1411 int i;
1412
1413 for (i = 0; i < header->attrs; i++) {
1414 struct perf_header_attr *attr = header->attr[i];
1415
1416 if (!type)
1417 type = attr->attr.sample_type;
1418 else if (type != attr->attr.sample_type)
1419 die("non matching sample_type");
1420 }
1421
1422 return type;
1423}
1424
1425static int __cmd_report(void) 1393static int __cmd_report(void)
1426{ 1394{
1427 int ret, rc = EXIT_FAILURE; 1395 int ret, rc = EXIT_FAILURE;
@@ -1460,7 +1428,7 @@ static int __cmd_report(void)
1460 header = perf_header__read(input); 1428 header = perf_header__read(input);
1461 head = header->data_offset; 1429 head = header->data_offset;
1462 1430
1463 sample_type = perf_header__sample_type(); 1431 sample_type = perf_header__sample_type(header);
1464 1432
1465 if (!(sample_type & PERF_SAMPLE_CALLCHAIN)) { 1433 if (!(sample_type & PERF_SAMPLE_CALLCHAIN)) {
1466 if (sort__has_parent) { 1434 if (sort__has_parent) {
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index b92a457ca32e..a37a2221a0c3 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -243,3 +243,38 @@ struct perf_header *perf_header__read(int fd)
243 243
244 return self; 244 return self;
245} 245}
246
247u64 perf_header__sample_type(struct perf_header *header)
248{
249 u64 type = 0;
250 int i;
251
252 for (i = 0; i < header->attrs; i++) {
253 struct perf_header_attr *attr = header->attr[i];
254
255 if (!type)
256 type = attr->attr.sample_type;
257 else if (type != attr->attr.sample_type)
258 die("non matching sample_type");
259 }
260
261 return type;
262}
263
264struct perf_counter_attr *
265perf_header__find_attr(u64 id, struct perf_header *header)
266{
267 int i;
268
269 for (i = 0; i < header->attrs; i++) {
270 struct perf_header_attr *attr = header->attr[i];
271 int j;
272
273 for (j = 0; j < attr->ids; j++) {
274 if (attr->id[j] == id)
275 return &attr->attr;
276 }
277 }
278
279 return NULL;
280}
diff --git a/tools/perf/util/header.h b/tools/perf/util/header.h
index bf280449fcfd..5d0a72ecc919 100644
--- a/tools/perf/util/header.h
+++ b/tools/perf/util/header.h
@@ -31,6 +31,10 @@ struct perf_header_attr *
31perf_header_attr__new(struct perf_counter_attr *attr); 31perf_header_attr__new(struct perf_counter_attr *attr);
32void perf_header_attr__add_id(struct perf_header_attr *self, u64 id); 32void perf_header_attr__add_id(struct perf_header_attr *self, u64 id);
33 33
34u64 perf_header__sample_type(struct perf_header *header);
35struct perf_counter_attr *
36perf_header__find_attr(u64 id, struct perf_header *header);
37
34 38
35struct perf_header *perf_header__new(void); 39struct perf_header *perf_header__new(void);
36 40