perf inject: Fix output from a file to a pipe
authorNamhyung Kim <namhyung@kernel.org>
Mon, 19 Jul 2021 22:31:52 +0000 (15:31 -0700)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 2 Aug 2021 13:14:34 +0000 (10:14 -0300)
commitc3a057dc3aa9979ce6dc350e05eb2e4c021432cd
tree529d39004afcda9a59b78f2a77564835f4fe9fd6
parentfea20d66f90cdbdc7dccf1fa001d40e084984e55
perf inject: Fix output from a file to a pipe

When the input is a regular file but the output is a pipe, it should
write a pipe header.  But just repiping would write a portion of the
existing header which is different in 'size' value.  So we need to
prevent it and write a new pipe header along with other information
like event attributes and features.

This can handle something like this:

  # perf record -a -B sleep 1

  # perf inject -b -i perf.data | perf report -i -

Factor out perf_event__synthesize_for_pipe() to be shared between perf
record and inject.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Acked-by: Jiri Olsa <jolsa@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lore.kernel.org/lkml/20210719223153.1618812-5-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/builtin-inject.c
tools/perf/builtin-record.c
tools/perf/util/synthetic-events.c
tools/perf/util/synthetic-events.h