Commit 1746212d authored by Namhyung Kim's avatar Namhyung Kim Committed by Arnaldo Carvalho de Melo

perf inject: Use perf_data__read() for auxtrace

In copy_bytes(), it reads the data from the (input) fd and writes it to
the output file.  But it does with the read(2) unconditionally which
caused a problem of mixing buffered vs unbuffered I/O together.

You can see the problem when using pipes.

  $ perf record -e intel_pt// -o- true | perf inject -b > /dev/null
  [ perf record: Woken up 1 times to write data ]
  [ perf record: Captured and wrote 0.000 MB - ]
  0x45c0 [0x30]: failed to process type: 71

It should use perf_data__read() to honor the 'use_stdio' setting.

Fixes: 60136667 ("perf data: Allow to use stdio functions for pipe mode")
Reviewed-by: default avatarAdrian Hunter <adrian.hunter@intel.com>
Reviewed-by: default avatarJames Clark <james.clark@arm.com>
Signed-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: https://lore.kernel.org/r/20230131023350.1903992-2-namhyung@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent c6535b6b
...@@ -215,14 +215,14 @@ static int perf_event__repipe_event_update(struct perf_tool *tool, ...@@ -215,14 +215,14 @@ static int perf_event__repipe_event_update(struct perf_tool *tool,
#ifdef HAVE_AUXTRACE_SUPPORT #ifdef HAVE_AUXTRACE_SUPPORT
static int copy_bytes(struct perf_inject *inject, int fd, off_t size) static int copy_bytes(struct perf_inject *inject, struct perf_data *data, off_t size)
{ {
char buf[4096]; char buf[4096];
ssize_t ssz; ssize_t ssz;
int ret; int ret;
while (size > 0) { while (size > 0) {
ssz = read(fd, buf, min(size, (off_t)sizeof(buf))); ssz = perf_data__read(data, buf, min(size, (off_t)sizeof(buf)));
if (ssz < 0) if (ssz < 0)
return -errno; return -errno;
ret = output_bytes(inject, buf, ssz); ret = output_bytes(inject, buf, ssz);
...@@ -260,7 +260,7 @@ static s64 perf_event__repipe_auxtrace(struct perf_session *session, ...@@ -260,7 +260,7 @@ static s64 perf_event__repipe_auxtrace(struct perf_session *session,
ret = output_bytes(inject, event, event->header.size); ret = output_bytes(inject, event, event->header.size);
if (ret < 0) if (ret < 0)
return ret; return ret;
ret = copy_bytes(inject, perf_data__fd(session->data), ret = copy_bytes(inject, session->data,
event->auxtrace.size); event->auxtrace.size);
} else { } else {
ret = output_bytes(inject, event, ret = output_bytes(inject, event,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment