From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753881AbdG3JlA (ORCPT ); Sun, 30 Jul 2017 05:41:00 -0400 Received: from terminus.zytor.com ([65.50.211.136]:35303 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750800AbdG3Jk6 (ORCPT ); Sun, 30 Jul 2017 05:40:58 -0400 Date: Sun, 30 Jul 2017 02:38:18 -0700 From: tip-bot for Jiri Olsa Message-ID: Cc: namhyung@kernel.org, alexander.shishkin@linux.intel.com, dsahern@gmail.com, linux-kernel@vger.kernel.org, a.p.zijlstra@chello.nl, mingo@kernel.org, jolsa@kernel.org, hpa@zytor.com, andi@firstfloor.org, acme@redhat.com, tglx@linutronix.de Reply-To: alexander.shishkin@linux.intel.com, namhyung@kernel.org, dsahern@gmail.com, mingo@kernel.org, a.p.zijlstra@chello.nl, linux-kernel@vger.kernel.org, hpa@zytor.com, andi@firstfloor.org, jolsa@kernel.org, acme@redhat.com, tglx@linutronix.de In-Reply-To: <20170726120206.9099-2-jolsa@kernel.org> References: <20170726120206.9099-2-jolsa@kernel.org> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/core] perf tools: Add perf_evsel__read_size function Git-Commit-ID: de63403bfd14ae8d613f30c9a0d415581b4cb37e X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: de63403bfd14ae8d613f30c9a0d415581b4cb37e Gitweb: http://git.kernel.org/tip/de63403bfd14ae8d613f30c9a0d415581b4cb37e Author: Jiri Olsa AuthorDate: Wed, 26 Jul 2017 14:02:04 +0200 Committer: Arnaldo Carvalho de Melo CommitDate: Wed, 26 Jul 2017 14:20:28 -0300 perf tools: Add perf_evsel__read_size function Currently we use the size of struct perf_counts_values to read the event, which prevents us to put any new member to the struct. Adding perf_evsel__read_size to return size of the buffer needed for event read. Signed-off-by: Jiri Olsa Cc: Alexander Shishkin Cc: Andi Kleen Cc: David Ahern Cc: Namhyung Kim Cc: Peter Zijlstra Link: http://lkml.kernel.org/r/20170726120206.9099-2-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/evsel.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 450b5fa..4dd0fcc 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -1261,15 +1261,42 @@ void perf_counts_values__scale(struct perf_counts_values *count, *pscaled = scaled; } +static int perf_evsel__read_size(struct perf_evsel *evsel) +{ + u64 read_format = evsel->attr.read_format; + int entry = sizeof(u64); /* value */ + int size = 0; + int nr = 1; + + if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) + size += sizeof(u64); + + if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) + size += sizeof(u64); + + if (read_format & PERF_FORMAT_ID) + entry += sizeof(u64); + + if (read_format & PERF_FORMAT_GROUP) { + nr = evsel->nr_members; + size += sizeof(u64); + } + + size += entry * nr; + return size; +} + int perf_evsel__read(struct perf_evsel *evsel, int cpu, int thread, struct perf_counts_values *count) { + size_t size = perf_evsel__read_size(evsel); + memset(count, 0, sizeof(*count)); if (FD(evsel, cpu, thread) < 0) return -EINVAL; - if (readn(FD(evsel, cpu, thread), count, sizeof(*count)) <= 0) + if (readn(FD(evsel, cpu, thread), count->values, size) <= 0) return -errno; return 0;