Skip to content

Commit cb1fab9

Browse files
namhyungacmel
authored andcommitted
perf report: Left align dynamic entries in hierarchy
The dynamic entries are right-aligned unlike other entries since it usually has numeric value. But for the hierarchy mode, left alignment is more appropriate IMHO. Also trim spaces on the left so that we can easily identify the hierarchy. Before: $ perf report --hierarchy -i perf.data.kmem -s gfp_flags,ptr,bytes_req --stdio -g none ... # # Overhead gfp_flags / ptr / bytes_req # .............. ................................................................................................. # 91.67% GFP_ATOMIC|GFP_NOWARN|GFP_NOMEMALLOC 37.50% 0xffff8803f7669400 37.50% 448 8.33% 0xffff8803f766be00 8.33% 96 4.17% 0xffff8800d156dc00 4.17% 704 After: # Overhead gfp_flags / ptr / bytes_req # .............. .................................... # 91.67% GFP_ATOMIC|GFP_NOWARN|GFP_NOMEMALLOC 37.50% 0xffff8803f7669400 37.50% 448 8.33% 0xffff8803f766be00 8.33% 96 4.17% 0xffff8800d156dc00 4.17% 704 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 d3a72fd commit cb1fab9

File tree

2 files changed

+33
-11
lines changed

2 files changed

+33
-11
lines changed

tools/perf/ui/browsers/hists.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,8 +1400,13 @@ static int hist_browser__show_hierarchy_entry(struct hist_browser *browser,
14001400
if (fmt->color) {
14011401
width -= fmt->color(fmt, &hpp, entry);
14021402
} else {
1403+
int i = 0;
1404+
14031405
width -= fmt->entry(fmt, &hpp, entry);
1404-
ui_browser__printf(&browser->b, "%s", s);
1406+
ui_browser__printf(&browser->b, "%s", ltrim(s));
1407+
1408+
while (isspace(s[i++]))
1409+
width++;
14051410
}
14061411
}
14071412

@@ -1576,6 +1581,8 @@ static int hists_browser__scnprintf_hierarchy_headers(struct hist_browser *brows
15761581
return ret;
15771582

15781583
hists__for_each_format(hists, fmt) {
1584+
char *start;
1585+
15791586
if (!perf_hpp__is_sort_entry(fmt) && !perf_hpp__is_dynamic_entry(fmt))
15801587
continue;
15811588
if (perf_hpp__should_skip(fmt, hists))
@@ -1593,7 +1600,12 @@ static int hists_browser__scnprintf_hierarchy_headers(struct hist_browser *brows
15931600
dummy_hpp.buf[ret] = '\0';
15941601
rtrim(dummy_hpp.buf);
15951602

1596-
ret = strlen(dummy_hpp.buf);
1603+
start = ltrim(dummy_hpp.buf);
1604+
ret = strlen(start);
1605+
1606+
if (start != dummy_hpp.buf)
1607+
memmove(dummy_hpp.buf, start, ret + 1);
1608+
15971609
if (advance_hpp_check(&dummy_hpp, ret))
15981610
break;
15991611
}

tools/perf/ui/stdio/hist.c

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,7 @@ static int hist_entry__hierarchy_fprintf(struct hist_entry *he,
418418
const char *sep = symbol_conf.field_sep;
419419
struct perf_hpp_fmt *fmt;
420420
char *buf = hpp->buf;
421+
size_t size = hpp->size;
421422
int ret, printed = 0;
422423
bool first = true;
423424

@@ -457,6 +458,11 @@ static int hist_entry__hierarchy_fprintf(struct hist_entry *he,
457458
(nr_sort_key - 1) * HIERARCHY_INDENT + 2, "");
458459
advance_hpp(hpp, ret);
459460

461+
printed += fprintf(fp, "%s", buf);
462+
463+
hpp->buf = buf;
464+
hpp->size = size;
465+
460466
/*
461467
* No need to call hist_entry__snprintf_alignment() since this
462468
* fmt is always the last column in the hierarchy mode.
@@ -467,7 +473,11 @@ static int hist_entry__hierarchy_fprintf(struct hist_entry *he,
467473
else
468474
fmt->entry(fmt, hpp, he);
469475

470-
printed += fprintf(fp, "%s\n", buf);
476+
/*
477+
* dynamic entries are right-aligned but we want left-aligned
478+
* in the hierarchy mode
479+
*/
480+
printed += fprintf(fp, "%s\n", ltrim(buf));
471481

472482
if (symbol_conf.use_callchain && he->leaf) {
473483
u64 total = hists__total_period(hists);
@@ -525,6 +535,7 @@ static int print_hierarchy_header(struct hists *hists, struct perf_hpp *hpp,
525535
{
526536
bool first = true;
527537
int nr_sort;
538+
int depth;
528539
unsigned width = 0;
529540
unsigned header_width = 0;
530541
struct perf_hpp_fmt *fmt;
@@ -558,19 +569,16 @@ static int print_hierarchy_header(struct hists *hists, struct perf_hpp *hpp,
558569
if (!first)
559570
header_width += fprintf(fp, " / ");
560571
else {
561-
header_width += fprintf(fp, "%s", sep ?: " ");
572+
fprintf(fp, "%s", sep ?: " ");
562573
first = false;
563574
}
564575

565576
fmt->header(fmt, hpp, hists_to_evsel(hists));
566577
rtrim(hpp->buf);
567578

568-
header_width += fprintf(fp, "%s", hpp->buf);
579+
header_width += fprintf(fp, "%s", ltrim(hpp->buf));
569580
}
570581

571-
/* preserve max indent depth for combined sort headers */
572-
print_hierarchy_indent(sep, nr_sort, spaces, fp);
573-
574582
fprintf(fp, "\n# ");
575583

576584
/* preserve max indent depth for initial dots */
@@ -590,22 +598,24 @@ static int print_hierarchy_header(struct hists *hists, struct perf_hpp *hpp,
590598
fprintf(fp, "%.*s", width, dots);
591599
}
592600

601+
depth = 0;
593602
hists__for_each_format(hists, fmt) {
594603
if (!perf_hpp__is_sort_entry(fmt) && !perf_hpp__is_dynamic_entry(fmt))
595604
continue;
596605
if (perf_hpp__should_skip(fmt, hists))
597606
continue;
598607

599608
width = fmt->width(fmt, hpp, hists_to_evsel(hists));
609+
width += depth * HIERARCHY_INDENT;
610+
600611
if (width > header_width)
601612
header_width = width;
613+
614+
depth++;
602615
}
603616

604617
fprintf(fp, "%s%-.*s", sep ?: " ", header_width, dots);
605618

606-
/* preserve max indent depth for dots under sort headers */
607-
print_hierarchy_indent(sep, nr_sort, dots, fp);
608-
609619
fprintf(fp, "\n#\n");
610620

611621
return 2;

0 commit comments

Comments
 (0)