diff options
author | Andrew Vagin <avagin@openvz.org> | 2011-11-28 04:03:31 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2011-12-12 05:44:00 -0500 |
commit | 74eec26facadbe6dbc0621bc862892c915c4534f (patch) | |
tree | 65dfed706164778235d8891843d8e0245c9cd3b3 /tools/perf/util/evsel.c | |
parent | 317df650c588bb9091b1fa0b5d726fe485aad88e (diff) |
perf tools: Add ability to synthesize event according to a sample
It's the counterpart of perf_session__parse_sample.
v2: fixed mistakes found by David Ahern.
v3: s/data/sample/
s/perf_event__change_sample/perf_event__synthesize_sample
Reviewed-by: David Ahern <dsahern@gmail.com>
Cc: Arun Sharma <asharma@fb.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: devel@openvz.org
Link: http://lkml.kernel.org/r/1323266161-394927-3-git-send-email-avagin@openvz.org
Signed-off-by: Andrew Vagin <avagin@openvz.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/evsel.c')
-rw-r--r-- | tools/perf/util/evsel.c | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index ee68d6944e61..4a8c8b02e9cc 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c | |||
@@ -574,3 +574,82 @@ int perf_event__parse_sample(const union perf_event *event, u64 type, | |||
574 | 574 | ||
575 | return 0; | 575 | return 0; |
576 | } | 576 | } |
577 | |||
578 | int perf_event__synthesize_sample(union perf_event *event, u64 type, | ||
579 | const struct perf_sample *sample, | ||
580 | bool swapped) | ||
581 | { | ||
582 | u64 *array; | ||
583 | |||
584 | /* | ||
585 | * used for cross-endian analysis. See git commit 65014ab3 | ||
586 | * for why this goofiness is needed. | ||
587 | */ | ||
588 | union { | ||
589 | u64 val64; | ||
590 | u32 val32[2]; | ||
591 | } u; | ||
592 | |||
593 | array = event->sample.array; | ||
594 | |||
595 | if (type & PERF_SAMPLE_IP) { | ||
596 | event->ip.ip = sample->ip; | ||
597 | array++; | ||
598 | } | ||
599 | |||
600 | if (type & PERF_SAMPLE_TID) { | ||
601 | u.val32[0] = sample->pid; | ||
602 | u.val32[1] = sample->tid; | ||
603 | if (swapped) { | ||
604 | /* | ||
605 | * Inverse of what is done in perf_event__parse_sample | ||
606 | */ | ||
607 | u.val32[0] = bswap_32(u.val32[0]); | ||
608 | u.val32[1] = bswap_32(u.val32[1]); | ||
609 | u.val64 = bswap_64(u.val64); | ||
610 | } | ||
611 | |||
612 | *array = u.val64; | ||
613 | array++; | ||
614 | } | ||
615 | |||
616 | if (type & PERF_SAMPLE_TIME) { | ||
617 | *array = sample->time; | ||
618 | array++; | ||
619 | } | ||
620 | |||
621 | if (type & PERF_SAMPLE_ADDR) { | ||
622 | *array = sample->addr; | ||
623 | array++; | ||
624 | } | ||
625 | |||
626 | if (type & PERF_SAMPLE_ID) { | ||
627 | *array = sample->id; | ||
628 | array++; | ||
629 | } | ||
630 | |||
631 | if (type & PERF_SAMPLE_STREAM_ID) { | ||
632 | *array = sample->stream_id; | ||
633 | array++; | ||
634 | } | ||
635 | |||
636 | if (type & PERF_SAMPLE_CPU) { | ||
637 | u.val32[0] = sample->cpu; | ||
638 | if (swapped) { | ||
639 | /* | ||
640 | * Inverse of what is done in perf_event__parse_sample | ||
641 | */ | ||
642 | u.val32[0] = bswap_32(u.val32[0]); | ||
643 | u.val64 = bswap_64(u.val64); | ||
644 | } | ||
645 | *array = u.val64; | ||
646 | array++; | ||
647 | } | ||
648 | |||
649 | if (type & PERF_SAMPLE_PERIOD) { | ||
650 | *array = sample->period; | ||
651 | array++; | ||
652 | } | ||
653 | |||
654 | return 0; | ||
655 | } | ||