Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp914495ybz; Fri, 1 May 2020 10:51:45 -0700 (PDT) X-Google-Smtp-Source: APiQypLr+Ar2xegdXQve0T+KGi+7KXTZGnafpFMj60CrUZIjGowvWRgF+10IWmlTai2I1F4jMHSy X-Received: by 2002:a17:906:3048:: with SMTP id d8mr4297447ejd.97.1588355505333; Fri, 01 May 2020 10:51:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588355505; cv=none; d=google.com; s=arc-20160816; b=C3LmX98+zetS+tilX2BHHRhWHQF3o00vCZIGqJn+e+cD0I8ZOdAM0xS6HSt8CgztU9 qZFrIXAv6LgSkZLvt7KvsofDsWAmLRyIuXvj7lGNQZtUboWV61lz67AdufLZi6HqhYEw ojYNS190a2uVd2HRArQc5cXI78rUgB61aFukViIF1HWbqtNNv5d4LrztBw2MOap7h/J1 STfeV/85mKT5MSqa/lswlP4vWIT6ewX/Mg/iQIao6p7+MoDADum0uvOsZOJXUHHRhuy4 2eFo6fphlBueQI4mlWr0PiUXOXpXjBV33GQOGPHkTdmN+t5z4RNERy2YHm2HxkgaKFqH PCpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=Vr7i4KBzRAJaxFRYhCEC2mVKHkt5/69Cvw0YZLzHCkI=; b=dCxBju/y2os59FbSASSTficd9XVOEEe3Og4nx38ezkfbFF9+TXQO8uHRS59BCwQQ0h tiJxek2c+00317fKdpWHR0or7VuYAZJU6QJp8fUQHG9PfjSxzQkRoRpswwfVhEmHKQBe 86ndNkqFE1hjo6tPaKAKUo6og2Moo4gPylOPrjaBh8z6Qcta4JPH2m+rVkY88DZVslEd Ywv4HrbTgfCSGlkpv/TYUVM/rnzLaM8Av9fFPm02eW4ixns4vZoGzcG3PvmYxX8TNXBB OdLsnHm6SmWYWnzkroIZnhiHGulDpoEZGj/URwmBagta0s+DfZdgt1nfcELp/wMz38gX 9z/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=PsVh7QRv; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cz5si1942863edb.127.2020.05.01.10.51.22; Fri, 01 May 2020 10:51:45 -0700 (PDT) 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; dkim=pass header.i=@google.com header.s=20161025 header.b=PsVh7QRv; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729990AbgEARtV (ORCPT + 99 others); Fri, 1 May 2020 13:49:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35120 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1729697AbgEARtU (ORCPT ); Fri, 1 May 2020 13:49:20 -0400 Received: from mail-yb1-xb43.google.com (mail-yb1-xb43.google.com [IPv6:2607:f8b0:4864:20::b43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EB559C061A0C for ; Fri, 1 May 2020 10:49:18 -0700 (PDT) Received: by mail-yb1-xb43.google.com with SMTP id b17so5309473ybq.13 for ; Fri, 01 May 2020 10:49:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Vr7i4KBzRAJaxFRYhCEC2mVKHkt5/69Cvw0YZLzHCkI=; b=PsVh7QRveASnS9mQbzIV54P0vEmP87capTD8KvpENmUfjmXbCnci0GT90owMQxvORd 3mpwwpY+o3GxItma7tH2B2oc9+foqqtSJ0V1Pu6144iLPjzT4xLT4q9GnJEetWNKUzgU K6D1UEk2LbOuE/iPnIhD5D00s1uAeI1jU3vvcpf4PtzlWhYcpTl8uv4mTZU9onHfWDQk 7LQNzkytaXi/vwuxxxVJ7xnJdib4Kt9oInZH+sQk9VVsKXli++rv6CwOcrdHlm76u/Z/ U58xhqjkfgwL0MuD25Vz2b7YpSRuPg59Bn9uG0tsAyuEIbAQ6vMdRGcV57cfg0Bw4QYk mFWg== 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=Vr7i4KBzRAJaxFRYhCEC2mVKHkt5/69Cvw0YZLzHCkI=; b=c9Kv+thVsTQ44KvFdFoyWuxqmXOGQNdYSylAKhcpIVr2AEU5hied1W42yn2E/3yL4J HY6IcU64XALiO5oaV263LEWJQI2Rch1f2/1oqf3/UwCiom09u9SBHV7oZazcbixPEC9+ 1HdoSvXkAnIvgRHXPpCN6tI9rPJybF4h6514lzf58cNoT2RDw4JaYfUaWeuKGwCBt7Fv sRnpFGa0aVIp4xGzV+oR2sj5OjPzS0t/Vhgr0Jw5zWWJB6rRFejX68nSK9YuorMEAgJ0 8GeG3PVUcfmrtIjpDzTusJnKG5eq44YI7XCWCrWeT96z0Rzc3GSZl1My9avu52cy75oo Euig== X-Gm-Message-State: AGi0PuYhxWeRBIW5Q9jlEBVw8U51zCHdjDGEJ9wGh/1uXN0w+TyOxV0f IagHyUJ9B0/K6wGzAYPPMbWnMnOStKn8+ik/ZhGzkg== X-Received: by 2002:a5b:9cb:: with SMTP id y11mr8303374ybq.177.1588355357976; Fri, 01 May 2020 10:49:17 -0700 (PDT) MIME-Version: 1.0 References: <20200501113448.1809037-1-jolsa@kernel.org> In-Reply-To: <20200501113448.1809037-1-jolsa@kernel.org> From: Ian Rogers Date: Fri, 1 May 2020 10:49:06 -0700 Message-ID: Subject: Re: [PATCH] perf session: Try to read pipe data from file To: Jiri Olsa Cc: Arnaldo Carvalho de Melo , lkml , Ingo Molnar , Namhyung Kim , Alexander Shishkin , Peter Zijlstra , Michael Petlan Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, May 1, 2020 at 4:35 AM Jiri Olsa wrote: > > From: Jiri Olsa > > Ian came with the idea of having support to read the pipe > data also from file [1]. Currently pipe mode files fails > like: > > $ perf record -o - sleep 1 > /tmp/perf.pipe.data > $ perf report -i /tmp/perf.pipe.data > incompatible file format (rerun with -v to learn more) > > This patch adds the support to do that by trying the pipe > header first, and if its successfully detected, switching nit: s/its/it's/ > the perf data to pipe mode. > > [1] https://lore.kernel.org/lkml/20200409185744.255881-1-irogers@google.com/ > Original-patch-by: Ian Rogers > Signed-off-by: Jiri Olsa Tested and works great, thanks! Reviewed-by: Ian Rogers Thanks, Ian > --- > tools/perf/util/header.c | 16 ++++++++++++---- > 1 file changed, 12 insertions(+), 4 deletions(-) > > diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c > index 0ce47283a8a1..8ca709f938b8 100644 > --- a/tools/perf/util/header.c > +++ b/tools/perf/util/header.c > @@ -3574,7 +3574,7 @@ static int perf_header__read_pipe(struct perf_session *session) > return -EINVAL; > } > > - return 0; > + return f_header.size == sizeof(f_header) ? 0 : -1; > } > > static int read_attr(int fd, struct perf_header *ph, > @@ -3676,7 +3676,7 @@ int perf_session__read_header(struct perf_session *session) > struct perf_file_header f_header; > struct perf_file_attr f_attr; > u64 f_id; > - int nr_attrs, nr_ids, i, j; > + int nr_attrs, nr_ids, i, j, err; > int fd = perf_data__fd(data); > > session->evlist = evlist__new(); > @@ -3685,8 +3685,16 @@ int perf_session__read_header(struct perf_session *session) > > session->evlist->env = &header->env; > session->machines.host.env = &header->env; > - if (perf_data__is_pipe(data)) > - return perf_header__read_pipe(session); > + > + /* > + * We can read 'pipe' data event from regular file, > + * check for the pipe header regardless of source. > + */ > + err = perf_header__read_pipe(session); > + if (!err || (err && perf_data__is_pipe(data))) { > + data->is_pipe = true; > + return err; > + } > > if (perf_file_header__read(&f_header, header, fd) < 0) > return -EINVAL; > -- > 2.25.4 >