diff options
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 | } | ||