Skip to content

Commit de63403

Browse files
olsajiriacmel
authored andcommitted
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 <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Andi Kleen <[email protected]> Cc: David Ahern <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent ee438ec commit de63403

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

tools/perf/util/evsel.c

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1261,15 +1261,42 @@ void perf_counts_values__scale(struct perf_counts_values *count,
12611261
*pscaled = scaled;
12621262
}
12631263

1264+
static int perf_evsel__read_size(struct perf_evsel *evsel)
1265+
{
1266+
u64 read_format = evsel->attr.read_format;
1267+
int entry = sizeof(u64); /* value */
1268+
int size = 0;
1269+
int nr = 1;
1270+
1271+
if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED)
1272+
size += sizeof(u64);
1273+
1274+
if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING)
1275+
size += sizeof(u64);
1276+
1277+
if (read_format & PERF_FORMAT_ID)
1278+
entry += sizeof(u64);
1279+
1280+
if (read_format & PERF_FORMAT_GROUP) {
1281+
nr = evsel->nr_members;
1282+
size += sizeof(u64);
1283+
}
1284+
1285+
size += entry * nr;
1286+
return size;
1287+
}
1288+
12641289
int perf_evsel__read(struct perf_evsel *evsel, int cpu, int thread,
12651290
struct perf_counts_values *count)
12661291
{
1292+
size_t size = perf_evsel__read_size(evsel);
1293+
12671294
memset(count, 0, sizeof(*count));
12681295

12691296
if (FD(evsel, cpu, thread) < 0)
12701297
return -EINVAL;
12711298

1272-
if (readn(FD(evsel, cpu, thread), count, sizeof(*count)) <= 0)
1299+
if (readn(FD(evsel, cpu, thread), count->values, size) <= 0)
12731300
return -errno;
12741301

12751302
return 0;

0 commit comments

Comments
 (0)