Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3769106pxb; Tue, 17 Nov 2020 03:07:01 -0800 (PST) X-Google-Smtp-Source: ABdhPJwjO9kwZAaIiCKl+7QtL/Kd9IkPf6diR1AHobcAvdlnViJT46Q3mJCa4ptm9ioxH2QG382E X-Received: by 2002:a17:906:1989:: with SMTP id g9mr17636880ejd.62.1605611221509; Tue, 17 Nov 2020 03:07:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605611221; cv=none; d=google.com; s=arc-20160816; b=Mx2XAYEmJx9Xz6UeNOmG1KYrk5e4UcLRZg7J+DDCR4fwctvgzaWsBCyb+xyDcAa0Yp oXaQCvY13IeDTyS0nHvifTdsaJy0WWpoko+/0zUPdeA3QwkyO/Z1L4cOUm3hUfEXLxc4 vzlVAxYYOdH5bevX/a9HbqLbplsgQbVrabLjT/m5WN2g/8iDF/M0fjcqD1PdbL0Bx+xU JvZuK54i6yaSZeNs5VDqtrNWlnSMXNVryLxR8EB96aN+jyzi/c59NWIxLEZK2UJMEvIM Du/W0j8zuEC2Y88LvP2HqPwi4SEQX7EaHqkrdKr4zXBaDgdsi56qVBp8kwcWs6umG3D2 5MUA== 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=ziBWmwBRJACBMnDlNiseoN70TFtwG/Ot4OPSiCnMFDJBngjkiN+9DG7gWeO8P6xv3V S8PBDSt92fD+LWxpIYPLSc4p5yDpmCGdtQzSS3PN0vuEde6jSo+y4ZiVLnF5a06x5JUL WuRAioZ2AEvSBCXL7L1yNk5BcriWwcpCVU860j7NF4Py0yrixjEYlD/qVuDfQGEMpzdx 4+lxdpoTwagx0H1AJZ4IoPofa3kV+jAvWy68sdn5rkv0DZrW5x9ZE/uaPXaA7mF7aT4o P6v8GJ2wsefVMFELd/BREfdaKqTbLW43oQduupYfw/knFBMHP3CvITwK9BauTKYPE3w2 eaDw== 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 b12si13602633ejz.656.2020.11.17.03.06.38; Tue, 17 Nov 2020 03:07:01 -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 S1728416AbgKQLCR convert rfc822-to-8bit (ORCPT + 99 others); Tue, 17 Nov 2020 06:02:17 -0500 Received: from us-smtp-delivery-44.mimecast.com ([207.211.30.44]:30489 "EHLO us-smtp-delivery-44.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728244AbgKQLCQ (ORCPT ); Tue, 17 Nov 2020 06:02:16 -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-331-VvHP7QTLOOWQG62JG5JpHQ-1; Tue, 17 Nov 2020 06:02:10 -0500 X-MC-Unique: VvHP7QTLOOWQG62JG5JpHQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id F0CF6188C122; Tue, 17 Nov 2020 11:02:07 +0000 (UTC) Received: from krava.redhat.com (unknown [10.40.192.215]) by smtp.corp.redhat.com (Postfix) with ESMTP id F04FF5C1CF; Tue, 17 Nov 2020 11:02:04 +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: Tue, 17 Nov 2020 12:00:48 +0100 Message-Id: <20201117110053.1303113-20-jolsa@kernel.org> In-Reply-To: <20201117110053.1303113-1-jolsa@kernel.org> References: <20201117110053.1303113-1-jolsa@kernel.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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. 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