Skip to content

Commit d3a72fd

Browse files
namhyungacmel
authored andcommitted
perf report: Fix indentation of dynamic entries in hierarchy
When dynamic entries are used in the hierarchy mode with multiple events, the output might not be aligned properly. In the hierarchy mode, the each sort column is indented using total number of sort keys. So it keeps track of number of sort keys when adding them. However a dynamic sort key can be added more than once when multiple events have same field names. This results in unnecessarily long indentation in the output. For example perf kmem records following events: $ perf evlist --trace-fields -i perf.data.kmem kmem:kmalloc: trace_fields: call_site,ptr,bytes_req,bytes_alloc,gfp_flags kmem:kmalloc_node: trace_fields: call_site,ptr,bytes_req,bytes_alloc,gfp_flags,node kmem:kfree: trace_fields: call_site,ptr kmem:kmem_cache_alloc: trace_fields: call_site,ptr,bytes_req,bytes_alloc,gfp_flags kmem:kmem_cache_alloc_node: trace_fields: call_site,ptr,bytes_req,bytes_alloc,gfp_flags,node kmem:kmem_cache_free: trace_fields: call_site,ptr kmem:mm_page_alloc: trace_fields: page,order,gfp_flags,migratetype kmem:mm_page_free: trace_fields: page,order As you can see, many field names shared between kmem events. So adding 'ptr' dynamic sort key alone will set nr_sort_keys to 6. And this adds many unnecessary spaces between columns. Before: $ perf report -i perf.data.kmem --hierarchy -s ptr -g none --stdio ... # Overhead ptr # ....................... ................................... # 99.89% 0xffff8803ffb79720 0.06% 0xffff8803d228a000 0.03% 0xffff8803f7678f00 0.00% 0xffff880401dc5280 0.00% 0xffff880406172380 0.00% 0xffff8803ffac3a00 0.00% 0xffff8803ffac1600 After: # Overhead ptr # ........ .................... # 99.89% 0xffff8803ffb79720 0.06% 0xffff8803d228a000 0.03% 0xffff8803f7678f00 0.00% 0xffff880401dc5280 0.00% 0xffff880406172380 0.00% 0xffff8803ffac3a00 0.00% 0xffff8803ffac1600 Signed-off-by: Namhyung Kim <[email protected]> Tested-by: Arnaldo Carvalho de Melo <[email protected]> Acked-by: Jiri Olsa <[email protected]> Cc: Andi Kleen <[email protected]> Cc: David Ahern <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Stephane Eranian <[email protected]> Cc: Wang Nan <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 84b6ee8 commit d3a72fd

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed

tools/perf/ui/browsers/hists.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1547,7 +1547,7 @@ static int hists_browser__scnprintf_hierarchy_headers(struct hist_browser *brows
15471547
struct perf_hpp_fmt *fmt;
15481548
size_t ret = 0;
15491549
int column = 0;
1550-
int nr_sort_keys = hists->hpp_list->nr_sort_keys;
1550+
int nr_sort_keys = hists->nr_sort_keys;
15511551
bool first = true;
15521552

15531553
ret = scnprintf(buf, size, " ");
@@ -1632,7 +1632,7 @@ static unsigned int hist_browser__refresh(struct ui_browser *browser)
16321632
u16 header_offset = 0;
16331633
struct rb_node *nd;
16341634
struct hist_browser *hb = container_of(browser, struct hist_browser, b);
1635-
int nr_sort = hb->hists->hpp_list->nr_sort_keys;
1635+
int nr_sort = hb->hists->nr_sort_keys;
16361636

16371637
if (hb->show_headers) {
16381638
hist_browser__show_headers(hb);
@@ -1969,7 +1969,7 @@ static int hist_browser__fprintf(struct hist_browser *browser, FILE *fp)
19691969
struct rb_node *nd = hists__filter_entries(rb_first(browser->b.entries),
19701970
browser->min_pcnt);
19711971
int printed = 0;
1972-
int nr_sort = browser->hists->hpp_list->nr_sort_keys;
1972+
int nr_sort = browser->hists->nr_sort_keys;
19731973

19741974
while (nd) {
19751975
struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node);

tools/perf/ui/stdio/hist.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ static int hist_entry__fprintf(struct hist_entry *he, size_t size,
495495
size = hpp.size = bfsz;
496496

497497
if (symbol_conf.report_hierarchy) {
498-
int nr_sort = hists->hpp_list->nr_sort_keys;
498+
int nr_sort = hists->nr_sort_keys;
499499

500500
return hist_entry__hierarchy_fprintf(he, &hpp, nr_sort,
501501
hists, fp);
@@ -529,7 +529,7 @@ static int print_hierarchy_header(struct hists *hists, struct perf_hpp *hpp,
529529
unsigned header_width = 0;
530530
struct perf_hpp_fmt *fmt;
531531

532-
nr_sort = hists->hpp_list->nr_sort_keys;
532+
nr_sort = hists->nr_sort_keys;
533533

534534
/* preserve max indent depth for column headers */
535535
print_hierarchy_indent(sep, nr_sort, spaces, fp);
@@ -728,7 +728,7 @@ size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows,
728728
* display "no entry >= x.xx%" message.
729729
*/
730730
if (!h->leaf && !hist_entry__has_hierarchy_children(h, min_pcnt)) {
731-
int nr_sort = hists->hpp_list->nr_sort_keys;
731+
int nr_sort = hists->nr_sort_keys;
732732

733733
print_hierarchy_indent(sep, nr_sort + h->depth + 1, spaces, fp);
734734
fprintf(fp, "%*sno entry >= %.2f%%\n", indent, "", min_pcnt);

tools/perf/util/hist.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ struct hists {
7878
u16 col_len[HISTC_NR_COLS];
7979
int socket_filter;
8080
struct perf_hpp_list *hpp_list;
81+
int nr_sort_keys;
8182
};
8283

8384
struct hist_entry_iter;

tools/perf/util/sort.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2633,6 +2633,9 @@ static int __setup_output_field(void)
26332633
int setup_sorting(struct perf_evlist *evlist)
26342634
{
26352635
int err;
2636+
struct hists *hists;
2637+
struct perf_evsel *evsel;
2638+
struct perf_hpp_fmt *fmt;
26362639

26372640
err = __setup_sorting(evlist);
26382641
if (err < 0)
@@ -2644,6 +2647,22 @@ int setup_sorting(struct perf_evlist *evlist)
26442647
return err;
26452648
}
26462649

2650+
evlist__for_each(evlist, evsel) {
2651+
hists = evsel__hists(evsel);
2652+
hists->nr_sort_keys = perf_hpp_list.nr_sort_keys;
2653+
2654+
/*
2655+
* If dynamic entries were used, it might add multiple
2656+
* entries to each evsel for a single field name. Set
2657+
* actual number of sort keys for each hists.
2658+
*/
2659+
perf_hpp_list__for_each_sort_list(&perf_hpp_list, fmt) {
2660+
if (perf_hpp__is_dynamic_entry(fmt) &&
2661+
!perf_hpp__defined_dynamic_entry(fmt, hists))
2662+
hists->nr_sort_keys--;
2663+
}
2664+
}
2665+
26472666
reset_dimensions();
26482667

26492668
/*

0 commit comments

Comments
 (0)