Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1225476pxu; Mon, 23 Nov 2020 15:12:55 -0800 (PST) X-Google-Smtp-Source: ABdhPJx+OOt1tZdwR/FfABWA+zgNE2VCN5/jK4BBUENsovHQspfMBuw/DXWcpHVsU0g1U35yX9TS X-Received: by 2002:a50:e715:: with SMTP id a21mr1471404edn.285.1606173174923; Mon, 23 Nov 2020 15:12:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606173174; cv=none; d=google.com; s=arc-20160816; b=S2oMfKttdIvdO/T1H29jVkwoe9Q+JLhUiJpEnOOo6vP5bXpiQXH9RQ5v08KQAJwH+y PVLURWT57ozOCPn1nICFWHsQTM2eKVu5tTVGLzm5Vzg2IrOE4aueiIN25pAdaivGSbgQ 68MBXd/oiTYVLHZT2EEMPMb4q1RMVkRrb3E1Z9az7LEvUN5RKwwdxs9+X4NkfyBYbeT9 L2ByK+23H+KQ7v0U6ByAcKLR+ruq9oOh1kjEnCaHEvOS+y9hKWO3gjGeH1i7HRbAv1Pz Wi/Puw8va0Ji4TFRUCQvL+lYmh26puYEbFwPLC4MbL0K+0+d7tdMrjv8HgrFfrx6Ke+f wcPw== 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=DoZx2U3nkjdWq2AStJ+fnZiQ5K0VzQoLW4EOnMjgXuY=; b=dP88ov10GTIdnYL+efSt8lwDpy3mWBXO7bzXVhMqzb1zPiPTbdiFmzRDgv1XkK/rmA lRC+opEMmTf1gftap1ZuxgMatmJ/xQ9O7449LCgvR7ja07bofMuAIchLkepqHiME2Ean yOWo4xDHIUx/Vwt6JweDEkKSkQxWckb+/ipR93VN2L7FQiMzhElwNnxvuSVVCaxujZkG 2awQekPeD4aIzcvzdabcE4y240QO1PczrdqeM5Ds4oewF3kD0u7X742ZJ+PS8gp9nptW Heb3LhAK/iaf5U+YKT9nrZHLWKZnpf0PpC/MuGQb+LDKG3kxdJrpuTsQgeVG0VU4uZw2 Uiew== 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 m12si7657336edv.299.2020.11.23.15.12.31; Mon, 23 Nov 2020 15:12:54 -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 S2388392AbgKWXIj convert rfc822-to-8bit (ORCPT + 99 others); Mon, 23 Nov 2020 18:08:39 -0500 Received: from us-smtp-delivery-44.mimecast.com ([205.139.111.44]:33613 "EHLO us-smtp-delivery-44.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388267AbgKWXGo (ORCPT ); Mon, 23 Nov 2020 18:06:44 -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-184-HeU2SR4oMQW01Wh3ODaRpA-1; Mon, 23 Nov 2020 18:06:36 -0500 X-MC-Unique: HeU2SR4oMQW01Wh3ODaRpA-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CAAF1100A241; Mon, 23 Nov 2020 23:06:34 +0000 (UTC) Received: from krava.redhat.com (unknown [10.40.195.242]) by smtp.corp.redhat.com (Postfix) with ESMTP id D62AB5D9CA; Mon, 23 Nov 2020 23:06:31 +0000 (UTC) From: Jiri Olsa To: Arnaldo Carvalho de Melo Cc: Ian Rogers , lkml , Peter Zijlstra , Ingo Molnar , Mark Rutland , Namhyung Kim , Alexander Shishkin , Michael Petlan , Song Liu , Stephane Eranian , Alexey Budankov , Andi Kleen , Adrian Hunter Subject: [PATCH 20/25] perf tools: Add is_perf_data function Date: Tue, 24 Nov 2020 00:05:07 +0100 Message-Id: <20201123230512.2097312-21-jolsa@kernel.org> In-Reply-To: <20201123230512.2097312-1-jolsa@kernel.org> References: <20201123230512.2097312-1-jolsa@kernel.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jolsa@kernel.org 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. Acked-by: Ian Rogers 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 05bbcb663c41..f29af4fc3d09 100644 --- a/tools/perf/util/data.c +++ b/tools/perf/util/data.c @@ -492,3 +492,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 c563fcbb0288..62a3e66fbee8 100644 --- a/tools/perf/util/data.h +++ b/tools/perf/util/data.h @@ -98,4 +98,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