Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp569906ybz; Fri, 1 May 2020 04:37:03 -0700 (PDT) X-Google-Smtp-Source: APiQypJxo5ovWJ53FODeAb158chCAj7oC2kbr/sVX7j6UqkxtfCGVhRv8R+Pw5VozFlh7vEMcHhi X-Received: by 2002:a17:906:7e5a:: with SMTP id z26mr2819949ejr.168.1588333023571; Fri, 01 May 2020 04:37:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588333023; cv=none; d=google.com; s=arc-20160816; b=hvnPoGFWx9vrcvHYT4hDYYglCbRZDTWvLULBrU9b5lSBnenvgZFXZIpAintQney/c+ L/PMjJuC59IlvfqY+WfMjJAKybeLbwWtObOfPCyigMHCzhBAabh4MoSLyWubW3aQdsso cBgMuFZieQT4ZhYvzLIAORg8JBD/yEjVjr1je4LBlRCllp2K6FTrAGz/2zcNDvev+oTv Cupf0rl6fkijjWj7MZ61RvXtkytq6oqhprDBRjtmW/rLuteqnMofp4ycTHQ5k6tmsda0 WM3TvE6iz712Op0snWb6q5DxKkq6fch9JdhTjumGNygNMdpPOznTfxy8xsiL9tMsKz9F x/iA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=s38emMHfCloLgMEW5ROOiOXERRbf880IpoO6pB3Vh54=; b=OavPhgU2gEE1uEA5dnbo5iyH2rmmwxbNXilLJ5vbWvu/fhExT7+b4GLUEpfHEqyuf9 jDvF25jtIRvA85T9MZz1tbb5f5gceCVbft2S4lek1hJ/eu9vHNWlgy+tsF4LeQ60NuPb yInnQxUHg3pfE9FCYvu5Q0wvcwcErSOusBE3FPPYgTo3i6oc/QY5o5ro2tfzRGAefb1a dklrM15pNnNr2V5Zbnfz+odIXgLkjQZGamQvFXiu6PwPiD+d5tnRT6nwWoyaGTh5S9ZX w1iLSNRA8Xzy4qyN7h7tPGZS87kqfLCqsAAGoVzwZqSFjvlBRlQIGYC0qrYX+ttTYJ3E yU9Q== 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 w21si1547634edt.595.2020.05.01.04.36.39; Fri, 01 May 2020 04:37:03 -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; 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 S1728733AbgEALe7 convert rfc822-to-8bit (ORCPT + 99 others); Fri, 1 May 2020 07:34:59 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:34203 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728611AbgEALe7 (ORCPT ); Fri, 1 May 2020 07:34:59 -0400 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-486-rDzu4dICN9y18Gyi0rcGPg-1; Fri, 01 May 2020 07:34:56 -0400 X-MC-Unique: rDzu4dICN9y18Gyi0rcGPg-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5A03983DE6E; Fri, 1 May 2020 11:34:54 +0000 (UTC) Received: from krava.redhat.com (unknown [10.40.192.9]) by smtp.corp.redhat.com (Postfix) with ESMTP id 49875101D480; Fri, 1 May 2020 11:34:49 +0000 (UTC) From: Jiri Olsa To: Arnaldo Carvalho de Melo Cc: Ian Rogers , lkml , Ingo Molnar , Namhyung Kim , Alexander Shishkin , Peter Zijlstra , Michael Petlan Subject: [PATCH] perf session: Try to read pipe data from file Date: Fri, 1 May 2020 13:34:47 +0200 Message-Id: <20200501113448.1809037-1-jolsa@kernel.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: kernel.org Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 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 --- 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