[PATCH 4/4] perf hist: Allow custom output fields in hierarchy mode

From: Namhyung Kim
Date: Mon Mar 31 2025 - 03:38:20 EST


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
...

Signed-off-by: Namhyung Kim <namhyung@xxxxxxxxxx>
---
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 c207aaed7ae5fc2b..f0299c7ee0254a37 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -1672,14 +1672,10 @@ int cmd_report(int argc, const char **argv)
}

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.49.0