Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

+30 -13
+3 -3
tools/perf/builtin-report.c
··· 296 296 next = rb_first(&session->hists_tree); 297 297 while (next) { 298 298 struct hists *hists; 299 - u64 nr_hists; 300 299 301 300 hists = rb_entry(next, struct hists, rb_node); 302 301 hists__collapse_resort(hists); 303 - nr_hists = hists__output_resort(hists); 302 + hists__output_resort(hists); 304 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 306 hists->stats.total, help, 307 307 input_name); 308 308 else {
+20 -7
tools/perf/util/hist.c
··· 47 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 57 struct hist_entry *__hists__add_entry(struct hists *self, 51 58 struct addr_location *al, 52 59 struct symbol *sym_parent, u64 count) ··· 96 89 return NULL; 97 90 rb_link_node(&he->rb_node, parent, p); 98 91 rb_insert_color(&he->rb_node, &self->entries); 92 + hists__inc_nr_entries(self, he); 99 93 out: 100 94 hist_entry__add_cpumode_count(he, al->cpumode, count); 101 95 return he; ··· 145 137 * collapse the histogram 146 138 */ 147 139 148 - static void collapse__insert_entry(struct rb_root *root, struct hist_entry *he) 140 + static bool collapse__insert_entry(struct rb_root *root, struct hist_entry *he) 149 141 { 150 142 struct rb_node **p = &root->rb_node; 151 143 struct rb_node *parent = NULL; ··· 161 153 if (!cmp) { 162 154 iter->count += he->count; 163 155 hist_entry__free(he); 164 - return; 156 + return false; 165 157 } 166 158 167 159 if (cmp < 0) ··· 172 164 173 165 rb_link_node(&he->rb_node, parent, p); 174 166 rb_insert_color(&he->rb_node, root); 167 + return true; 175 168 } 176 169 177 170 void hists__collapse_resort(struct hists *self) ··· 186 177 187 178 tmp = RB_ROOT; 188 179 next = rb_first(&self->entries); 180 + self->nr_entries = 0; 181 + self->max_sym_namelen = 0; 189 182 190 183 while (next) { 191 184 n = rb_entry(next, struct hist_entry, rb_node); 192 185 next = rb_next(&n->rb_node); 193 186 194 187 rb_erase(&n->rb_node, &self->entries); 195 - collapse__insert_entry(&tmp, n); 188 + if (collapse__insert_entry(&tmp, n)) 189 + hists__inc_nr_entries(self, n); 196 190 } 197 191 198 192 self->entries = tmp; ··· 231 219 rb_insert_color(&he->rb_node, entries); 232 220 } 233 221 234 - u64 hists__output_resort(struct hists *self) 222 + void hists__output_resort(struct hists *self) 235 223 { 236 224 struct rb_root tmp; 237 225 struct rb_node *next; 238 226 struct hist_entry *n; 239 227 u64 min_callchain_hits; 240 - u64 nr_hists = 0; 241 228 242 229 min_callchain_hits = self->stats.total * (callchain_param.min_percent / 100); 243 230 244 231 tmp = RB_ROOT; 245 232 next = rb_first(&self->entries); 233 + 234 + self->nr_entries = 0; 235 + self->max_sym_namelen = 0; 246 236 247 237 while (next) { 248 238 n = rb_entry(next, struct hist_entry, rb_node); ··· 252 238 253 239 rb_erase(&n->rb_node, &self->entries); 254 240 __hists__insert_output_entry(&tmp, n, min_callchain_hits); 255 - ++nr_hists; 241 + hists__inc_nr_entries(self, n); 256 242 } 257 243 258 244 self->entries = tmp; 259 - return nr_hists; 260 245 } 261 246 262 247 static size_t callchain__fprintf_left_margin(FILE *fp, int left_margin)
+3 -1
tools/perf/util/hist.h
··· 19 19 struct hists { 20 20 struct rb_node rb_node; 21 21 struct rb_root entries; 22 + u64 nr_entries; 22 23 struct events_stats stats; 23 24 u64 config; 24 25 u64 event_stream; 25 26 u32 type; 27 + u32 max_sym_namelen; 26 28 }; 27 29 28 30 struct hist_entry *__hists__add_entry(struct hists *self, ··· 40 38 long displacement, bool color, u64 total); 41 39 void hist_entry__free(struct hist_entry *); 42 40 43 - u64 hists__output_resort(struct hists *self); 41 + void hists__output_resort(struct hists *self); 44 42 void hists__collapse_resort(struct hists *self); 45 43 size_t hists__fprintf(struct hists *self, struct hists *pair, 46 44 bool show_displacement, FILE *fp);
+3 -2
tools/perf/util/symbol.c
··· 130 130 if (symbol_conf.priv_size) 131 131 self = ((void *)self) + symbol_conf.priv_size; 132 132 133 - self->start = start; 134 - self->end = len ? start + len - 1 : start; 133 + self->start = start; 134 + self->end = len ? start + len - 1 : start; 135 + self->namelen = namelen - 1; 135 136 136 137 pr_debug4("%s: %s %#Lx-%#Lx\n", __func__, name, start, self->end); 137 138
+1
tools/perf/util/symbol.h
··· 54 54 struct rb_node rb_node; 55 55 u64 start; 56 56 u64 end; 57 + u16 namelen; 57 58 char name[0]; 58 59 }; 59 60