perf record: Display data size on pipe mode
authorNamhyung Kim <namhyung@kernel.org>
Fri, 12 Jan 2024 23:13:40 +0000 (15:13 -0800)
committerNamhyung Kim <namhyung@kernel.org>
Wed, 7 Feb 2024 16:55:11 +0000 (08:55 -0800)
Currently pipe mode doesn't set the file size and it results in a
misleading message of 0 data size at the end.  Although it might miss
some accounting for pipe header or more, just displaying the data size
would reduce the possible confusion.

Before:
  $ perf record -o- perf test -w noploop | perf report -i- -q --percent-limit=1
  [ perf record: Woken up 1 times to write data ]
  [ perf record: Captured and wrote 0.000 MB - ]    <======  (here)
      99.58%  perf     perf                  [.] noploop

After:
  $ perf record -o- perf test -w noploop | perf report -i- -q --percent-limit=1
  [ perf record: Woken up 1 times to write data ]
  [ perf record: Captured and wrote 0.229 MB - ]
      99.46%  perf     perf                  [.] noploop

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Reviewed-by: Ian Rogers <irogers@google.com>
Link: https://lore.kernel.org/r/20240112231340.779469-1-namhyung@kernel.org
tools/perf/builtin-record.c

index 0b6f29fa0064ea8d8cbc0e04d5f0c32eea34878f..c310eaad56ce1211913180fba992ccfae66d613e 100644 (file)
@@ -1773,8 +1773,11 @@ record__finish_output(struct record *rec)
        struct perf_data *data = &rec->data;
        int fd = perf_data__fd(data);
 
-       if (data->is_pipe)
+       if (data->is_pipe) {
+               /* Just to display approx. size */
+               data->file.size = rec->bytes_written;
                return;
+       }
 
        rec->session->header.data_size += rec->bytes_written;
        data->file.size = lseek(perf_data__fd(data), 0, SEEK_CUR);