aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/hist.c
diff options
context:
space:
mode:
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}