From 0ef8091f177f314d379c487cd8ec1024b7ae0f99 Mon Sep 17 00:00:00 2001 From: Namhyung Kim Date: Mon, 31 Mar 2025 00:37:22 -0700 Subject: [PATCH] perf hist: Allow custom output fields in hierarchy mode Now it can handle multiple output fields and sort keys in separate levels, so it should be ok to use it in the hierarchy mode. This allows fully customized output format. $ perf report -F latency,comm,parallelism -H --stdio ... # Latency Command / Parallelism # ........... ..................... # 31.84% cc1 29.96% 5 1.24% 4 0.37% 6 0.26% 3 0.02% 2 24.68% as 22.39% 5 1.12% 2 0.98% 4 0.12% 3 0.07% 6 ... Committer testing: Before: $ perf report -F latency,comm,parallelism -H --stdio Error: --hierarchy and --fields options cannot be used together Usage: perf report [] -F, --fields output field(s): overhead latency overhead_sys overhead_us overhead_guest_sys overhead_guest_us overhead_children latency_children sample period weight1 weight2 weight3 -H, --hierarchy Show entries in a hierarchy $ After: $ perf report -F latency,comm,parallelism -H --stdio # Total Lost Samples: 0 # # Samples: 1K of event 'cycles:Pu' # Event count (approx.): 1581450138 # # Latency Command / Parallelism # ........... ..................... # 97.66% git 96.95% 1 0.55% 2 0.04% 5 0.03% 8 0.03% 4 0.02% 3 0.01% 9 0.01% 7 0.01% 6 0.01% 10 0.00% 12 2.34% git-remote-http 2.24% 1 0.07% 5 0.02% 2 0.00% 4 # # (Tip: To analyze particular parallelism levels, try: perf report --latency --parallelism=32-64) Signed-off-by: Namhyung Kim Tested-by: Arnaldo Carvalho de Melo Cc: Adrian Hunter Cc: Ian Rogers Cc: Ingo Molnar Cc: Jiri Olsa Cc: Kan Liang Cc: Peter Zijlstra Link: https://lore.kernel.org/r/20250331073722.4695-5-namhyung@kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-report.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index c207aaed7ae5..f0299c7ee025 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c @@ -1672,14 +1672,10 @@ repeat: } if (symbol_conf.report_hierarchy) { - /* disable incompatible options */ - if (field_order) { - pr_err("Error: --hierarchy and --fields options cannot be used together\n"); - parse_options_usage(report_usage, options, "F", 1); - parse_options_usage(NULL, options, "hierarchy", 0); - goto error; - } - + /* + * The hist entries in hierarchy are added during the collpase + * phase. Let's enable it even if no sort keys require it. + */ perf_hpp_list.need_collapse = true; } -- 2.51.0