diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2009-12-14 08:37:11 -0500 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2009-12-14 10:57:17 -0500 |
commit | b9bf089212d95746ce66482bcdbc7e77a0651088 (patch) | |
tree | f6a5d219d100498a2c16c1fb3a555f518c2c528d /tools/perf | |
parent | 4aa65636411ccb12f006a6ad593930655c445ff6 (diff) |
perf tools: No need for three rb_trees for sorting hist entries
All hist entries are in only one of them, so use just one and a
temporary rb_root while sorting/collapsing.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1260797831-11220-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'tools/perf')
-rw-r--r-- | tools/perf/builtin-annotate.c | 2 | ||||
-rw-r--r-- | tools/perf/builtin-report.c | 2 | ||||
-rw-r--r-- | tools/perf/util/hist.c | 36 | ||||
-rw-r--r-- | tools/perf/util/hist.h | 10 |
4 files changed, 22 insertions, 28 deletions
diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c index e44c54c79be4..f25e89e9c9b0 100644 --- a/tools/perf/builtin-annotate.c +++ b/tools/perf/builtin-annotate.c | |||
@@ -432,7 +432,7 @@ static void find_annotations(void) | |||
432 | { | 432 | { |
433 | struct rb_node *nd; | 433 | struct rb_node *nd; |
434 | 434 | ||
435 | for (nd = rb_first(&output_hists); nd; nd = rb_next(nd)) { | 435 | for (nd = rb_first(&hist); nd; nd = rb_next(nd)) { |
436 | struct hist_entry *he = rb_entry(nd, struct hist_entry, rb_node); | 436 | struct hist_entry *he = rb_entry(nd, struct hist_entry, rb_node); |
437 | struct sym_priv *priv; | 437 | struct sym_priv *priv; |
438 | 438 | ||
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index 3487224670a8..9cbdcbc4cd56 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c | |||
@@ -567,7 +567,7 @@ static size_t output__fprintf(FILE *fp, u64 total_samples) | |||
567 | fprintf(fp, "#\n"); | 567 | fprintf(fp, "#\n"); |
568 | 568 | ||
569 | print_entries: | 569 | print_entries: |
570 | for (nd = rb_first(&output_hists); nd; nd = rb_next(nd)) { | 570 | for (nd = rb_first(&hist); nd; nd = rb_next(nd)) { |
571 | pos = rb_entry(nd, struct hist_entry, rb_node); | 571 | pos = rb_entry(nd, struct hist_entry, rb_node); |
572 | ret += hist_entry__fprintf(fp, pos, total_samples); | 572 | ret += hist_entry__fprintf(fp, pos, total_samples); |
573 | } | 573 | } |
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c index 0ebf6ee16caa..b40e37ded4bf 100644 --- a/tools/perf/util/hist.c +++ b/tools/perf/util/hist.c | |||
@@ -1,8 +1,6 @@ | |||
1 | #include "hist.h" | 1 | #include "hist.h" |
2 | 2 | ||
3 | struct rb_root hist; | 3 | struct rb_root hist; |
4 | struct rb_root collapse_hists; | ||
5 | struct rb_root output_hists; | ||
6 | int callchain; | 4 | int callchain; |
7 | 5 | ||
8 | struct callchain_param callchain_param = { | 6 | struct callchain_param callchain_param = { |
@@ -102,9 +100,9 @@ void hist_entry__free(struct hist_entry *he) | |||
102 | * collapse the histogram | 100 | * collapse the histogram |
103 | */ | 101 | */ |
104 | 102 | ||
105 | void collapse__insert_entry(struct hist_entry *he) | 103 | static void collapse__insert_entry(struct rb_root *root, struct hist_entry *he) |
106 | { | 104 | { |
107 | struct rb_node **p = &collapse_hists.rb_node; | 105 | struct rb_node **p = &root->rb_node; |
108 | struct rb_node *parent = NULL; | 106 | struct rb_node *parent = NULL; |
109 | struct hist_entry *iter; | 107 | struct hist_entry *iter; |
110 | int64_t cmp; | 108 | int64_t cmp; |
@@ -128,34 +126,40 @@ void collapse__insert_entry(struct hist_entry *he) | |||
128 | } | 126 | } |
129 | 127 | ||
130 | rb_link_node(&he->rb_node, parent, p); | 128 | rb_link_node(&he->rb_node, parent, p); |
131 | rb_insert_color(&he->rb_node, &collapse_hists); | 129 | rb_insert_color(&he->rb_node, root); |
132 | } | 130 | } |
133 | 131 | ||
134 | void collapse__resort(void) | 132 | void collapse__resort(void) |
135 | { | 133 | { |
134 | struct rb_root tmp; | ||
136 | struct rb_node *next; | 135 | struct rb_node *next; |
137 | struct hist_entry *n; | 136 | struct hist_entry *n; |
138 | 137 | ||
139 | if (!sort__need_collapse) | 138 | if (!sort__need_collapse) |
140 | return; | 139 | return; |
141 | 140 | ||
141 | tmp = RB_ROOT; | ||
142 | next = rb_first(&hist); | 142 | next = rb_first(&hist); |
143 | |||
143 | while (next) { | 144 | while (next) { |
144 | n = rb_entry(next, struct hist_entry, rb_node); | 145 | n = rb_entry(next, struct hist_entry, rb_node); |
145 | next = rb_next(&n->rb_node); | 146 | next = rb_next(&n->rb_node); |
146 | 147 | ||
147 | rb_erase(&n->rb_node, &hist); | 148 | rb_erase(&n->rb_node, &hist); |
148 | collapse__insert_entry(n); | 149 | collapse__insert_entry(&tmp, n); |
149 | } | 150 | } |
151 | |||
152 | hist = tmp; | ||
150 | } | 153 | } |
151 | 154 | ||
152 | /* | 155 | /* |
153 | * reverse the map, sort on count. | 156 | * reverse the map, sort on count. |
154 | */ | 157 | */ |
155 | 158 | ||
156 | void output__insert_entry(struct hist_entry *he, u64 min_callchain_hits) | 159 | static void output__insert_entry(struct rb_root *root, struct hist_entry *he, |
160 | u64 min_callchain_hits) | ||
157 | { | 161 | { |
158 | struct rb_node **p = &output_hists.rb_node; | 162 | struct rb_node **p = &root->rb_node; |
159 | struct rb_node *parent = NULL; | 163 | struct rb_node *parent = NULL; |
160 | struct hist_entry *iter; | 164 | struct hist_entry *iter; |
161 | 165 | ||
@@ -174,29 +178,29 @@ void output__insert_entry(struct hist_entry *he, u64 min_callchain_hits) | |||
174 | } | 178 | } |
175 | 179 | ||
176 | rb_link_node(&he->rb_node, parent, p); | 180 | rb_link_node(&he->rb_node, parent, p); |
177 | rb_insert_color(&he->rb_node, &output_hists); | 181 | rb_insert_color(&he->rb_node, root); |
178 | } | 182 | } |
179 | 183 | ||
180 | void output__resort(u64 total_samples) | 184 | void output__resort(u64 total_samples) |
181 | { | 185 | { |
186 | struct rb_root tmp; | ||
182 | struct rb_node *next; | 187 | struct rb_node *next; |
183 | struct hist_entry *n; | 188 | struct hist_entry *n; |
184 | struct rb_root *tree = &hist; | ||
185 | u64 min_callchain_hits; | 189 | u64 min_callchain_hits; |
186 | 190 | ||
187 | min_callchain_hits = | 191 | min_callchain_hits = |
188 | total_samples * (callchain_param.min_percent / 100); | 192 | total_samples * (callchain_param.min_percent / 100); |
189 | 193 | ||
190 | if (sort__need_collapse) | 194 | tmp = RB_ROOT; |
191 | tree = &collapse_hists; | 195 | next = rb_first(&hist); |
192 | |||
193 | next = rb_first(tree); | ||
194 | 196 | ||
195 | while (next) { | 197 | while (next) { |
196 | n = rb_entry(next, struct hist_entry, rb_node); | 198 | n = rb_entry(next, struct hist_entry, rb_node); |
197 | next = rb_next(&n->rb_node); | 199 | next = rb_next(&n->rb_node); |
198 | 200 | ||
199 | rb_erase(&n->rb_node, tree); | 201 | rb_erase(&n->rb_node, &hist); |
200 | output__insert_entry(n, min_callchain_hits); | 202 | output__insert_entry(&tmp, n, min_callchain_hits); |
201 | } | 203 | } |
204 | |||
205 | hist = tmp; | ||
202 | } | 206 | } |
diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h index 3020db0c9292..a6cb1485e3b9 100644 --- a/tools/perf/util/hist.h +++ b/tools/perf/util/hist.h | |||
@@ -25,16 +25,8 @@ | |||
25 | #include "sort.h" | 25 | #include "sort.h" |
26 | 26 | ||
27 | extern struct rb_root hist; | 27 | extern struct rb_root hist; |
28 | extern struct rb_root collapse_hists; | ||
29 | extern struct rb_root output_hists; | ||
30 | extern int callchain; | 28 | extern int callchain; |
31 | extern struct callchain_param callchain_param; | 29 | extern struct callchain_param callchain_param; |
32 | extern unsigned long total; | ||
33 | extern unsigned long total_mmap; | ||
34 | extern unsigned long total_comm; | ||
35 | extern unsigned long total_fork; | ||
36 | extern unsigned long total_unknown; | ||
37 | extern unsigned long total_lost; | ||
38 | 30 | ||
39 | struct hist_entry *__hist_entry__add(struct addr_location *al, | 31 | struct hist_entry *__hist_entry__add(struct addr_location *al, |
40 | struct symbol *parent, | 32 | struct symbol *parent, |
@@ -42,9 +34,7 @@ struct hist_entry *__hist_entry__add(struct addr_location *al, | |||
42 | extern int64_t hist_entry__cmp(struct hist_entry *, struct hist_entry *); | 34 | extern int64_t hist_entry__cmp(struct hist_entry *, struct hist_entry *); |
43 | extern int64_t hist_entry__collapse(struct hist_entry *, struct hist_entry *); | 35 | extern int64_t hist_entry__collapse(struct hist_entry *, struct hist_entry *); |
44 | extern void hist_entry__free(struct hist_entry *); | 36 | extern void hist_entry__free(struct hist_entry *); |
45 | extern void collapse__insert_entry(struct hist_entry *); | ||
46 | extern void collapse__resort(void); | 37 | extern void collapse__resort(void); |
47 | extern void output__insert_entry(struct hist_entry *, u64); | ||
48 | extern void output__resort(u64); | 38 | extern void output__resort(u64); |
49 | 39 | ||
50 | #endif /* __PERF_HIST_H */ | 40 | #endif /* __PERF_HIST_H */ |