aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/hist.c
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2009-12-14 08:37:11 -0500
committerIngo Molnar <mingo@elte.hu>2009-12-14 10:57:17 -0500
commitb9bf089212d95746ce66482bcdbc7e77a0651088 (patch)
treef6a5d219d100498a2c16c1fb3a555f518c2c528d /tools/perf/util/hist.c
parent4aa65636411ccb12f006a6ad593930655c445ff6 (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/util/hist.c')
-rw-r--r--tools/perf/util/hist.c36
1 files changed, 20 insertions, 16 deletions
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
3struct rb_root hist; 3struct rb_root hist;
4struct rb_root collapse_hists;
5struct rb_root output_hists;
6int callchain; 4int callchain;
7 5
8struct callchain_param callchain_param = { 6struct 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
105void collapse__insert_entry(struct hist_entry *he) 103static 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
134void collapse__resort(void) 132void 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
156void output__insert_entry(struct hist_entry *he, u64 min_callchain_hits) 159static 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
180void output__resort(u64 total_samples) 184void 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}