From 5c30af92f2b1e9d844e1ae3243e4adcd7753d4c1 Mon Sep 17 00:00:00 2001 From: Jiri Olsa Date: Sun, 21 Jul 2019 13:24:51 +0200 Subject: libperf: Adopt perf_evsel__read() function from tools/perf Move the perf_evsel__read() function to libperf as a public interface together with struct perf_counts_values for returning counter values. Signed-off-by: Jiri Olsa Cc: Alexander Shishkin Cc: Alexey Budankov Cc: Andi Kleen Cc: Michael Petlan Cc: Namhyung Kim Cc: Peter Zijlstra Link: http://lkml.kernel.org/r/20190721112506.12306-65-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/counts.h | 12 +----------- tools/perf/util/evsel.c | 45 ++------------------------------------------- tools/perf/util/evsel.h | 3 --- 3 files changed, 3 insertions(+), 57 deletions(-) (limited to 'tools/perf/util') diff --git a/tools/perf/util/counts.h b/tools/perf/util/counts.h index bbfac9ecf642..13430f353c19 100644 --- a/tools/perf/util/counts.h +++ b/tools/perf/util/counts.h @@ -3,17 +3,7 @@ #define __PERF_COUNTS_H #include - -struct perf_counts_values { - union { - struct { - u64 val; - u64 ena; - u64 run; - }; - u64 values[3]; - }; -}; +#include struct perf_counts { s8 scaled; diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 8d8ed36377f5..0957ec24f518 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -1346,53 +1346,12 @@ void perf_counts_values__scale(struct perf_counts_values *count, *pscaled = scaled; } -static int perf_evsel__read_size(struct evsel *evsel) -{ - u64 read_format = evsel->core.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->core.nr_members; - size += sizeof(u64); - } - - size += entry * nr; - return size; -} - -int perf_evsel__read(struct 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->values, size) <= 0) - return -errno; - - return 0; -} - static int perf_evsel__read_one(struct evsel *evsel, int cpu, int thread) { struct perf_counts_values *count = perf_counts(evsel->counts, cpu, thread); - return perf_evsel__read(evsel, cpu, thread, count); + return perf_evsel__read(&evsel->core, cpu, thread, count); } static void @@ -1453,7 +1412,7 @@ perf_evsel__read_group(struct evsel *leader, int cpu, int thread) { struct perf_stat_evsel *ps = leader->stats; u64 read_format = leader->core.attr.read_format; - int size = perf_evsel__read_size(leader); + int size = perf_evsel__read_size(&leader->core); u64 *data = ps->group_data; if (!(read_format & PERF_FORMAT_ID)) diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index 03fc8edad492..57e315d8158e 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -336,9 +336,6 @@ static inline bool perf_evsel__match2(struct evsel *e1, (a)->core.attr.type == (b)->core.attr.type && \ (a)->core.attr.config == (b)->core.attr.config) -int perf_evsel__read(struct evsel *evsel, int cpu, int thread, - struct perf_counts_values *count); - int perf_evsel__read_counter(struct evsel *evsel, int cpu, int thread); int __perf_evsel__read_on_cpu(struct evsel *evsel, -- cgit v1.2.3-59-g8ed1b