diff options
author | Adrian Hunter <adrian.hunter@intel.com> | 2013-08-27 04:23:12 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2013-08-29 15:44:26 -0400 |
commit | b1cf6f65aa7096984836addab7cec6b5b6d4393a (patch) | |
tree | 3277b767bb9744acf84bcbdd67798ab114cb817f /tools | |
parent | d03f2170546d2f0c236a42706d211e15ffb64184 (diff) |
perf tools: Add a function to calculate sample event size
Add perf_event__sample_event_size() which can be used when synthesizing
sample events to determine how big the resulting event will be, and
therefore how much memory to allocate.
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/1377591794-30553-11-git-send-email-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/perf/util/event.h | 2 | ||||
-rw-r--r-- | tools/perf/util/evsel.c | 92 |
2 files changed, 94 insertions, 0 deletions
diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h index 1c80e1304e48..93130d856bf0 100644 --- a/tools/perf/util/event.h +++ b/tools/perf/util/event.h | |||
@@ -229,6 +229,8 @@ int perf_event__preprocess_sample(const union perf_event *self, | |||
229 | 229 | ||
230 | const char *perf_event__name(unsigned int id); | 230 | const char *perf_event__name(unsigned int id); |
231 | 231 | ||
232 | size_t perf_event__sample_event_size(const struct perf_sample *sample, u64 type, | ||
233 | u64 sample_regs_user, u64 read_format); | ||
232 | int perf_event__synthesize_sample(union perf_event *event, u64 type, | 234 | int perf_event__synthesize_sample(union perf_event *event, u64 type, |
233 | u64 sample_regs_user, u64 read_format, | 235 | u64 sample_regs_user, u64 read_format, |
234 | const struct perf_sample *sample, | 236 | const struct perf_sample *sample, |
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 7d62373e0b6f..e8745fb635a7 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c | |||
@@ -1465,6 +1465,98 @@ int perf_evsel__parse_sample(struct perf_evsel *evsel, union perf_event *event, | |||
1465 | return 0; | 1465 | return 0; |
1466 | } | 1466 | } |
1467 | 1467 | ||
1468 | size_t perf_event__sample_event_size(const struct perf_sample *sample, u64 type, | ||
1469 | u64 sample_regs_user, u64 read_format) | ||
1470 | { | ||
1471 | size_t sz, result = sizeof(struct sample_event); | ||
1472 | |||
1473 | if (type & PERF_SAMPLE_IDENTIFIER) | ||
1474 | result += sizeof(u64); | ||
1475 | |||
1476 | if (type & PERF_SAMPLE_IP) | ||
1477 | result += sizeof(u64); | ||
1478 | |||
1479 | if (type & PERF_SAMPLE_TID) | ||
1480 | result += sizeof(u64); | ||
1481 | |||
1482 | if (type & PERF_SAMPLE_TIME) | ||
1483 | result += sizeof(u64); | ||
1484 | |||
1485 | if (type & PERF_SAMPLE_ADDR) | ||
1486 | result += sizeof(u64); | ||
1487 | |||
1488 | if (type & PERF_SAMPLE_ID) | ||
1489 | result += sizeof(u64); | ||
1490 | |||
1491 | if (type & PERF_SAMPLE_STREAM_ID) | ||
1492 | result += sizeof(u64); | ||
1493 | |||
1494 | if (type & PERF_SAMPLE_CPU) | ||
1495 | result += sizeof(u64); | ||
1496 | |||
1497 | if (type & PERF_SAMPLE_PERIOD) | ||
1498 | result += sizeof(u64); | ||
1499 | |||
1500 | if (type & PERF_SAMPLE_READ) { | ||
1501 | result += sizeof(u64); | ||
1502 | if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) | ||
1503 | result += sizeof(u64); | ||
1504 | if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) | ||
1505 | result += sizeof(u64); | ||
1506 | /* PERF_FORMAT_ID is forced for PERF_SAMPLE_READ */ | ||
1507 | if (read_format & PERF_FORMAT_GROUP) { | ||
1508 | sz = sample->read.group.nr * | ||
1509 | sizeof(struct sample_read_value); | ||
1510 | result += sz; | ||
1511 | } else { | ||
1512 | result += sizeof(u64); | ||
1513 | } | ||
1514 | } | ||
1515 | |||
1516 | if (type & PERF_SAMPLE_CALLCHAIN) { | ||
1517 | sz = (sample->callchain->nr + 1) * sizeof(u64); | ||
1518 | result += sz; | ||
1519 | } | ||
1520 | |||
1521 | if (type & PERF_SAMPLE_RAW) { | ||
1522 | result += sizeof(u32); | ||
1523 | result += sample->raw_size; | ||
1524 | } | ||
1525 | |||
1526 | if (type & PERF_SAMPLE_BRANCH_STACK) { | ||
1527 | sz = sample->branch_stack->nr * sizeof(struct branch_entry); | ||
1528 | sz += sizeof(u64); | ||
1529 | result += sz; | ||
1530 | } | ||
1531 | |||
1532 | if (type & PERF_SAMPLE_REGS_USER) { | ||
1533 | if (sample->user_regs.abi) { | ||
1534 | result += sizeof(u64); | ||
1535 | sz = hweight_long(sample_regs_user) * sizeof(u64); | ||
1536 | result += sz; | ||
1537 | } else { | ||
1538 | result += sizeof(u64); | ||
1539 | } | ||
1540 | } | ||
1541 | |||
1542 | if (type & PERF_SAMPLE_STACK_USER) { | ||
1543 | sz = sample->user_stack.size; | ||
1544 | result += sizeof(u64); | ||
1545 | if (sz) { | ||
1546 | result += sz; | ||
1547 | result += sizeof(u64); | ||
1548 | } | ||
1549 | } | ||
1550 | |||
1551 | if (type & PERF_SAMPLE_WEIGHT) | ||
1552 | result += sizeof(u64); | ||
1553 | |||
1554 | if (type & PERF_SAMPLE_DATA_SRC) | ||
1555 | result += sizeof(u64); | ||
1556 | |||
1557 | return result; | ||
1558 | } | ||
1559 | |||
1468 | int perf_event__synthesize_sample(union perf_event *event, u64 type, | 1560 | int perf_event__synthesize_sample(union perf_event *event, u64 type, |
1469 | u64 sample_regs_user, u64 read_format, | 1561 | u64 sample_regs_user, u64 read_format, |
1470 | const struct perf_sample *sample, | 1562 | const struct perf_sample *sample, |