diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2010-05-10 12:57:51 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2010-05-10 18:49:08 -0400 |
commit | fefb0b94bbab858be0909a7eb5ef357e0f996a79 (patch) | |
tree | db46b10241ad338db05e9ee68bb0ee45954d7b8a /tools | |
parent | 1c02c4d2e92f2097f1bba63ec71560b0e05a7f36 (diff) |
perf hist: Calculate max_sym name len and nr_entries
Better done when we are adding entries, be it initially of when we're
re-sorting the histograms.
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Tom Zanussi <tzanussi@gmail.com>
LKML-Reference: <new-submission>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/perf/builtin-report.c | 6 | ||||
-rw-r--r-- | tools/perf/util/hist.c | 27 | ||||
-rw-r--r-- | tools/perf/util/hist.h | 4 | ||||
-rw-r--r-- | tools/perf/util/symbol.c | 5 | ||||
-rw-r--r-- | tools/perf/util/symbol.h | 1 |
5 files changed, 30 insertions, 13 deletions
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index 53077fd973f0..d7c75291e788 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c | |||
@@ -296,13 +296,13 @@ static int __cmd_report(void) | |||
296 | next = rb_first(&session->hists_tree); | 296 | next = rb_first(&session->hists_tree); |
297 | while (next) { | 297 | while (next) { |
298 | struct hists *hists; | 298 | struct hists *hists; |
299 | u64 nr_hists; | ||
300 | 299 | ||
301 | hists = rb_entry(next, struct hists, rb_node); | 300 | hists = rb_entry(next, struct hists, rb_node); |
302 | hists__collapse_resort(hists); | 301 | hists__collapse_resort(hists); |
303 | nr_hists = hists__output_resort(hists); | 302 | hists__output_resort(hists); |
304 | if (use_browser) | 303 | if (use_browser) |
305 | perf_session__browse_hists(&hists->entries, nr_hists, | 304 | perf_session__browse_hists(&hists->entries, |
305 | hists->nr_entries, | ||
306 | hists->stats.total, help, | 306 | hists->stats.total, help, |
307 | input_name); | 307 | input_name); |
308 | else { | 308 | else { |
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c index 410cf56c9662..e34fd248067d 100644 --- a/tools/perf/util/hist.c +++ b/tools/perf/util/hist.c | |||
@@ -47,6 +47,13 @@ static struct hist_entry *hist_entry__new(struct hist_entry *template) | |||
47 | return self; | 47 | return self; |
48 | } | 48 | } |
49 | 49 | ||
50 | static void hists__inc_nr_entries(struct hists *self, struct hist_entry *entry) | ||
51 | { | ||
52 | if (entry->ms.sym && self->max_sym_namelen < entry->ms.sym->namelen) | ||
53 | self->max_sym_namelen = entry->ms.sym->namelen; | ||
54 | ++self->nr_entries; | ||
55 | } | ||
56 | |||
50 | struct hist_entry *__hists__add_entry(struct hists *self, | 57 | struct hist_entry *__hists__add_entry(struct hists *self, |
51 | struct addr_location *al, | 58 | struct addr_location *al, |
52 | struct symbol *sym_parent, u64 count) | 59 | struct symbol *sym_parent, u64 count) |
@@ -89,6 +96,7 @@ struct hist_entry *__hists__add_entry(struct hists *self, | |||
89 | return NULL; | 96 | return NULL; |
90 | rb_link_node(&he->rb_node, parent, p); | 97 | rb_link_node(&he->rb_node, parent, p); |
91 | rb_insert_color(&he->rb_node, &self->entries); | 98 | rb_insert_color(&he->rb_node, &self->entries); |
99 | hists__inc_nr_entries(self, he); | ||
92 | out: | 100 | out: |
93 | hist_entry__add_cpumode_count(he, al->cpumode, count); | 101 | hist_entry__add_cpumode_count(he, al->cpumode, count); |
94 | return he; | 102 | return he; |
@@ -137,7 +145,7 @@ void hist_entry__free(struct hist_entry *he) | |||
137 | * collapse the histogram | 145 | * collapse the histogram |
138 | */ | 146 | */ |
139 | 147 | ||
140 | static void collapse__insert_entry(struct rb_root *root, struct hist_entry *he) | 148 | static bool collapse__insert_entry(struct rb_root *root, struct hist_entry *he) |
141 | { | 149 | { |
142 | struct rb_node **p = &root->rb_node; | 150 | struct rb_node **p = &root->rb_node; |
143 | struct rb_node *parent = NULL; | 151 | struct rb_node *parent = NULL; |
@@ -153,7 +161,7 @@ static void collapse__insert_entry(struct rb_root *root, struct hist_entry *he) | |||
153 | if (!cmp) { | 161 | if (!cmp) { |
154 | iter->count += he->count; | 162 | iter->count += he->count; |
155 | hist_entry__free(he); | 163 | hist_entry__free(he); |
156 | return; | 164 | return false; |
157 | } | 165 | } |
158 | 166 | ||
159 | if (cmp < 0) | 167 | if (cmp < 0) |
@@ -164,6 +172,7 @@ static void collapse__insert_entry(struct rb_root *root, struct hist_entry *he) | |||
164 | 172 | ||
165 | rb_link_node(&he->rb_node, parent, p); | 173 | rb_link_node(&he->rb_node, parent, p); |
166 | rb_insert_color(&he->rb_node, root); | 174 | rb_insert_color(&he->rb_node, root); |
175 | return true; | ||
167 | } | 176 | } |
168 | 177 | ||
169 | void hists__collapse_resort(struct hists *self) | 178 | void hists__collapse_resort(struct hists *self) |
@@ -177,13 +186,16 @@ void hists__collapse_resort(struct hists *self) | |||
177 | 186 | ||
178 | tmp = RB_ROOT; | 187 | tmp = RB_ROOT; |
179 | next = rb_first(&self->entries); | 188 | next = rb_first(&self->entries); |
189 | self->nr_entries = 0; | ||
190 | self->max_sym_namelen = 0; | ||
180 | 191 | ||
181 | while (next) { | 192 | while (next) { |
182 | n = rb_entry(next, struct hist_entry, rb_node); | 193 | n = rb_entry(next, struct hist_entry, rb_node); |
183 | next = rb_next(&n->rb_node); | 194 | next = rb_next(&n->rb_node); |
184 | 195 | ||
185 | rb_erase(&n->rb_node, &self->entries); | 196 | rb_erase(&n->rb_node, &self->entries); |
186 | collapse__insert_entry(&tmp, n); | 197 | if (collapse__insert_entry(&tmp, n)) |
198 | hists__inc_nr_entries(self, n); | ||
187 | } | 199 | } |
188 | 200 | ||
189 | self->entries = tmp; | 201 | self->entries = tmp; |
@@ -219,30 +231,31 @@ static void __hists__insert_output_entry(struct rb_root *entries, | |||
219 | rb_insert_color(&he->rb_node, entries); | 231 | rb_insert_color(&he->rb_node, entries); |
220 | } | 232 | } |
221 | 233 | ||
222 | u64 hists__output_resort(struct hists *self) | 234 | void hists__output_resort(struct hists *self) |
223 | { | 235 | { |
224 | struct rb_root tmp; | 236 | struct rb_root tmp; |
225 | struct rb_node *next; | 237 | struct rb_node *next; |
226 | struct hist_entry *n; | 238 | struct hist_entry *n; |
227 | u64 min_callchain_hits; | 239 | u64 min_callchain_hits; |
228 | u64 nr_hists = 0; | ||
229 | 240 | ||
230 | min_callchain_hits = self->stats.total * (callchain_param.min_percent / 100); | 241 | min_callchain_hits = self->stats.total * (callchain_param.min_percent / 100); |
231 | 242 | ||
232 | tmp = RB_ROOT; | 243 | tmp = RB_ROOT; |
233 | next = rb_first(&self->entries); | 244 | next = rb_first(&self->entries); |
234 | 245 | ||
246 | self->nr_entries = 0; | ||
247 | self->max_sym_namelen = 0; | ||
248 | |||
235 | while (next) { | 249 | while (next) { |
236 | n = rb_entry(next, struct hist_entry, rb_node); | 250 | n = rb_entry(next, struct hist_entry, rb_node); |
237 | next = rb_next(&n->rb_node); | 251 | next = rb_next(&n->rb_node); |
238 | 252 | ||
239 | rb_erase(&n->rb_node, &self->entries); | 253 | rb_erase(&n->rb_node, &self->entries); |
240 | __hists__insert_output_entry(&tmp, n, min_callchain_hits); | 254 | __hists__insert_output_entry(&tmp, n, min_callchain_hits); |
241 | ++nr_hists; | 255 | hists__inc_nr_entries(self, n); |
242 | } | 256 | } |
243 | 257 | ||
244 | self->entries = tmp; | 258 | self->entries = tmp; |
245 | return nr_hists; | ||
246 | } | 259 | } |
247 | 260 | ||
248 | static size_t callchain__fprintf_left_margin(FILE *fp, int left_margin) | 261 | static size_t callchain__fprintf_left_margin(FILE *fp, int left_margin) |
diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h index bdde81eca69f..1b18d04195dc 100644 --- a/tools/perf/util/hist.h +++ b/tools/perf/util/hist.h | |||
@@ -19,10 +19,12 @@ struct events_stats { | |||
19 | struct hists { | 19 | struct hists { |
20 | struct rb_node rb_node; | 20 | struct rb_node rb_node; |
21 | struct rb_root entries; | 21 | struct rb_root entries; |
22 | u64 nr_entries; | ||
22 | struct events_stats stats; | 23 | struct events_stats stats; |
23 | u64 config; | 24 | u64 config; |
24 | u64 event_stream; | 25 | u64 event_stream; |
25 | u32 type; | 26 | u32 type; |
27 | u32 max_sym_namelen; | ||
26 | }; | 28 | }; |
27 | 29 | ||
28 | struct hist_entry *__hists__add_entry(struct hists *self, | 30 | struct hist_entry *__hists__add_entry(struct hists *self, |
@@ -38,7 +40,7 @@ int hist_entry__snprintf(struct hist_entry *self, char *bf, size_t size, | |||
38 | long displacement, bool color, u64 total); | 40 | long displacement, bool color, u64 total); |
39 | void hist_entry__free(struct hist_entry *); | 41 | void hist_entry__free(struct hist_entry *); |
40 | 42 | ||
41 | u64 hists__output_resort(struct hists *self); | 43 | void hists__output_resort(struct hists *self); |
42 | void hists__collapse_resort(struct hists *self); | 44 | void hists__collapse_resort(struct hists *self); |
43 | size_t hists__fprintf(struct hists *self, struct hists *pair, | 45 | size_t hists__fprintf(struct hists *self, struct hists *pair, |
44 | bool show_displacement, FILE *fp); | 46 | bool show_displacement, FILE *fp); |
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c index 994efdb531e4..ecccc8df128e 100644 --- a/tools/perf/util/symbol.c +++ b/tools/perf/util/symbol.c | |||
@@ -130,8 +130,9 @@ static struct symbol *symbol__new(u64 start, u64 len, const char *name) | |||
130 | if (symbol_conf.priv_size) | 130 | if (symbol_conf.priv_size) |
131 | self = ((void *)self) + symbol_conf.priv_size; | 131 | self = ((void *)self) + symbol_conf.priv_size; |
132 | 132 | ||
133 | self->start = start; | 133 | self->start = start; |
134 | self->end = len ? start + len - 1 : start; | 134 | self->end = len ? start + len - 1 : start; |
135 | self->namelen = namelen - 1; | ||
135 | 136 | ||
136 | pr_debug4("%s: %s %#Lx-%#Lx\n", __func__, name, start, self->end); | 137 | pr_debug4("%s: %s %#Lx-%#Lx\n", __func__, name, start, self->end); |
137 | 138 | ||
diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h index edff866d76b2..6389d1acaf81 100644 --- a/tools/perf/util/symbol.h +++ b/tools/perf/util/symbol.h | |||
@@ -54,6 +54,7 @@ struct symbol { | |||
54 | struct rb_node rb_node; | 54 | struct rb_node rb_node; |
55 | u64 start; | 55 | u64 start; |
56 | u64 end; | 56 | u64 end; |
57 | u16 namelen; | ||
57 | char name[0]; | 58 | char name[0]; |
58 | }; | 59 | }; |
59 | 60 | ||