diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2011-11-28 04:56:39 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2011-11-28 07:39:12 -0500 |
commit | 743eb868657bdb1b26c7b24077ca21c67c82c777 (patch) | |
tree | 4803b557725213043ccd5d3f83d2eec796a49f69 /tools/perf/builtin-top.c | |
parent | d20deb64e0490ee9442b5181bc08a62d2cadcb90 (diff) |
perf tools: Resolve machine earlier and pass it to perf_event_ops
Reducing the exposure of perf_session further, so that we can use the
classes in cases where no perf.data file is created.
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-stua66dcscsezzrcdugvbmvd@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/builtin-top.c')
-rw-r--r-- | tools/perf/builtin-top.c | 99 |
1 files changed, 51 insertions, 48 deletions
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index e8e3320602bd..31d497368ccf 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c | |||
@@ -258,11 +258,9 @@ out_unlock: | |||
258 | 258 | ||
259 | static const char CONSOLE_CLEAR[] = "[H[2J"; | 259 | static const char CONSOLE_CLEAR[] = "[H[2J"; |
260 | 260 | ||
261 | static struct hist_entry * | 261 | static struct hist_entry *perf_evsel__add_hist_entry(struct perf_evsel *evsel, |
262 | perf_session__add_hist_entry(struct perf_session *session, | 262 | struct addr_location *al, |
263 | struct addr_location *al, | 263 | struct perf_sample *sample) |
264 | struct perf_sample *sample, | ||
265 | struct perf_evsel *evsel) | ||
266 | { | 264 | { |
267 | struct hist_entry *he; | 265 | struct hist_entry *he; |
268 | 266 | ||
@@ -270,7 +268,7 @@ static struct hist_entry * | |||
270 | if (he == NULL) | 268 | if (he == NULL) |
271 | return NULL; | 269 | return NULL; |
272 | 270 | ||
273 | session->hists.stats.total_period += sample->period; | 271 | evsel->hists.stats.total_period += sample->period; |
274 | hists__inc_nr_events(&evsel->hists, PERF_RECORD_SAMPLE); | 272 | hists__inc_nr_events(&evsel->hists, PERF_RECORD_SAMPLE); |
275 | return he; | 273 | return he; |
276 | } | 274 | } |
@@ -675,44 +673,12 @@ static int symbol_filter(struct map *map __used, struct symbol *sym) | |||
675 | static void perf_event__process_sample(const union perf_event *event, | 673 | static void perf_event__process_sample(const union perf_event *event, |
676 | struct perf_evsel *evsel, | 674 | struct perf_evsel *evsel, |
677 | struct perf_sample *sample, | 675 | struct perf_sample *sample, |
678 | struct perf_session *session) | 676 | struct machine *machine) |
679 | { | 677 | { |
680 | struct symbol *parent = NULL; | 678 | struct symbol *parent = NULL; |
681 | u64 ip = event->ip.ip; | 679 | u64 ip = event->ip.ip; |
682 | struct addr_location al; | 680 | struct addr_location al; |
683 | struct machine *machine; | ||
684 | int err; | 681 | int err; |
685 | u8 origin = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK; | ||
686 | |||
687 | ++top.samples; | ||
688 | |||
689 | switch (origin) { | ||
690 | case PERF_RECORD_MISC_USER: | ||
691 | ++top.us_samples; | ||
692 | if (top.hide_user_symbols) | ||
693 | return; | ||
694 | machine = perf_session__find_host_machine(session); | ||
695 | break; | ||
696 | case PERF_RECORD_MISC_KERNEL: | ||
697 | ++top.kernel_samples; | ||
698 | if (top.hide_kernel_symbols) | ||
699 | return; | ||
700 | machine = perf_session__find_host_machine(session); | ||
701 | break; | ||
702 | case PERF_RECORD_MISC_GUEST_KERNEL: | ||
703 | ++top.guest_kernel_samples; | ||
704 | machine = perf_session__find_machine(session, event->ip.pid); | ||
705 | break; | ||
706 | case PERF_RECORD_MISC_GUEST_USER: | ||
707 | ++top.guest_us_samples; | ||
708 | /* | ||
709 | * TODO: we don't process guest user from host side | ||
710 | * except simple counting. | ||
711 | */ | ||
712 | return; | ||
713 | default: | ||
714 | return; | ||
715 | } | ||
716 | 682 | ||
717 | if (!machine && perf_guest) { | 683 | if (!machine && perf_guest) { |
718 | pr_err("Can't find guest [%d]'s kernel information\n", | 684 | pr_err("Can't find guest [%d]'s kernel information\n", |
@@ -723,7 +689,7 @@ static void perf_event__process_sample(const union perf_event *event, | |||
723 | if (event->header.misc & PERF_RECORD_MISC_EXACT_IP) | 689 | if (event->header.misc & PERF_RECORD_MISC_EXACT_IP) |
724 | top.exact_samples++; | 690 | top.exact_samples++; |
725 | 691 | ||
726 | if (perf_event__preprocess_sample(event, session, &al, sample, | 692 | if (perf_event__preprocess_sample(event, machine, &al, sample, |
727 | symbol_filter) < 0 || | 693 | symbol_filter) < 0 || |
728 | al.filtered) | 694 | al.filtered) |
729 | return; | 695 | return; |
@@ -777,13 +743,13 @@ static void perf_event__process_sample(const union perf_event *event, | |||
777 | 743 | ||
778 | if ((sort__has_parent || symbol_conf.use_callchain) && | 744 | if ((sort__has_parent || symbol_conf.use_callchain) && |
779 | sample->callchain) { | 745 | sample->callchain) { |
780 | err = perf_session__resolve_callchain(session, evsel, al.thread, | 746 | err = machine__resolve_callchain(machine, evsel, al.thread, |
781 | sample->callchain, &parent); | 747 | sample->callchain, &parent); |
782 | if (err) | 748 | if (err) |
783 | return; | 749 | return; |
784 | } | 750 | } |
785 | 751 | ||
786 | he = perf_session__add_hist_entry(session, &al, sample, evsel); | 752 | he = perf_evsel__add_hist_entry(evsel, &al, sample); |
787 | if (he == NULL) { | 753 | if (he == NULL) { |
788 | pr_err("Problem incrementing symbol period, skipping event\n"); | 754 | pr_err("Problem incrementing symbol period, skipping event\n"); |
789 | return; | 755 | return; |
@@ -808,6 +774,8 @@ static void perf_session__mmap_read_idx(struct perf_session *self, int idx) | |||
808 | struct perf_sample sample; | 774 | struct perf_sample sample; |
809 | struct perf_evsel *evsel; | 775 | struct perf_evsel *evsel; |
810 | union perf_event *event; | 776 | union perf_event *event; |
777 | struct machine *machine; | ||
778 | u8 origin; | ||
811 | int ret; | 779 | int ret; |
812 | 780 | ||
813 | while ((event = perf_evlist__mmap_read(top.evlist, idx)) != NULL) { | 781 | while ((event = perf_evlist__mmap_read(top.evlist, idx)) != NULL) { |
@@ -820,11 +788,45 @@ static void perf_session__mmap_read_idx(struct perf_session *self, int idx) | |||
820 | evsel = perf_evlist__id2evsel(self->evlist, sample.id); | 788 | evsel = perf_evlist__id2evsel(self->evlist, sample.id); |
821 | assert(evsel != NULL); | 789 | assert(evsel != NULL); |
822 | 790 | ||
791 | origin = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK; | ||
792 | |||
823 | if (event->header.type == PERF_RECORD_SAMPLE) | 793 | if (event->header.type == PERF_RECORD_SAMPLE) |
824 | perf_event__process_sample(event, evsel, &sample, self); | 794 | ++top.samples; |
795 | |||
796 | switch (origin) { | ||
797 | case PERF_RECORD_MISC_USER: | ||
798 | ++top.us_samples; | ||
799 | if (top.hide_user_symbols) | ||
800 | continue; | ||
801 | machine = perf_session__find_host_machine(self); | ||
802 | break; | ||
803 | case PERF_RECORD_MISC_KERNEL: | ||
804 | ++top.kernel_samples; | ||
805 | if (top.hide_kernel_symbols) | ||
806 | continue; | ||
807 | machine = perf_session__find_host_machine(self); | ||
808 | break; | ||
809 | case PERF_RECORD_MISC_GUEST_KERNEL: | ||
810 | ++top.guest_kernel_samples; | ||
811 | machine = perf_session__find_machine(self, event->ip.pid); | ||
812 | break; | ||
813 | case PERF_RECORD_MISC_GUEST_USER: | ||
814 | ++top.guest_us_samples; | ||
815 | /* | ||
816 | * TODO: we don't process guest user from host side | ||
817 | * except simple counting. | ||
818 | */ | ||
819 | /* Fall thru */ | ||
820 | default: | ||
821 | continue; | ||
822 | } | ||
823 | |||
824 | |||
825 | if (event->header.type == PERF_RECORD_SAMPLE) | ||
826 | perf_event__process_sample(event, evsel, &sample, machine); | ||
825 | else if (event->header.type < PERF_RECORD_MAX) { | 827 | else if (event->header.type < PERF_RECORD_MAX) { |
826 | hists__inc_nr_events(&evsel->hists, event->header.type); | 828 | hists__inc_nr_events(&evsel->hists, event->header.type); |
827 | perf_event__process(&top.ops, event, &sample, self); | 829 | perf_event__process(&top.ops, event, &sample, machine); |
828 | } else | 830 | } else |
829 | ++self->hists.stats.nr_unknown_events; | 831 | ++self->hists.stats.nr_unknown_events; |
830 | } | 832 | } |
@@ -967,10 +969,11 @@ static int __cmd_top(void) | |||
967 | 969 | ||
968 | if (top.target_tid != -1) | 970 | if (top.target_tid != -1) |
969 | perf_event__synthesize_thread_map(&top.ops, top.evlist->threads, | 971 | perf_event__synthesize_thread_map(&top.ops, top.evlist->threads, |
970 | perf_event__process, top.session); | 972 | perf_event__process, |
973 | &top.session->host_machine); | ||
971 | else | 974 | else |
972 | perf_event__synthesize_threads(&top.ops, perf_event__process, top.session); | 975 | perf_event__synthesize_threads(&top.ops, perf_event__process, |
973 | 976 | &top.session->host_machine); | |
974 | start_counters(top.evlist); | 977 | start_counters(top.evlist); |
975 | top.session->evlist = top.evlist; | 978 | top.session->evlist = top.evlist; |
976 | perf_session__update_sample_type(top.session); | 979 | perf_session__update_sample_type(top.session); |