From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 840B1C433E0 for ; Tue, 29 Dec 2020 09:47:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 31C1421D7F for ; Tue, 29 Dec 2020 09:47:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726265AbgL2JrB (ORCPT ); Tue, 29 Dec 2020 04:47:01 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:25245 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725979AbgL2JrA (ORCPT ); Tue, 29 Dec 2020 04:47:00 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1609235133; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=EHujqTQJeLBNhAhHdnbewrD1ZbbPgrDviwX6XQxpul4=; b=cAvpnnVFyxhPONgr9HXeBl92D5i/T6uJDy3vjeT1LGql9dtLqI94Q5JIfOuYcsRg/ngn50 075h8F9DGFuDByVI4OuU8727NdGbDqkP3lRXF/JGLTaZhpi3Q23qCrm2HT8HA5E3zSXhDt r6lkHO/LQPBCB6+n7G5r3vZ36wPzjk8= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-487-aOlPMDqmPdKEWY3mWbYCxA-1; Tue, 29 Dec 2020 04:45:31 -0500 X-MC-Unique: aOlPMDqmPdKEWY3mWbYCxA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 450F4107ACE4; Tue, 29 Dec 2020 09:45:29 +0000 (UTC) Received: from krava (unknown [10.40.192.119]) by smtp.corp.redhat.com (Postfix) with SMTP id E9AA57216E; Tue, 29 Dec 2020 09:45:25 +0000 (UTC) Date: Tue, 29 Dec 2020 10:45:24 +0100 From: Jiri Olsa To: Namhyung Kim Cc: Jiri Olsa , Arnaldo Carvalho de Melo , lkml , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Michael Petlan , Ian Rogers , Stephane Eranian , Alexei Budankov Subject: Re: [PATCH] perf tools: Detect when pipe is passed as perf data Message-ID: <20201229094524.GG450923@krava> References: <20201225222109.364465-1-jolsa@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Dec 29, 2020 at 02:53:36PM +0900, Namhyung Kim wrote: > On Sat, Dec 26, 2020 at 7:21 AM Jiri Olsa 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 > > --- > > 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 however I can't see any check on kernel side for that, so it can removed.. I'll send new version thanks, jirka