Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9572678pxu; Mon, 28 Dec 2020 21:56:04 -0800 (PST) X-Google-Smtp-Source: ABdhPJx92b+E86xhBzkOwDlpq4RYTjjcejtuVlRcPnDITmQEx9eksP7bla0ABuJ2L+4sSe2s1O5u X-Received: by 2002:a17:907:3e17:: with SMTP id hp23mr43489105ejc.545.1609221364740; Mon, 28 Dec 2020 21:56:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609221364; cv=none; d=google.com; s=arc-20160816; b=puEpaVrU6AsH9SeLLREbyUkkDlgHeC38GzYEISs8Nm8CzjWIo4U40gbh71speRDUMK Iq9PTzgVEhvGDiLs4D74qlOorwZx8iUOs7ICH8MOlWJ6BPeOYbTYHKtnvEq+lAjAjZWd HGq3etxqFRJzqErJDpytBDGqutzfE24vNvF1WOlV1jD3L+ozGUuR7hD/4SXCFtJlssNa v58RRh1z/ZMGEsHZT8waA0sVgPSfggUGRfQAfnee/RxgoCLJBMk5tkuNXEKz94dTeHSh pw8Y5YQRVI9mH7RovXmMcXtxMkO4yGjXJw8kMugMpE9pqhUXfSguQrISuzQFPhBCEPnV 2WFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version; bh=gPNfML2ks2KPHAzz+TPLrKUVoqsU6o/9WIH8efYkIsY=; b=sPPki2MsVL9S//t4rQM3y+YiqfolX4JHW/LfA5Lhy8dlHDj+uAp3Pv+8N0fOyyJ/xQ HJeF7gfPlvRqLAmnNUQv8MQ8aRGZP/zMuUOujcVW0ID8jwcRG8Uc0TLB3Gq+QKCu6UGH WaZrwsezmhYcf+rgxYUXhh4GIBN06ZKt1G80rC207jZipbU9L/qA5ClgfUS0Mhoks4jG TVCNPXS6jr2m7rJclJtFaiogrVZ/oUcqlAn0uBvBBKSoz9F3itE4yZdkjedJ8aJH/SCx OyzGNFalMaXHQSGh7TsSzaiRuxkTFyYLKrrfA2dU0BXANdDNsnt0adAvoef0N8TfkyQI K6aQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r21si1795691ejo.415.2020.12.28.21.55.42; Mon, 28 Dec 2020 21:56:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726322AbgL2Fy3 (ORCPT + 99 others); Tue, 29 Dec 2020 00:54:29 -0500 Received: from mail-qt1-f174.google.com ([209.85.160.174]:36099 "EHLO mail-qt1-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725832AbgL2Fy2 (ORCPT ); Tue, 29 Dec 2020 00:54:28 -0500 Received: by mail-qt1-f174.google.com with SMTP id z20so8367858qtq.3 for ; Mon, 28 Dec 2020 21:54:12 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=gPNfML2ks2KPHAzz+TPLrKUVoqsU6o/9WIH8efYkIsY=; b=U52nAg3+/RL25mHXu1NgbT0ig+v6Hpsx4ITDG8c+ll5oWVE33se39nOP+mu/EsnpQP IF0aBwnL6uF6grIp4HJW8XxqmrLjmdTcFXKuPt/HeLhvrWv0ynQbTE6EYkV3LnR4vubn GVEH6YAw60BwmoJyXm+/d4fl4Mv4pbhVoHUJWyP66XcIylTNUCl/YB9rIZEafirzPdLT OINyuG4kzFRCpFT1P/QafhT7C0vQcSPxgaYCwfqVok/jmeb3XmamJ6GU+x4ixcqHPfMw W+OYkMRbX1pUP+4GhM4uCrY94ejw/HGicIVQRwy+jhPy7BnLZa4+XzwV4sreiQAbBjt6 Hknw== X-Gm-Message-State: AOAM5323Oo1+RqSPSh1/gIGQ37GkqyvIA5XG53M1wQNhYD3x+Ws0m/6c sOUqMygg5cl8HLB1h6RpMkOkM7NLW8v0KWvheHQ= X-Received: by 2002:ac8:5806:: with SMTP id g6mr47211020qtg.292.1609221227277; Mon, 28 Dec 2020 21:53:47 -0800 (PST) MIME-Version: 1.0 References: <20201225222109.364465-1-jolsa@kernel.org> In-Reply-To: <20201225222109.364465-1-jolsa@kernel.org> From: Namhyung Kim Date: Tue, 29 Dec 2020 14:53:36 +0900 Message-ID: Subject: Re: [PATCH] perf tools: Detect when pipe is passed as perf data To: Jiri Olsa Cc: Arnaldo Carvalho de Melo , lkml , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Michael Petlan , Ian Rogers , Stephane Eranian , Alexei Budankov Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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). Thanks, Namhyung > + > + fd = open(data->path, flags); > + if (fd < 0) > + return -EINVAL; > + is_pipe = true; > + } > } > > if (is_pipe) { > @@ -190,7 +199,8 @@ static bool check_pipe(struct perf_data *data) > } > } > > - return data->is_pipe = is_pipe; > + data->is_pipe = is_pipe; > + return 0; > }