Skip to content

Commit a6e4a4a

Browse files
committed
perf report: Fix hierarchy mode on pipe input
The hierarchy mode needs to setup output formats for each evsel. Normally setup_sorting() handles this at the beginning, but it cannot do that if data comes from a pipe since there's no evsel info before reading the data. And then perf report cannot process the samples in hierarchy mode and think as if there's no sample. Let's check the condition and setup the output formats after reading data so that it can find evsels. Before: $ ./perf record -o- true | ./perf report -i- --hierarchy -q [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.000 MB - ] Error: The - data has no samples! After: $ ./perf record -o- true | ./perf report -i- --hierarchy -q [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.000 MB - ] 94.76% true 94.76% [kernel.kallsyms] 94.76% [k] filemap_fault 5.24% perf-ex 5.24% [kernel.kallsyms] 5.06% [k] __memset 0.18% [k] native_write_msr Acked-by: Ian Rogers <irogers@google.com> Link: https://lore.kernel.org/r/20231025003121.2811738-1-namhyung@kernel.org Signed-off-by: Namhyung Kim <namhyung@kernel.org>
1 parent b571104 commit a6e4a4a

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

tools/perf/builtin-report.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,10 +691,25 @@ static int report__browse_hists(struct report *rep)
691691

692692
static int report__collapse_hists(struct report *rep)
693693
{
694+
struct perf_session *session = rep->session;
695+
struct evlist *evlist = session->evlist;
694696
struct ui_progress prog;
695697
struct evsel *pos;
696698
int ret = 0;
697699

700+
/*
701+
* The pipe data needs to setup hierarchy hpp formats now, because it
702+
* cannot know about evsels in the data before reading the data. The
703+
* normal file data saves the event (attribute) info in the header
704+
* section, but pipe does not have the luxury.
705+
*/
706+
if (perf_data__is_pipe(session->data)) {
707+
if (perf_hpp__setup_hists_formats(&perf_hpp_list, evlist) < 0) {
708+
ui__error("Failed to setup hierachy output formats\n");
709+
return -1;
710+
}
711+
}
712+
698713
ui_progress__init(&prog, rep->nr_entries, "Merging related events...");
699714

700715
evlist__for_each_entry(rep->session->evlist, pos) {

0 commit comments

Comments
 (0)