diff options
author | John Kacur <jkacur@redhat.com> | 2009-09-28 09:32:55 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2009-09-30 07:57:56 -0400 |
commit | 3d1d07ecd2009f65cb2091563fa21f9600c36774 (patch) | |
tree | a1ef97a8264fc880ee8a9406a9be9070d0d12176 /tools/perf/builtin-report.c | |
parent | dd68ada2d417e57b848822a1407b5317a54136c5 (diff) |
perf tools: Put common histogram functions in their own file
Move histogram related functions into their own files (hist.c and
hist.h) and make use of them in builtin-annotate.c and
builtin-report.c.
Signed-off-by: John Kacur <jkacur@redhat.com>
Acked-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
LKML-Reference: <alpine.LFD.2.00.0909281531180.8316@localhost.localdomain>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'tools/perf/builtin-report.c')
-rw-r--r-- | tools/perf/builtin-report.c | 164 |
1 files changed, 1 insertions, 163 deletions
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index 7b43504900ff..c1a54fc8527a 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c | |||
@@ -28,6 +28,7 @@ | |||
28 | 28 | ||
29 | #include "util/thread.h" | 29 | #include "util/thread.h" |
30 | #include "util/sort.h" | 30 | #include "util/sort.h" |
31 | #include "util/hist.h" | ||
31 | 32 | ||
32 | static char const *input_name = "perf.data"; | 33 | static char const *input_name = "perf.data"; |
33 | 34 | ||
@@ -55,8 +56,6 @@ static int exclude_other = 1; | |||
55 | 56 | ||
56 | static char callchain_default_opt[] = "fractal,0.5"; | 57 | static char callchain_default_opt[] = "fractal,0.5"; |
57 | 58 | ||
58 | static int callchain; | ||
59 | |||
60 | static char __cwd[PATH_MAX]; | 59 | static char __cwd[PATH_MAX]; |
61 | static char *cwd = __cwd; | 60 | static char *cwd = __cwd; |
62 | static int cwdlen; | 61 | static int cwdlen; |
@@ -66,50 +65,8 @@ static struct thread *last_match; | |||
66 | 65 | ||
67 | static struct perf_header *header; | 66 | static struct perf_header *header; |
68 | 67 | ||
69 | static | ||
70 | struct callchain_param callchain_param = { | ||
71 | .mode = CHAIN_GRAPH_REL, | ||
72 | .min_percent = 0.5 | ||
73 | }; | ||
74 | |||
75 | static u64 sample_type; | 68 | static u64 sample_type; |
76 | 69 | ||
77 | static struct rb_root hist; | ||
78 | |||
79 | static int64_t | ||
80 | hist_entry__cmp(struct hist_entry *left, struct hist_entry *right) | ||
81 | { | ||
82 | struct sort_entry *se; | ||
83 | int64_t cmp = 0; | ||
84 | |||
85 | list_for_each_entry(se, &hist_entry__sort_list, list) { | ||
86 | cmp = se->cmp(left, right); | ||
87 | if (cmp) | ||
88 | break; | ||
89 | } | ||
90 | |||
91 | return cmp; | ||
92 | } | ||
93 | |||
94 | static int64_t | ||
95 | hist_entry__collapse(struct hist_entry *left, struct hist_entry *right) | ||
96 | { | ||
97 | struct sort_entry *se; | ||
98 | int64_t cmp = 0; | ||
99 | |||
100 | list_for_each_entry(se, &hist_entry__sort_list, list) { | ||
101 | int64_t (*f)(struct hist_entry *, struct hist_entry *); | ||
102 | |||
103 | f = se->collapse ?: se->cmp; | ||
104 | |||
105 | cmp = f(left, right); | ||
106 | if (cmp) | ||
107 | break; | ||
108 | } | ||
109 | |||
110 | return cmp; | ||
111 | } | ||
112 | |||
113 | static size_t ipchain__fprintf_graph_line(FILE *fp, int depth, int depth_mask) | 70 | static size_t ipchain__fprintf_graph_line(FILE *fp, int depth, int depth_mask) |
114 | { | 71 | { |
115 | int i; | 72 | int i; |
@@ -308,7 +265,6 @@ hist_entry_callchain__fprintf(FILE *fp, struct hist_entry *self, | |||
308 | return ret; | 265 | return ret; |
309 | } | 266 | } |
310 | 267 | ||
311 | |||
312 | static size_t | 268 | static size_t |
313 | hist_entry__fprintf(FILE *fp, struct hist_entry *self, u64 total_samples) | 269 | hist_entry__fprintf(FILE *fp, struct hist_entry *self, u64 total_samples) |
314 | { | 270 | { |
@@ -573,117 +529,6 @@ hist_entry__add(struct thread *thread, struct map *map, struct dso *dso, | |||
573 | return 0; | 529 | return 0; |
574 | } | 530 | } |
575 | 531 | ||
576 | static void hist_entry__free(struct hist_entry *he) | ||
577 | { | ||
578 | free(he); | ||
579 | } | ||
580 | |||
581 | /* | ||
582 | * collapse the histogram | ||
583 | */ | ||
584 | |||
585 | static struct rb_root collapse_hists; | ||
586 | |||
587 | static void collapse__insert_entry(struct hist_entry *he) | ||
588 | { | ||
589 | struct rb_node **p = &collapse_hists.rb_node; | ||
590 | struct rb_node *parent = NULL; | ||
591 | struct hist_entry *iter; | ||
592 | int64_t cmp; | ||
593 | |||
594 | while (*p != NULL) { | ||
595 | parent = *p; | ||
596 | iter = rb_entry(parent, struct hist_entry, rb_node); | ||
597 | |||
598 | cmp = hist_entry__collapse(iter, he); | ||
599 | |||
600 | if (!cmp) { | ||
601 | iter->count += he->count; | ||
602 | hist_entry__free(he); | ||
603 | return; | ||
604 | } | ||
605 | |||
606 | if (cmp < 0) | ||
607 | p = &(*p)->rb_left; | ||
608 | else | ||
609 | p = &(*p)->rb_right; | ||
610 | } | ||
611 | |||
612 | rb_link_node(&he->rb_node, parent, p); | ||
613 | rb_insert_color(&he->rb_node, &collapse_hists); | ||
614 | } | ||
615 | |||
616 | static void collapse__resort(void) | ||
617 | { | ||
618 | struct rb_node *next; | ||
619 | struct hist_entry *n; | ||
620 | |||
621 | if (!sort__need_collapse) | ||
622 | return; | ||
623 | |||
624 | next = rb_first(&hist); | ||
625 | while (next) { | ||
626 | n = rb_entry(next, struct hist_entry, rb_node); | ||
627 | next = rb_next(&n->rb_node); | ||
628 | |||
629 | rb_erase(&n->rb_node, &hist); | ||
630 | collapse__insert_entry(n); | ||
631 | } | ||
632 | } | ||
633 | |||
634 | /* | ||
635 | * reverse the map, sort on count. | ||
636 | */ | ||
637 | |||
638 | static struct rb_root output_hists; | ||
639 | |||
640 | static void output__insert_entry(struct hist_entry *he, u64 min_callchain_hits) | ||
641 | { | ||
642 | struct rb_node **p = &output_hists.rb_node; | ||
643 | struct rb_node *parent = NULL; | ||
644 | struct hist_entry *iter; | ||
645 | |||
646 | if (callchain) | ||
647 | callchain_param.sort(&he->sorted_chain, &he->callchain, | ||
648 | min_callchain_hits, &callchain_param); | ||
649 | |||
650 | while (*p != NULL) { | ||
651 | parent = *p; | ||
652 | iter = rb_entry(parent, struct hist_entry, rb_node); | ||
653 | |||
654 | if (he->count > iter->count) | ||
655 | p = &(*p)->rb_left; | ||
656 | else | ||
657 | p = &(*p)->rb_right; | ||
658 | } | ||
659 | |||
660 | rb_link_node(&he->rb_node, parent, p); | ||
661 | rb_insert_color(&he->rb_node, &output_hists); | ||
662 | } | ||
663 | |||
664 | static void output__resort(u64 total_samples) | ||
665 | { | ||
666 | struct rb_node *next; | ||
667 | struct hist_entry *n; | ||
668 | struct rb_root *tree = &hist; | ||
669 | u64 min_callchain_hits; | ||
670 | |||
671 | min_callchain_hits = total_samples * (callchain_param.min_percent / 100); | ||
672 | |||
673 | if (sort__need_collapse) | ||
674 | tree = &collapse_hists; | ||
675 | |||
676 | next = rb_first(tree); | ||
677 | |||
678 | while (next) { | ||
679 | n = rb_entry(next, struct hist_entry, rb_node); | ||
680 | next = rb_next(&n->rb_node); | ||
681 | |||
682 | rb_erase(&n->rb_node, tree); | ||
683 | output__insert_entry(n, min_callchain_hits); | ||
684 | } | ||
685 | } | ||
686 | |||
687 | static size_t output__fprintf(FILE *fp, u64 total_samples) | 532 | static size_t output__fprintf(FILE *fp, u64 total_samples) |
688 | { | 533 | { |
689 | struct hist_entry *pos; | 534 | struct hist_entry *pos; |
@@ -778,13 +623,6 @@ print_entries: | |||
778 | return ret; | 623 | return ret; |
779 | } | 624 | } |
780 | 625 | ||
781 | static unsigned long total = 0, | ||
782 | total_mmap = 0, | ||
783 | total_comm = 0, | ||
784 | total_fork = 0, | ||
785 | total_unknown = 0, | ||
786 | total_lost = 0; | ||
787 | |||
788 | static int validate_chain(struct ip_callchain *chain, event_t *event) | 626 | static int validate_chain(struct ip_callchain *chain, event_t *event) |
789 | { | 627 | { |
790 | unsigned int chain_size; | 628 | unsigned int chain_size; |