Skip to content

Commit fefb0b9

Browse files
committed
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>
1 parent 1c02c4d commit fefb0b9

5 files changed

Lines changed: 30 additions & 13 deletions

File tree

‎tools/perf/builtin-report.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,13 +296,13 @@ static int __cmd_report(void)
296296
next = rb_first(&session->hists_tree);
297297
while (next) {
298298
struct hists *hists;
299-
u64 nr_hists;
300299

301300
hists = rb_entry(next, struct hists, rb_node);
302301
hists__collapse_resort(hists);
303-
nr_hists = hists__output_resort(hists);
302+
hists__output_resort(hists);
304303
if (use_browser)
305-
perf_session__browse_hists(&hists->entries, nr_hists,
304+
perf_session__browse_hists(&hists->entries,
305+
hists->nr_entries,
306306
hists->stats.total, help,
307307
input_name);
308308
else {

‎tools/perf/util/hist.c‎

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ static struct hist_entry *hist_entry__new(struct hist_entry *template)
4747
return self;
4848
}
4949

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+
5057
struct hist_entry *__hists__add_entry(struct hists *self,
5158
struct addr_location *al,
5259
struct symbol *sym_parent, u64 count)
@@ -89,6 +96,7 @@ struct hist_entry *__hists__add_entry(struct hists *self,
8996
return NULL;
9097
rb_link_node(&he->rb_node, parent, p);
9198
rb_insert_color(&he->rb_node, &self->entries);
99+
hists__inc_nr_entries(self, he);
92100
out:
93101
hist_entry__add_cpumode_count(he, al->cpumode, count);
94102
return he;
@@ -137,7 +145,7 @@ void hist_entry__free(struct hist_entry *he)
137145
* collapse the histogram
138146
*/
139147

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)
141149
{
142150
struct rb_node **p = &root->rb_node;
143151
struct rb_node *parent = NULL;
@@ -153,7 +161,7 @@ static void collapse__insert_entry(struct rb_root *root, struct hist_entry *he)
153161
if (!cmp) {
154162
iter->count += he->count;
155163
hist_entry__free(he);
156-
return;
164+
return false;
157165
}
158166

159167
if (cmp < 0)
@@ -164,6 +172,7 @@ static void collapse__insert_entry(struct rb_root *root, struct hist_entry *he)
164172

165173
rb_link_node(&he->rb_node, parent, p);
166174
rb_insert_color(&he->rb_node, root);
175+
return true;
167176
}
168177

169178
void hists__collapse_resort(struct hists *self)
@@ -177,13 +186,16 @@ void hists__collapse_resort(struct hists *self)
177186

178187
tmp = RB_ROOT;
179188
next = rb_first(&self->entries);
189+
self->nr_entries = 0;
190+
self->max_sym_namelen = 0;
180191

181192
while (next) {
182193
n = rb_entry(next, struct hist_entry, rb_node);
183194
next = rb_next(&n->rb_node);
184195

185196
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);
187199
}
188200

189201
self->entries = tmp;
@@ -219,30 +231,31 @@ static void __hists__insert_output_entry(struct rb_root *entries,
219231
rb_insert_color(&he->rb_node, entries);
220232
}
221233

222-
u64 hists__output_resort(struct hists *self)
234+
void hists__output_resort(struct hists *self)
223235
{
224236
struct rb_root tmp;
225237
struct rb_node *next;
226238
struct hist_entry *n;
227239
u64 min_callchain_hits;
228-
u64 nr_hists = 0;
229240

230241
min_callchain_hits = self->stats.total * (callchain_param.min_percent / 100);
231242

232243
tmp = RB_ROOT;
233244
next = rb_first(&self->entries);
234245

246+
self->nr_entries = 0;
247+
self->max_sym_namelen = 0;
248+
235249
while (next) {
236250
n = rb_entry(next, struct hist_entry, rb_node);
237251
next = rb_next(&n->rb_node);
238252

239253
rb_erase(&n->rb_node, &self->entries);
240254
__hists__insert_output_entry(&tmp, n, min_callchain_hits);
241-
++nr_hists;
255+
hists__inc_nr_entries(self, n);
242256
}
243257

244258
self->entries = tmp;
245-
return nr_hists;
246259
}
247260

248261
static size_t callchain__fprintf_left_margin(FILE *fp, int left_margin)

‎tools/perf/util/hist.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ struct events_stats {
1919
struct hists {
2020
struct rb_node rb_node;
2121
struct rb_root entries;
22+
u64 nr_entries;
2223
struct events_stats stats;
2324
u64 config;
2425
u64 event_stream;
2526
u32 type;
27+
u32 max_sym_namelen;
2628
};
2729

2830
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,
3840
long displacement, bool color, u64 total);
3941
void hist_entry__free(struct hist_entry *);
4042

41-
u64 hists__output_resort(struct hists *self);
43+
void hists__output_resort(struct hists *self);
4244
void hists__collapse_resort(struct hists *self);
4345
size_t hists__fprintf(struct hists *self, struct hists *pair,
4446
bool show_displacement, FILE *fp);

‎tools/perf/util/symbol.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,9 @@ static struct symbol *symbol__new(u64 start, u64 len, const char *name)
130130
if (symbol_conf.priv_size)
131131
self = ((void *)self) + symbol_conf.priv_size;
132132

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;
135136

136137
pr_debug4("%s: %s %#Lx-%#Lx\n", __func__, name, start, self->end);
137138

‎tools/perf/util/symbol.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ struct symbol {
5454
struct rb_node rb_node;
5555
u64 start;
5656
u64 end;
57+
u16 namelen;
5758
char name[0];
5859
};
5960

0 commit comments

Comments
 (0)