Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1693660

[PATCH 2/4] perf tools: Add perf_evsel__read_size function

From Jiri Olsa <jolsa@kernel.org>
Newsgroups linux.kernel
Subject [PATCH 2/4] perf tools: Add perf_evsel__read_size function
Date 2017-07-21 14:20 +0200
Message-ID <u5F4v-4Ir-29@gated-at.bofh.it> (permalink)
References <u5F4t-4Ir-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


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.

Link: http://lkml.kernel.org/n/tip-cfc3dmil3tlzezzxtyi9f38m@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 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 450b5fadf8cb..4dd0fcc06db9 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;
-- 
2.9.4

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 0/4] perf stat: Enable group read of counters Jiri Olsa <jolsa@kernel.org> - 2017-07-21 14:20 +0200
  [PATCH 1/4] perf tools: Add verbose output for sys_perf_event_open fallback Jiri Olsa <jolsa@kernel.org> - 2017-07-21 14:20 +0200
    [tip:perf/core] perf evsel: Add verbose output for  sys_perf_event_open fallback tip-bot for Jiri Olsa <tipbot@zytor.com> - 2017-07-26 19:30 +0200
  [PATCH 3/4] perf tools: Add perf_evsel__read_counter function Jiri Olsa <jolsa@kernel.org> - 2017-07-21 14:20 +0200
    Re: [PATCH 3/4] perf tools: Add perf_evsel__read_counter function Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-07-26 03:50 +0200
      Re: [PATCH 3/4] perf tools: Add perf_evsel__read_counter function Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-07-26 03:50 +0200
      Re: [PATCH 3/4] perf tools: Add perf_evsel__read_counter function Jiri Olsa <jolsa@redhat.com> - 2017-07-26 09:40 +0200
  [PATCH 2/4] perf tools: Add perf_evsel__read_size function Jiri Olsa <jolsa@kernel.org> - 2017-07-21 14:20 +0200
  Re: [PATCH 0/4] perf stat: Enable group read of counters Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-07-21 19:10 +0200

csiph-web