]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
perf tools: Add perf_evsel__read_size function
authorJiri Olsa <jolsa@kernel.org>
Wed, 26 Jul 2017 12:02:04 +0000 (14:02 +0200)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 26 Jul 2017 17:20:28 +0000 (14:20 -0300)
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 <jolsa@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/20170726120206.9099-2-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/evsel.c

index 450b5fadf8cb07937f3e424b6f3ee35177c08632..4dd0fcc06db96b41b52c4c84fad8c7a4c926fff6 100644 (file)
@@ -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;