Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp584492ybj; Thu, 7 May 2020 02:53:20 -0700 (PDT) X-Google-Smtp-Source: APiQypIcTJ+U/ja+L/oR47dHzDk34LI+5edwIiXarcLVNg46oN6B89TikKF18f6AwsJHr75c//K4 X-Received: by 2002:a50:88a6:: with SMTP id d35mr5041034edd.238.1588845200736; Thu, 07 May 2020 02:53:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588845200; cv=none; d=google.com; s=arc-20160816; b=eDTWETSCNzKyCofCyAui6SsI/oFQsDunmIU7eoGLajy1wJ9UvPXQe4dEEYvrJ5Qo4O nv69mPKTFlRcDCHg9YxApNiIqnm7Yw3YdfkTLPnW8A3lYpMsTWPGRlVDCWLTQBDuaknl o7vPSClUONtbXk2he6S15X2MBb1BVxwORl77d7EINEFlKqBwsF5WdeLqG15/Pd8zo3du w+cga1npcYRAH5xurZkm0mh2EnBkIaBnZqteyWQsAKIidpfyFMcWokW88mU2wbmUljua zlY4UdcAZ6bcKnmV/Rg/9UEteW29/HRbKim+7xMvST6aBbW9RKl/bT9imrD/68MZVhNt K3VQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=vAH20VtFQP5lslNsyKkG1D4cfLa/F8Dd5f4/ggVvM/k=; b=sl4wdU0rep4XTBVYwwmityBdXX8Lepiv36xu8er+uBjeKjuVvYjhNpHbRGqyDoS0Hn dG2fC3RkKCFFk78rzvXY0KuOO4eEkPeHCxk/MdtWzOgSW4trAac/PkF0ytFQT2YA7U8Z hkYFRxs2TjWuE3FXd8Q3x4s8uYYQKM45uk3mOe8oAW3nCH09NxTCmPk8Qu8mFQXcVXQ8 8U9SSulNxgARVw2+JctH6FoTKMZAKYXFRhsxoTTstw1ThLMi1b8iImS/dD/8fnO6dl5s WguaCemjK581r00Akj6w6f8uNVTHWsouMQGxcmzz0l3fv9X5I/3LQEXR7pQ/EXR9n38E FlhA== 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 i14si3057056eja.57.2020.05.07.02.52.57; Thu, 07 May 2020 02:53:20 -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 S1726736AbgEGJvI convert rfc822-to-8bit (ORCPT + 99 others); Thu, 7 May 2020 05:51:08 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:53107 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725893AbgEGJvG (ORCPT ); Thu, 7 May 2020 05:51:06 -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-280-vgamMrb2M_u2QLFBGd4O6w-1; Thu, 07 May 2020 05:51:02 -0400 X-MC-Unique: vgamMrb2M_u2QLFBGd4O6w-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 9C577107ACF6; Thu, 7 May 2020 09:51:00 +0000 (UTC) Received: from krava.redhat.com (unknown [10.40.194.212]) by smtp.corp.redhat.com (Postfix) with ESMTP id 94E4310013BD; Thu, 7 May 2020 09:50:33 +0000 (UTC) From: Jiri Olsa To: Arnaldo Carvalho de Melo Cc: Ian Rogers , lkml , Ingo Molnar , Namhyung Kim , Alexander Shishkin , Peter Zijlstra , Michael Petlan , Paul Khuong Subject: [PATCH 3/5] perf session: Try to read pipe data from file Date: Thu, 7 May 2020 11:50:22 +0200 Message-Id: <20200507095024.2789147-4-jolsa@kernel.org> In-Reply-To: <20200507095024.2789147-1-jolsa@kernel.org> References: <20200507095024.2789147-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=WINDOWS-1252 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Ian came with the idea of having support to read the pipe data also from file. Currently pipe mode files fail 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. 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 13a1fe4ac0c0..7a67d017d72c 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