perf evsel: Introduce perf_evsel__read_cb function
authorJiri Olsa <jolsa@kernel.org>
Fri, 21 Nov 2014 09:31:07 +0000 (10:31 +0100)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 24 Nov 2014 21:03:50 +0000 (18:03 -0300)
Adding perf_evsel__read_cb read function that retuns count values via
callback. It will be used later in stat command as single way to
retrieve counter values.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Matt Fleming <matt.fleming@intel.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/1416562275-12404-4-git-send-email-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/evsel.c
tools/perf/util/evsel.h

index 6dc7a67e6d359023c57338e8e105fd7dbff1d77f..2d26b7ad6fe053e185a18f1d345a72f7573b99ed 100644 (file)
@@ -917,6 +917,22 @@ void perf_counts_values__scale(struct perf_counts_values *count,
                *pscaled = scaled;
 }
 
+int perf_evsel__read_cb(struct perf_evsel *evsel, int cpu, int thread,
+                       perf_evsel__read_cb_t cb)
+{
+       struct perf_counts_values count;
+
+       memset(&count, 0, sizeof(count));
+
+       if (FD(evsel, cpu, thread) < 0)
+               return -EINVAL;
+
+       if (readn(FD(evsel, cpu, thread), &count, sizeof(count)) < 0)
+               return -errno;
+
+       return cb(evsel, cpu, thread, &count);
+}
+
 int __perf_evsel__read_on_cpu(struct perf_evsel *evsel,
                              int cpu, int thread, bool scale)
 {
index 7af0377ceb18117a2cb0ff0f983c08b540196dd8..5c93bed8e8d9fabbcad1204628579750680e5e16 100644 (file)
@@ -233,6 +233,13 @@ static inline bool perf_evsel__match2(struct perf_evsel *e1,
         (a)->attr.type == (b)->attr.type &&    \
         (a)->attr.config == (b)->attr.config)
 
+typedef int (perf_evsel__read_cb_t)(struct perf_evsel *evsel,
+                                   int cpu, int thread,
+                                   struct perf_counts_values *count);
+
+int perf_evsel__read_cb(struct perf_evsel *evsel, int cpu, int thread,
+                       perf_evsel__read_cb_t cb);
+
 int __perf_evsel__read_on_cpu(struct perf_evsel *evsel,
                              int cpu, int thread, bool scale);