diff options
author | Thomas Gleixner <tglx@linutronix.de> | 2010-11-30 12:49:38 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2010-11-30 16:57:01 -0500 |
commit | 0331ee0cf4187dcdc2b184cf701d8b58bf9ff637 (patch) | |
tree | d32a66215eb6b18e787b08dc2a9e35862aad826d /tools/perf/util/session.c | |
parent | 28990f75e66b36faf6ce56747890009d4e250243 (diff) |
perf session: Cleanup __perf_session__process_events()
Replace the pseudo C++ self argument with session and give the mmap related
variables a sensible name. shift is a complete misnomer - it took me several
rounds of cursing to figure out that it's not a shift value.
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
LKML-Reference: <20101130163820.029687218@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/session.c')
-rw-r--r-- | tools/perf/util/session.c | 77 |
1 files changed, 37 insertions, 40 deletions
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index 525bcf6adc21..2fdbccf10770 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c | |||
@@ -567,13 +567,13 @@ static int perf_session__process_sample(event_t *event, struct perf_session *s, | |||
567 | static int perf_session__process_event(struct perf_session *self, | 567 | static int perf_session__process_event(struct perf_session *self, |
568 | event_t *event, | 568 | event_t *event, |
569 | struct perf_event_ops *ops, | 569 | struct perf_event_ops *ops, |
570 | u64 offset, u64 head) | 570 | u64 file_offset) |
571 | { | 571 | { |
572 | trace_event(event); | 572 | trace_event(event); |
573 | 573 | ||
574 | if (event->header.type < PERF_RECORD_HEADER_MAX) { | 574 | if (event->header.type < PERF_RECORD_HEADER_MAX) { |
575 | dump_printf("%#Lx [%#x]: PERF_RECORD_%s", | 575 | dump_printf("%#Lx [%#x]: PERF_RECORD_%s", |
576 | offset + head, event->header.size, | 576 | file_offset, event->header.size, |
577 | event__name[event->header.type]); | 577 | event__name[event->header.type]); |
578 | hists__inc_nr_events(&self->hists, event->header.type); | 578 | hists__inc_nr_events(&self->hists, event->header.type); |
579 | } | 579 | } |
@@ -606,7 +606,7 @@ static int perf_session__process_event(struct perf_session *self, | |||
606 | return ops->event_type(event, self); | 606 | return ops->event_type(event, self); |
607 | case PERF_RECORD_HEADER_TRACING_DATA: | 607 | case PERF_RECORD_HEADER_TRACING_DATA: |
608 | /* setup for reading amidst mmap */ | 608 | /* setup for reading amidst mmap */ |
609 | lseek(self->fd, offset + head, SEEK_SET); | 609 | lseek(self->fd, file_offset, SEEK_SET); |
610 | return ops->tracing_data(event, self); | 610 | return ops->tracing_data(event, self); |
611 | case PERF_RECORD_HEADER_BUILD_ID: | 611 | case PERF_RECORD_HEADER_BUILD_ID: |
612 | return ops->build_id(event, self); | 612 | return ops->build_id(event, self); |
@@ -705,8 +705,7 @@ more: | |||
705 | } | 705 | } |
706 | 706 | ||
707 | if (size == 0 || | 707 | if (size == 0 || |
708 | (skip = perf_session__process_event(self, &event, ops, | 708 | (skip = perf_session__process_event(self, &event, ops, head)) < 0) { |
709 | 0, head)) < 0) { | ||
710 | dump_printf("%#Lx [%#x]: skipping unknown header type: %d\n", | 709 | dump_printf("%#Lx [%#x]: skipping unknown header type: %d\n", |
711 | head, event.header.size, event.header.type); | 710 | head, event.header.size, event.header.type); |
712 | /* | 711 | /* |
@@ -735,19 +734,19 @@ out_err: | |||
735 | return err; | 734 | return err; |
736 | } | 735 | } |
737 | 736 | ||
738 | int __perf_session__process_events(struct perf_session *self, | 737 | int __perf_session__process_events(struct perf_session *session, |
739 | u64 data_offset, u64 data_size, | 738 | u64 data_offset, u64 data_size, |
740 | u64 file_size, struct perf_event_ops *ops) | 739 | u64 file_size, struct perf_event_ops *ops) |
741 | { | 740 | { |
741 | u64 head, page_offset, file_offset; | ||
742 | int err, mmap_prot, mmap_flags; | 742 | int err, mmap_prot, mmap_flags; |
743 | u64 head, shift; | 743 | struct ui_progress *progress; |
744 | u64 offset = 0; | ||
745 | size_t page_size; | 744 | size_t page_size; |
746 | event_t *event; | 745 | event_t *event; |
747 | uint32_t size; | 746 | uint32_t size; |
748 | char *buf; | 747 | char *buf; |
749 | struct ui_progress *progress = ui_progress__new("Processing events...", | 748 | |
750 | self->size); | 749 | progress = ui_progress__new("Processing events...", session->size); |
751 | if (progress == NULL) | 750 | if (progress == NULL) |
752 | return -1; | 751 | return -1; |
753 | 752 | ||
@@ -755,21 +754,20 @@ int __perf_session__process_events(struct perf_session *self, | |||
755 | 754 | ||
756 | page_size = sysconf(_SC_PAGESIZE); | 755 | page_size = sysconf(_SC_PAGESIZE); |
757 | 756 | ||
758 | head = data_offset; | 757 | page_offset = page_size * (data_offset / page_size); |
759 | shift = page_size * (head / page_size); | 758 | file_offset = page_offset; |
760 | offset += shift; | 759 | head = data_offset - page_offset; |
761 | head -= shift; | ||
762 | 760 | ||
763 | mmap_prot = PROT_READ; | 761 | mmap_prot = PROT_READ; |
764 | mmap_flags = MAP_SHARED; | 762 | mmap_flags = MAP_SHARED; |
765 | 763 | ||
766 | if (self->header.needs_swap) { | 764 | if (session->header.needs_swap) { |
767 | mmap_prot |= PROT_WRITE; | 765 | mmap_prot |= PROT_WRITE; |
768 | mmap_flags = MAP_PRIVATE; | 766 | mmap_flags = MAP_PRIVATE; |
769 | } | 767 | } |
770 | remap: | 768 | remap: |
771 | buf = mmap(NULL, page_size * self->mmap_window, mmap_prot, | 769 | buf = mmap(NULL, page_size * session->mmap_window, mmap_prot, |
772 | mmap_flags, self->fd, offset); | 770 | mmap_flags, session->fd, file_offset); |
773 | if (buf == MAP_FAILED) { | 771 | if (buf == MAP_FAILED) { |
774 | pr_err("failed to mmap file\n"); | 772 | pr_err("failed to mmap file\n"); |
775 | err = -errno; | 773 | err = -errno; |
@@ -778,36 +776,35 @@ remap: | |||
778 | 776 | ||
779 | more: | 777 | more: |
780 | event = (event_t *)(buf + head); | 778 | event = (event_t *)(buf + head); |
781 | ui_progress__update(progress, offset); | 779 | ui_progress__update(progress, file_offset); |
782 | 780 | ||
783 | if (self->header.needs_swap) | 781 | if (session->header.needs_swap) |
784 | perf_event_header__bswap(&event->header); | 782 | perf_event_header__bswap(&event->header); |
785 | size = event->header.size; | 783 | size = event->header.size; |
786 | if (size == 0) | 784 | if (size == 0) |
787 | size = 8; | 785 | size = 8; |
788 | 786 | ||
789 | if (head + event->header.size >= page_size * self->mmap_window) { | 787 | if (head + event->header.size >= page_size * session->mmap_window) { |
790 | int munmap_ret; | 788 | int munmap_ret; |
791 | 789 | ||
792 | shift = page_size * (head / page_size); | 790 | munmap_ret = munmap(buf, page_size * session->mmap_window); |
793 | |||
794 | munmap_ret = munmap(buf, page_size * self->mmap_window); | ||
795 | assert(munmap_ret == 0); | 791 | assert(munmap_ret == 0); |
796 | 792 | ||
797 | offset += shift; | 793 | page_offset = page_size * (head / page_size); |
798 | head -= shift; | 794 | file_offset += page_offset; |
795 | head -= page_offset; | ||
799 | goto remap; | 796 | goto remap; |
800 | } | 797 | } |
801 | 798 | ||
802 | size = event->header.size; | 799 | size = event->header.size; |
803 | 800 | ||
804 | dump_printf("\n%#Lx [%#x]: event: %d\n", | 801 | dump_printf("\n%#Lx [%#x]: event: %d\n", |
805 | offset + head, event->header.size, event->header.type); | 802 | file_offset + head, event->header.size, event->header.type); |
806 | 803 | ||
807 | if (size == 0 || | 804 | if (size == 0 || perf_session__process_event(session, event, ops, |
808 | perf_session__process_event(self, event, ops, offset, head) < 0) { | 805 | file_offset + head) < 0) { |
809 | dump_printf("%#Lx [%#x]: skipping unknown header type: %d\n", | 806 | dump_printf("%#Lx [%#x]: skipping unknown header type: %d\n", |
810 | offset + head, event->header.size, | 807 | file_offset + head, event->header.size, |
811 | event->header.type); | 808 | event->header.type); |
812 | /* | 809 | /* |
813 | * assume we lost track of the stream, check alignment, and | 810 | * assume we lost track of the stream, check alignment, and |
@@ -821,36 +818,36 @@ more: | |||
821 | 818 | ||
822 | head += size; | 819 | head += size; |
823 | 820 | ||
824 | if (offset + head >= data_offset + data_size) | 821 | if (file_offset + head >= data_offset + data_size) |
825 | goto done; | 822 | goto done; |
826 | 823 | ||
827 | if (offset + head < file_size) | 824 | if (file_offset + head < file_size) |
828 | goto more; | 825 | goto more; |
829 | done: | 826 | done: |
830 | err = 0; | 827 | err = 0; |
831 | /* do the final flush for ordered samples */ | 828 | /* do the final flush for ordered samples */ |
832 | self->ordered_samples.next_flush = ULLONG_MAX; | 829 | session->ordered_samples.next_flush = ULLONG_MAX; |
833 | flush_sample_queue(self, ops); | 830 | flush_sample_queue(session, ops); |
834 | out_err: | 831 | out_err: |
835 | ui_progress__delete(progress); | 832 | ui_progress__delete(progress); |
836 | 833 | ||
837 | if (ops->lost == event__process_lost && | 834 | if (ops->lost == event__process_lost && |
838 | self->hists.stats.total_lost != 0) { | 835 | session->hists.stats.total_lost != 0) { |
839 | ui__warning("Processed %Lu events and LOST %Lu!\n\n" | 836 | ui__warning("Processed %Lu events and LOST %Lu!\n\n" |
840 | "Check IO/CPU overload!\n\n", | 837 | "Check IO/CPU overload!\n\n", |
841 | self->hists.stats.total_period, | 838 | session->hists.stats.total_period, |
842 | self->hists.stats.total_lost); | 839 | session->hists.stats.total_lost); |
843 | } | 840 | } |
844 | 841 | ||
845 | if (self->hists.stats.nr_unknown_events != 0) { | 842 | if (session->hists.stats.nr_unknown_events != 0) { |
846 | ui__warning("Found %u unknown events!\n\n" | 843 | ui__warning("Found %u unknown events!\n\n" |
847 | "Is this an older tool processing a perf.data " | 844 | "Is this an older tool processing a perf.data " |
848 | "file generated by a more recent tool?\n\n" | 845 | "file generated by a more recent tool?\n\n" |
849 | "If that is not the case, consider " | 846 | "If that is not the case, consider " |
850 | "reporting to linux-kernel@vger.kernel.org.\n\n", | 847 | "reporting to linux-kernel@vger.kernel.org.\n\n", |
851 | self->hists.stats.nr_unknown_events); | 848 | session->hists.stats.nr_unknown_events); |
852 | } | 849 | } |
853 | 850 | ||
854 | return err; | 851 | return err; |
855 | } | 852 | } |
856 | 853 | ||