aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/hist.c
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2009-12-14 10:10:39 -0500
committerIngo Molnar <mingo@elte.hu>2009-12-14 10:57:18 -0500
commit4e4f06e4c8f17ea96f7dd76251cab99511026401 (patch)
tree18b7f83b664939be0a9bde8e43daf9db8ca7fccc /tools/perf/util/hist.c
parentb9bf089212d95746ce66482bcdbc7e77a0651088 (diff)
perf session: Move the hist_entries rb tree to perf_session
As we'll need to sort multiple times for multiple perf sessions, so that we can then do a diff. 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: <1260803439-16783-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.c43
1 files changed, 23 insertions, 20 deletions
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c
index b40e37ded4bf..b9828fce7bf0 100644
--- a/tools/perf/util/hist.c
+++ b/tools/perf/util/hist.c
@@ -1,7 +1,6 @@
1#include "hist.h" 1#include "hist.h"
2 2#include "session.h"
3struct rb_root hist; 3#include "sort.h"
4int callchain;
5 4
6struct callchain_param callchain_param = { 5struct callchain_param callchain_param = {
7 .mode = CHAIN_GRAPH_REL, 6 .mode = CHAIN_GRAPH_REL,
@@ -12,11 +11,12 @@ struct callchain_param callchain_param = {
12 * histogram, sorted on item, collects counts 11 * histogram, sorted on item, collects counts
13 */ 12 */
14 13
15struct hist_entry *__hist_entry__add(struct addr_location *al, 14struct hist_entry *__perf_session__add_hist_entry(struct perf_session *self,
16 struct symbol *sym_parent, 15 struct addr_location *al,
17 u64 count, bool *hit) 16 struct symbol *sym_parent,
17 u64 count, bool *hit)
18{ 18{
19 struct rb_node **p = &hist.rb_node; 19 struct rb_node **p = &self->hists.rb_node;
20 struct rb_node *parent = NULL; 20 struct rb_node *parent = NULL;
21 struct hist_entry *he; 21 struct hist_entry *he;
22 struct hist_entry entry = { 22 struct hist_entry entry = {
@@ -52,7 +52,7 @@ struct hist_entry *__hist_entry__add(struct addr_location *al,
52 return NULL; 52 return NULL;
53 *he = entry; 53 *he = entry;
54 rb_link_node(&he->rb_node, parent, p); 54 rb_link_node(&he->rb_node, parent, p);
55 rb_insert_color(&he->rb_node, &hist); 55 rb_insert_color(&he->rb_node, &self->hists);
56 *hit = false; 56 *hit = false;
57 return he; 57 return he;
58} 58}
@@ -129,7 +129,7 @@ static void collapse__insert_entry(struct rb_root *root, struct hist_entry *he)
129 rb_insert_color(&he->rb_node, root); 129 rb_insert_color(&he->rb_node, root);
130} 130}
131 131
132void collapse__resort(void) 132void perf_session__collapse_resort(struct perf_session *self)
133{ 133{
134 struct rb_root tmp; 134 struct rb_root tmp;
135 struct rb_node *next; 135 struct rb_node *next;
@@ -139,31 +139,33 @@ void collapse__resort(void)
139 return; 139 return;
140 140
141 tmp = RB_ROOT; 141 tmp = RB_ROOT;
142 next = rb_first(&hist); 142 next = rb_first(&self->hists);
143 143
144 while (next) { 144 while (next) {
145 n = rb_entry(next, struct hist_entry, rb_node); 145 n = rb_entry(next, struct hist_entry, rb_node);
146 next = rb_next(&n->rb_node); 146 next = rb_next(&n->rb_node);
147 147
148 rb_erase(&n->rb_node, &hist); 148 rb_erase(&n->rb_node, &self->hists);
149 collapse__insert_entry(&tmp, n); 149 collapse__insert_entry(&tmp, n);
150 } 150 }
151 151
152 hist = tmp; 152 self->hists = tmp;
153} 153}
154 154
155/* 155/*
156 * reverse the map, sort on count. 156 * reverse the map, sort on count.
157 */ 157 */
158 158
159static void output__insert_entry(struct rb_root *root, struct hist_entry *he, 159static void perf_session__insert_output_hist_entry(struct perf_session *self,
160 u64 min_callchain_hits) 160 struct rb_root *root,
161 struct hist_entry *he,
162 u64 min_callchain_hits)
161{ 163{
162 struct rb_node **p = &root->rb_node; 164 struct rb_node **p = &root->rb_node;
163 struct rb_node *parent = NULL; 165 struct rb_node *parent = NULL;
164 struct hist_entry *iter; 166 struct hist_entry *iter;
165 167
166 if (callchain) 168 if (self->use_callchain)
167 callchain_param.sort(&he->sorted_chain, &he->callchain, 169 callchain_param.sort(&he->sorted_chain, &he->callchain,
168 min_callchain_hits, &callchain_param); 170 min_callchain_hits, &callchain_param);
169 171
@@ -181,7 +183,7 @@ static void output__insert_entry(struct rb_root *root, struct hist_entry *he,
181 rb_insert_color(&he->rb_node, root); 183 rb_insert_color(&he->rb_node, root);
182} 184}
183 185
184void output__resort(u64 total_samples) 186void perf_session__output_resort(struct perf_session *self, u64 total_samples)
185{ 187{
186 struct rb_root tmp; 188 struct rb_root tmp;
187 struct rb_node *next; 189 struct rb_node *next;
@@ -192,15 +194,16 @@ void output__resort(u64 total_samples)
192 total_samples * (callchain_param.min_percent / 100); 194 total_samples * (callchain_param.min_percent / 100);
193 195
194 tmp = RB_ROOT; 196 tmp = RB_ROOT;
195 next = rb_first(&hist); 197 next = rb_first(&self->hists);
196 198
197 while (next) { 199 while (next) {
198 n = rb_entry(next, struct hist_entry, rb_node); 200 n = rb_entry(next, struct hist_entry, rb_node);
199 next = rb_next(&n->rb_node); 201 next = rb_next(&n->rb_node);
200 202
201 rb_erase(&n->rb_node, &hist); 203 rb_erase(&n->rb_node, &self->hists);
202 output__insert_entry(&tmp, n, min_callchain_hits); 204 perf_session__insert_output_hist_entry(self, &tmp, n,
205 min_callchain_hits);
203 } 206 }
204 207
205 hist = tmp; 208 self->hists = tmp;
206} 209}