Skip to contentSkip to conversation

perf report: Fix --task and --stat with pipe input

PATCH In review Namhyung Kim 3 participants 3 messages Jun 30, 2021 – Jul 2, 2021 perf events

lore
Share & tools
lore

Namhyung Kim

author maintainer
#0 lore raw

PATCH 1/1 perf report: Fix --task and --stat with pipe input

Current perf report fails to process a pipe input when --task or --stat option is used. This is because they reset all the tool callbacks and failed to find a matching event for a sample.

When pipe input is used, the event info is passed via ATTR records so it needs to handle that operation. Otherwise the following error occurred. Note, -14 (= -EFAULT) comes from evlist__parse_sample():

  # perf record -a -o- sleep 1 | perf report -i- --stat
  Can't parse sample, err = -14
  0x271044 [0x38]: failed to process type: 9
  Error:
  failed to process sample
---
 tools/perf/builtin-report.c | 6 ++++++
 1 file changed, 6 insertions(+)
tools/perf/builtin-report.c +6 -0
index bc5c393021dc..8639bbe0969d 100644
@@ -729,9 +729,14 @@ static int count_sample_event(struct perf_tool *tool __maybe_unused,
 	return 0;
 }
 
+static int process_attr(struct perf_tool *tool __maybe_unused,
+			union perf_event *event,
+			struct evlist **pevlist);
+
 static void stats_setup(struct report *rep)
 {
 	memset(&rep->tool, 0, sizeof(rep->tool));
+	rep->tool.attr = process_attr;
 	rep->tool.sample = count_sample_event;
 	rep->tool.no_warn = true;
 }
@@ -753,6 +758,7 @@ static void tasks_setup(struct report *rep)
 		rep->tool.mmap = perf_event__process_mmap;
 		rep->tool.mmap2 = perf_event__process_mmap2;
 	}
+	rep->tool.attr = process_attr;
 	rep->tool.comm = perf_event__process_comm;
 	rep->tool.exit = perf_event__process_exit;
 	rep->tool.fork = perf_event__process_fork;
Signature · 1 line
2.32.0.93.g670b81a890-goog
Acked-by on v1 1/1
#1 lore raw
Quoted 8 lines · Namhyung Kim

Current perf report fails to process a pipe input when --task or --stat option is used. This is because they reset all the tool callbacks and failed to find a matching event for a sample.

When pipe input is used, the event info is passed via ATTR records so it needs to handle that operation. Otherwise the following error occurred. Note, -14 (= -EFAULT) comes from evlist__parse_sample():

Quoted 7 lines
  # perf record -a -o- sleep 1 | perf report -i- --stat
  Can't parse sample, err = -14
  0x271044 [0x38]: failed to process type: 9
  Error:
  failed to process sample

thanks,
jirka

Quoted 34 lines
---
 tools/perf/builtin-report.c | 6 ++++++
 1 file changed, 6 insertions(+)
tools/perf/builtin-report.c +6 -0
index bc5c393021dc..8639bbe0969d 100644
@@ -729,9 +729,14 @@ static int count_sample_event(struct perf_tool *tool __maybe_unused,
 	return 0;
 }
 
+static int process_attr(struct perf_tool *tool __maybe_unused,
+			union perf_event *event,
+			struct evlist **pevlist);
+
 static void stats_setup(struct report *rep)
 {
 	memset(&rep->tool, 0, sizeof(rep->tool));
+	rep->tool.attr = process_attr;
 	rep->tool.sample = count_sample_event;
 	rep->tool.no_warn = true;
 }
@@ -753,6 +758,7 @@ static void tasks_setup(struct report *rep)
 		rep->tool.mmap = perf_event__process_mmap;
 		rep->tool.mmap2 = perf_event__process_mmap2;
 	}
+	rep->tool.attr = process_attr;
 	rep->tool.comm = perf_event__process_comm;
 	rep->tool.exit = perf_event__process_exit;
 	rep->tool.fork = perf_event__process_fork;
Signature · 1 line
2.32.0.93.g670b81a890-goog
#2 lore raw

Em Fri, Jul 02, 2021 at 12:38:09PM +0200, Jiri Olsa escreveu:

Quoted 15 lines · Namhyung Kim
Quoted 14 lines

Current perf report fails to process a pipe input when --task or --stat option is used. This is because they reset all the tool callbacks and failed to find a matching event for a sample.

When pipe input is used, the event info is passed via ATTR records so it needs to handle that operation. Otherwise the following error occurred. Note, -14 (= -EFAULT) comes from evlist__parse_sample():

  # perf record -a -o- sleep 1 | perf report -i- --stat
  Can't parse sample, err = -14
  0x271044 [0x38]: failed to process type: 9
  Error:
  failed to process sample
Quoted 3 lines
Quoted 1 line

Added this for the the benefit of [email protected]:

Fixes a4a4d0a7a2b20f78 ("perf report: Add --stats option to display quick data statistics")
Quoted 38 lines

thanks,
jirka

Quoted 34 lines
---
 tools/perf/builtin-report.c | 6 ++++++
 1 file changed, 6 insertions(+)
tools/perf/builtin-report.c +6 -0
index bc5c393021dc..8639bbe0969d 100644
@@ -729,9 +729,14 @@ static int count_sample_event(struct perf_tool *tool __maybe_unused,
 	return 0;
 }
 
+static int process_attr(struct perf_tool *tool __maybe_unused,
+			union perf_event *event,
+			struct evlist **pevlist);
+
 static void stats_setup(struct report *rep)
 {
 	memset(&rep->tool, 0, sizeof(rep->tool));
+	rep->tool.attr = process_attr;
 	rep->tool.sample = count_sample_event;
 	rep->tool.no_warn = true;
 }
@@ -753,6 +758,7 @@ static void tasks_setup(struct report *rep)
 		rep->tool.mmap = perf_event__process_mmap;
 		rep->tool.mmap2 = perf_event__process_mmap2;
 	}
+	rep->tool.attr = process_attr;
 	rep->tool.comm = perf_event__process_comm;
 	rep->tool.exit = perf_event__process_exit;
 	rep->tool.fork = perf_event__process_fork;
Signature · 1 line
2.32.0.93.g670b81a890-goog
Signature · 1 line
- Arnaldo