Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp687481pxu; Thu, 26 Nov 2020 09:05:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJw02suqNPu3vFza+S2Yk68g0tbkXU8IRVtTFNM2H0s4K/uQFoodh90AxRhK9jrFzylHXjm2 X-Received: by 2002:a50:ab07:: with SMTP id s7mr3527454edc.374.1606410324326; Thu, 26 Nov 2020 09:05:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606410324; cv=none; d=google.com; s=arc-20160816; b=a8A5zwrtG53lOV5Z4i25MN46mjNkX6EJyQXih/R0/yfLY3Hl6Y3G8AS7cU7+KBlQ/O pwvkN4zs3SrF+vF+E1DyjKkxgZl48E7UXu+uqQTfsBktCQ6pG6S8j5J+PnfXbjQYrlhm Poaz0a4gnC253LBcA8Z7qZy/DfOAnfmD7e58XI3oVBMXgkvMNks2uDlrA/+g/lI3UYSc 3OHNJaJFNLdWKydYjZiuqQQ8Yv53sGRmg/G48j4ein9pyuuqT0Yjuwx2MFcJSEBuL2YW BX+1j3aLWs0ReUWcw+V168GlFqzPjahc1Oq5wc423Y1Z7uvFWY/4Yp7LNW2iPoBgKyWP 7X8Q== 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=jrpfoWKzzeeJVaLZYtHurpNdq59xpQUcQEtoQXXgemMJ4JGjH2UnNwCvjdK6xV5KcX fBOIkVr23c3FDhRhSTClk+J5RnujLf7gsqIq3HmVhQqA0QMwhaGm5OGVe2HOK9wNJMpn kMzL+q78SKEJc8qVwB8zXv6dnbDqo1T8rlcbWhqK+AEWMuSSvZDm4RiWbq8zWTcwhdF0 FtIdGwqQ6ASLgcKHi5KBbWP6+hpNdoPUtxAnEthEFIMG4K2xfB+FZ5t3G5Us67euP8Hj gbOlI7+v39ZqxoNbHwsuGjxkHfg5bU+6DlQDS/kuKkZfqyv9+h1/aauLYuJvOXO8vkeF bWmg== 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 j13si3747668edn.150.2020.11.26.09.04.57; Thu, 26 Nov 2020 09:05:24 -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 S2404183AbgKZRB5 convert rfc822-to-8bit (ORCPT + 99 others); Thu, 26 Nov 2020 12:01:57 -0500 Received: from us-smtp-delivery-44.mimecast.com ([207.211.30.44]:43818 "EHLO us-smtp-delivery-44.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404106AbgKZRB4 (ORCPT ); Thu, 26 Nov 2020 12:01:56 -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-235-yhIt8bwNPSaDTVnZlTeVqw-1; Thu, 26 Nov 2020 12:01:51 -0500 X-MC-Unique: yhIt8bwNPSaDTVnZlTeVqw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7B360100E33F; Thu, 26 Nov 2020 17:01:49 +0000 (UTC) Received: from krava.redhat.com (unknown [10.40.192.133]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6C4B860BFA; Thu, 26 Nov 2020 17:01:46 +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: Thu, 26 Nov 2020 18:00:21 +0100 Message-Id: <20201126170026.2619053-21-jolsa@kernel.org> In-Reply-To: <20201126170026.2619053-1-jolsa@kernel.org> References: <20201126170026.2619053-1-jolsa@kernel.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 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