diff options
Diffstat (limited to 'tools/perf')
-rw-r--r-- | tools/perf/builtin-report.c | 44 | ||||
-rw-r--r-- | tools/perf/util/header.c | 35 | ||||
-rw-r--r-- | tools/perf/util/header.h | 4 |
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; | |||
70 | static struct rb_root threads; | 70 | static struct rb_root threads; |
71 | static struct thread *last_match; | 71 | static struct thread *last_match; |
72 | 72 | ||
73 | static struct perf_header *header; | ||
74 | |||
73 | static | 75 | static |
74 | struct callchain_param callchain_param = { | 76 | struct 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 | ||
1322 | static struct perf_header *header; | ||
1323 | |||
1324 | static 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 | |||
1341 | static int | 1324 | static int |
1342 | process_read_event(event_t *event, unsigned long offset, unsigned long head) | 1325 | process_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 | ||
1408 | static 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 | |||
1425 | static int __cmd_report(void) | 1393 | static 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 | |||
247 | u64 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 | |||
264 | struct perf_counter_attr * | ||
265 | perf_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 * | |||
31 | perf_header_attr__new(struct perf_counter_attr *attr); | 31 | perf_header_attr__new(struct perf_counter_attr *attr); |
32 | void perf_header_attr__add_id(struct perf_header_attr *self, u64 id); | 32 | void perf_header_attr__add_id(struct perf_header_attr *self, u64 id); |
33 | 33 | ||
34 | u64 perf_header__sample_type(struct perf_header *header); | ||
35 | struct perf_counter_attr * | ||
36 | perf_header__find_attr(u64 id, struct perf_header *header); | ||
37 | |||
34 | 38 | ||
35 | struct perf_header *perf_header__new(void); | 39 | struct perf_header *perf_header__new(void); |
36 | 40 | ||