From: Jiri Olsa <jolsa@redhat.com>
To: Namhyung Kim <namhyung@kernel.org>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>,
Ingo Molnar <mingo@kernel.org>,
Peter Zijlstra <a.p.zijlstra@chello.nl>,
Mark Rutland <mark.rutland@arm.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
LKML <linux-kernel@vger.kernel.org>,
Stephane Eranian <eranian@google.com>,
Ian Rogers <irogers@google.com>
Subject: Re: [PATCH] perf data: Allow to use stdio functions for pipe mode
Date: Thu, 29 Oct 2020 12:57:43 +0100 [thread overview]
Message-ID: <20201029115743.GF3027684@krava> (raw)
In-Reply-To: <20201028085632.825804-1-namhyung@kernel.org>
On Wed, Oct 28, 2020 at 05:56:32PM +0900, Namhyung Kim wrote:
> When perf data is in a pipe, it reads each event separately using
> read(2) syscall. This is a huge performance bottleneck when
> processing large data like in perf inject. Also perf inject needs to
> use write(2) syscall for the output.
>
> So convert it to use buffer I/O functions in stdio library for pipe
> data. This makes inject-build-id bench time drops from 20ms to 8ms.
>
> $ perf bench internals inject-build-id
> # Running 'internals/inject-build-id' benchmark:
> Average build-id injection took: 8.074 msec (+- 0.013 msec)
> Average time per event: 0.792 usec (+- 0.001 usec)
> Average memory usage: 8328 KB (+- 0 KB)
> Average build-id-all injection took: 5.490 msec (+- 0.008 msec)
> Average time per event: 0.538 usec (+- 0.001 usec)
> Average memory usage: 7563 KB (+- 0 KB)
>
> This patch enables it just for perf inject when used with pipe (it's a
> default behavior). Maybe we could do it for perf record and/or report
> later..
>
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
> ---
> tools/perf/builtin-inject.c | 2 ++
> tools/perf/util/data.c | 36 +++++++++++++++++++++++++++++++++---
> tools/perf/util/data.h | 11 ++++++++++-
> tools/perf/util/header.c | 8 ++++----
> tools/perf/util/session.c | 7 ++++---
> 5 files changed, 53 insertions(+), 11 deletions(-)
>
> diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c
> index 452a75fe68e5..14d6c88fed76 100644
> --- a/tools/perf/builtin-inject.c
> +++ b/tools/perf/builtin-inject.c
> @@ -853,10 +853,12 @@ int cmd_inject(int argc, const char **argv)
> .output = {
> .path = "-",
> .mode = PERF_DATA_MODE_WRITE,
> + .use_stdio = true,
> },
> };
> struct perf_data data = {
> .mode = PERF_DATA_MODE_READ,
> + .use_stdio = true,
> };
> int ret;
>
> diff --git a/tools/perf/util/data.c b/tools/perf/util/data.c
> index c47aa34fdc0a..47b5a4b50ca5 100644
> --- a/tools/perf/util/data.c
> +++ b/tools/perf/util/data.c
> @@ -174,8 +174,16 @@ static bool check_pipe(struct perf_data *data)
> is_pipe = true;
> }
>
> - if (is_pipe)
> - data->file.fd = fd;
> + if (is_pipe) {
> + if (data->use_stdio) {
> + const char *mode;
> +
> + mode = perf_data__is_read(data) ? "r" : "w";
> + data->file.fptr = fdopen(fd, mode);
I guess fdopen should never fail right? but I think we should
add BUG_ON(data->file.fptr == NULL) or something
other than this the change looks good, I can see the speedup
in bench as well
jirka
next prev parent reply other threads:[~2020-10-29 11:57 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-28 8:56 [PATCH] perf data: Allow to use stdio functions for pipe mode Namhyung Kim
2020-10-28 16:37 ` Ian Rogers
2020-10-29 11:15 ` Namhyung Kim
2020-10-29 11:57 ` Jiri Olsa [this message]
2020-10-30 5:34 ` Namhyung Kim
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201029115743.GF3027684@krava \
--to=jolsa@redhat.com \
--cc=a.p.zijlstra@chello.nl \
--cc=acme@kernel.org \
--cc=alexander.shishkin@linux.intel.com \
--cc=eranian@google.com \
--cc=irogers@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@kernel.org \
--cc=namhyung@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox