From: Jiri Olsa <jolsa@redhat.com>
To: Namhyung Kim <namhyung@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
lkml <linux-kernel@vger.kernel.org>,
Peter Zijlstra <a.p.zijlstra@chello.nl>,
Ingo Molnar <mingo@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Michael Petlan <mpetlan@redhat.com>,
Ian Rogers <irogers@google.com>,
Stephane Eranian <eranian@google.com>,
Alexei Budankov <abudankov@huawei.com>
Subject: Re: [PATCH] perf tools: Detect when pipe is passed as perf data
Date: Tue, 29 Dec 2020 10:45:24 +0100 [thread overview]
Message-ID: <20201229094524.GG450923@krava> (raw)
In-Reply-To: <CAM9d7ciF+_s+MqNou4szVSStBObtB87UznMMG8SsZkuRyR1dNg@mail.gmail.com>
On Tue, Dec 29, 2020 at 02:53:36PM +0900, Namhyung Kim wrote:
> On Sat, Dec 26, 2020 at 7:21 AM Jiri Olsa <jolsa@kernel.org> wrote:
> >
> > Currently we allow pipe input/output only through '-' string
> > being passed to '-o' or '-i' options, like:
> >
> > # mkfifo perf.pipe
> > # perf record --no-buffering -e 'sched:sched_switch' -o - > perf.pipe &
> > [1] 354406
> > # cat perf.pipe | ./perf --no-pager script -i - | head -3
> > perf 354406 [000] 168190.164921: sched:sched_switch: perf:354406..
> > migration/0 12 [000] 168190.164928: sched:sched_switch: migration/0:..
> > perf 354406 [001] 168190.164981: sched:sched_switch: perf:354406..
> > ...
> >
> > This patch detects if given path is pipe and set the perf data
> > object accordingly, so it's possible now to do above with:
> >
> > # mkfifo perf.pipe
> > # perf record --no-buffering -e 'sched:sched_switch' -o perf.pipe &
> > [1] 360188
> > # perf --no-pager script -i ./perf.pipe | head -3
> > perf 354442 [000] 168275.464895: sched:sched_switch: perf:354442..
> > migration/0 12 [000] 168275.464902: sched:sched_switch: migration/0:..
> > perf 354442 [001] 168275.464953: sched:sched_switch: perf:354442..
> >
> > It's of course possible to combine any of above ways.
> >
> > Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> > ---
> > tools/perf/util/data.c | 27 +++++++++++++++++++++------
> > 1 file changed, 21 insertions(+), 6 deletions(-)
> >
> > diff --git a/tools/perf/util/data.c b/tools/perf/util/data.c
> > index f29af4fc3d09..767b6c903cf5 100644
> > --- a/tools/perf/util/data.c
> > +++ b/tools/perf/util/data.c
> > @@ -159,7 +159,7 @@ int perf_data__update_dir(struct perf_data *data)
> > return 0;
> > }
> >
> > -static bool check_pipe(struct perf_data *data)
> > +static int check_pipe(struct perf_data *data)
> > {
> > struct stat st;
> > bool is_pipe = false;
> > @@ -172,6 +172,15 @@ static bool check_pipe(struct perf_data *data)
> > } else {
> > if (!strcmp(data->path, "-"))
> > is_pipe = true;
> > + else if (!stat(data->path, &st) && S_ISFIFO(st.st_mode)) {
> > + int flags = perf_data__is_read(data) ?
> > + O_RDONLY : O_WRONLY|O_CREAT|O_TRUNC;
>
> I don't think we need O_CREAT here (maybe O_TRUNC as well).
I copied that from bash opening write end like:
openat(AT_FDCWD, "perf.pipe", O_WRONLY|O_CREAT|O_TRUNC, 0666 <detached ...>
however I can't see any check on kernel side for that,
so it can removed.. I'll send new version
thanks,
jirka
prev parent reply other threads:[~2020-12-29 9:47 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-25 22:21 [PATCH] perf tools: Detect when pipe is passed as perf data Jiri Olsa
2020-12-29 5:53 ` Namhyung Kim
2020-12-29 9:45 ` Jiri Olsa [this message]
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=20201229094524.GG450923@krava \
--to=jolsa@redhat.com \
--cc=a.p.zijlstra@chello.nl \
--cc=abudankov@huawei.com \
--cc=acme@kernel.org \
--cc=alexander.shishkin@linux.intel.com \
--cc=eranian@google.com \
--cc=irogers@google.com \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@kernel.org \
--cc=mpetlan@redhat.com \
--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;
as well as URLs for NNTP newsgroup(s).