Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3535793pxb; Mon, 9 Nov 2020 13:58:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJxq0me5kmNjZmyuFuNgAlxe4EZOlN81D+8XcVJ0PYzhB6zxpmdDG5jULN82WvwnFsDUhu72 X-Received: by 2002:a05:6402:411:: with SMTP id q17mr2062795edv.125.1604959088360; Mon, 09 Nov 2020 13:58:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604959088; cv=none; d=google.com; s=arc-20160816; b=qYzs7Dhkgn9jE4wxrxfXEyfPlVijZ8ZfOsOt3YyXwyZJffzmvJ5fGz1C7Mrez/EmZw LuG4akialYnn0GmCpw3oJLj+zkVDmwQ0vRI9QTfDfGHk4vkloiny6RAl+/R0g3DRioOS SI65LL2pGC40ZbjX/LKjfXtfTJPWxD52i4dUaJoa/tZqTEPMuKwQrcZEodmGNYFTA8ff //rzP6QYPovYQq3YP9t3hXby4bOtTT3PFEWHEzqkPnXsI/3f4MWyilRg9GnP+UBnbiKT 2/Kv4AwxakJcPbE3vkQ7gpPw6mkVDSzfx/PvIatwun+JspcpM0wmLyM2rLeyru8N26rv yZZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=IHFtSm59FI/G47D4sWKSKPMVwmah/5O+Vt0VaamsBVg=; b=U6/C95lhKcWpKOO2IahtEB/+uA5FUYirJ29uK3BbVM3mYCEX2cp57BXYGnoQMS4stC rjSZX0y1Um4zc8jBNLHmgJ+P0vXR/LSe7jMyPGEuTdRoLbrAilvdYcfX2zGB3T/DCzyL rVQU1rSMYiDqP6PdJ+qgRyrOCvJP7rJZHOH2N2McCxZxklaX61fCTTGV9u+hECLjkRx4 1tbTwCDaLvkLSqLhH46IADvGyy71eb/aRicL+EZjFYO7akUZPIV5BVB0tQ3HccrPr7mu B6YPPBk1xtfAmw88OCoQIdouVnPErGNY72raeO6tzW4+TxdRVpRxc3z2cPXoEkis+QKF ap6g== 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 o22si7737166eds.598.2020.11.09.13.57.45; Mon, 09 Nov 2020 13:58:08 -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 S1731842AbgKIVzj convert rfc822-to-8bit (ORCPT + 99 others); Mon, 9 Nov 2020 16:55:39 -0500 Received: from us-smtp-delivery-44.mimecast.com ([207.211.30.44]:59686 "EHLO us-smtp-delivery-44.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731787AbgKIVzf (ORCPT ); Mon, 9 Nov 2020 16:55:35 -0500 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-29-LT5BGdzNNqKQgtLRBgii_A-1; Mon, 09 Nov 2020 16:55:33 -0500 X-MC-Unique: LT5BGdzNNqKQgtLRBgii_A-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B62581007462; Mon, 9 Nov 2020 21:55:30 +0000 (UTC) Received: from krava.redhat.com (unknown [10.40.192.57]) by smtp.corp.redhat.com (Postfix) with ESMTP id B0F196EF51; Mon, 9 Nov 2020 21:55:27 +0000 (UTC) From: Jiri Olsa To: Arnaldo Carvalho de Melo Cc: lkml , Peter Zijlstra , Ingo Molnar , Mark Rutland , Namhyung Kim , Alexander Shishkin , Michael Petlan , Song Liu , Ian Rogers , Stephane Eranian , Alexey Budankov , Andi Kleen , Adrian Hunter Subject: [PATCH 19/24] perf tools: Add is_perf_data function Date: Mon, 9 Nov 2020 22:54:10 +0100 Message-Id: <20201109215415.400153-20-jolsa@kernel.org> In-Reply-To: <20201109215415.400153-1-jolsa@kernel.org> References: <20201109215415.400153-1-jolsa@kernel.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: kernel.org Content-Transfer-Encoding: 8BIT Content-Type: text/plain; charset=WINDOWS-1252 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Adding is_perf_data function that returns true if the given path is perf data file. It will be used in following patches. Signed-off-by: Jiri Olsa --- tools/perf/util/data.c | 19 +++++++++++++++++++ tools/perf/util/data.h | 1 + 2 files changed, 20 insertions(+) diff --git a/tools/perf/util/data.c b/tools/perf/util/data.c index c47aa34fdc0a..be049e812f5a 100644 --- a/tools/perf/util/data.c +++ b/tools/perf/util/data.c @@ -457,3 +457,22 @@ char *perf_data__kallsyms_name(struct perf_data *data) return kallsyms_name; } + +bool is_perf_data(const char *path) +{ + bool ret = false; + FILE *file; + u64 magic; + + file = fopen(path, "r"); + if (!file) + return false; + + if (fread(&magic, 1, 8, file) < 8) + goto out; + + ret = is_perf_magic(magic); +out: + fclose(file); + return ret; +} diff --git a/tools/perf/util/data.h b/tools/perf/util/data.h index 75947ef6bc17..0ebb1568ca86 100644 --- a/tools/perf/util/data.h +++ b/tools/perf/util/data.h @@ -89,4 +89,5 @@ int perf_data__update_dir(struct perf_data *data); unsigned long perf_data__size(struct perf_data *data); int perf_data__make_kcore_dir(struct perf_data *data, char *buf, size_t buf_sz); char *perf_data__kallsyms_name(struct perf_data *data); +bool is_perf_data(const char *path); #endif /* __PERF_DATA_H */ -- 2.26.2