perf stat: Move perf_evlist__(alloc|free|reset)_stats into stat object
authorJiri Olsa <jolsa@kernel.org>
Fri, 26 Jun 2015 09:29:16 +0000 (11:29 +0200)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Fri, 26 Jun 2015 14:44:37 +0000 (11:44 -0300)
Moving perf_evlist__(alloc|free|reset)_stats into stat object,
so it could be used in following patches.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/1435310967-14570-12-git-send-email-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/builtin-stat.c
tools/perf/util/evlist.h
tools/perf/util/stat.c
tools/perf/util/stat.h

index 0ccba5c6b61dc9a6e53984206b972868d563dc74..3e385f9f12ee8706f5051e05e430ad8f324f2d52 100644 (file)
@@ -141,48 +141,6 @@ static inline void diff_timespec(struct timespec *r, struct timespec *a,
        }
 }
 
-static void perf_evlist__free_stats(struct perf_evlist *evlist)
-{
-       struct perf_evsel *evsel;
-
-       evlist__for_each(evlist, evsel) {
-               perf_evsel__free_stat_priv(evsel);
-               perf_evsel__free_counts(evsel);
-               perf_evsel__free_prev_raw_counts(evsel);
-       }
-}
-
-static int perf_evlist__alloc_stats(struct perf_evlist *evlist, bool alloc_raw)
-{
-       struct perf_evsel *evsel;
-       int nthreads = thread_map__nr(evsel_list->threads);
-
-       evlist__for_each(evlist, evsel) {
-               int ncpus = perf_evsel__nr_cpus(evsel);
-
-               if (perf_evsel__alloc_stat_priv(evsel) < 0 ||
-                   perf_evsel__alloc_counts(evsel, ncpus, nthreads) < 0 ||
-                   (alloc_raw && perf_evsel__alloc_prev_raw_counts(evsel, ncpus, nthreads) < 0))
-                       goto out_free;
-       }
-
-       return 0;
-
-out_free:
-       perf_evlist__free_stats(evlist);
-       return -1;
-}
-
-static void perf_evlist__reset_stats(struct perf_evlist *evlist)
-{
-       struct perf_evsel *evsel;
-
-       evlist__for_each(evlist, evsel) {
-               perf_evsel__reset_stat_priv(evsel);
-               perf_evsel__reset_counts(evsel);
-       }
-}
-
 static void perf_stat__reset_stats(void)
 {
        perf_evlist__reset_stats(evsel_list);
index a8489b9d2812baecf1ba4709ff3b6da9787adda0..037633c1da9d0c42402b908294724f92e6caddc8 100644 (file)
@@ -289,5 +289,4 @@ void perf_evlist__to_front(struct perf_evlist *evlist,
 
 void perf_evlist__set_tracking_event(struct perf_evlist *evlist,
                                     struct perf_evsel *tracking_evsel);
-
 #endif /* __PERF_EVLIST_H */
index 6221c38983974950a1a41191c8f26c053c28932d..818cb022fcb61eafbe46ef58f9a703a42b33cba1 100644 (file)
@@ -1,6 +1,8 @@
 #include <math.h>
 #include "stat.h"
+#include "evlist.h"
 #include "evsel.h"
+#include "thread_map.h"
 
 void update_stats(struct stats *stats, u64 val)
 {
@@ -186,3 +188,45 @@ void perf_evsel__free_prev_raw_counts(struct perf_evsel *evsel)
        perf_counts__delete(evsel->prev_raw_counts);
        evsel->prev_raw_counts = NULL;
 }
+
+int perf_evlist__alloc_stats(struct perf_evlist *evlist, bool alloc_raw)
+{
+       struct perf_evsel *evsel;
+       int nthreads = thread_map__nr(evlist->threads);
+
+       evlist__for_each(evlist, evsel) {
+               int ncpus = perf_evsel__nr_cpus(evsel);
+
+               if (perf_evsel__alloc_stat_priv(evsel) < 0 ||
+                   perf_evsel__alloc_counts(evsel, ncpus, nthreads) < 0 ||
+                   (alloc_raw && perf_evsel__alloc_prev_raw_counts(evsel, ncpus, nthreads) < 0))
+                       goto out_free;
+       }
+
+       return 0;
+
+out_free:
+       perf_evlist__free_stats(evlist);
+       return -1;
+}
+
+void perf_evlist__free_stats(struct perf_evlist *evlist)
+{
+       struct perf_evsel *evsel;
+
+       evlist__for_each(evlist, evsel) {
+               perf_evsel__free_stat_priv(evsel);
+               perf_evsel__free_counts(evsel);
+               perf_evsel__free_prev_raw_counts(evsel);
+       }
+}
+
+void perf_evlist__reset_stats(struct perf_evlist *evlist)
+{
+       struct perf_evsel *evsel;
+
+       evlist__for_each(evlist, evsel) {
+               perf_evsel__reset_stat_priv(evsel);
+               perf_evsel__reset_counts(evsel);
+       }
+}
index 454b26875aef6633da1ea9ca862cf157fa745801..5f62db2472c7130cc4d153efed178d8fa6353555 100644 (file)
@@ -70,6 +70,8 @@ static inline void init_stats(struct stats *stats)
 }
 
 struct perf_evsel;
+struct perf_evlist;
+
 bool __perf_evsel_stat__is(struct perf_evsel *evsel,
                           enum perf_stat_evsel_id id);
 
@@ -100,4 +102,8 @@ void perf_evsel__free_stat_priv(struct perf_evsel *evsel);
 int perf_evsel__alloc_prev_raw_counts(struct perf_evsel *evsel,
                                      int ncpus, int nthreads);
 void perf_evsel__free_prev_raw_counts(struct perf_evsel *evsel);
+
+int perf_evlist__alloc_stats(struct perf_evlist *evlist, bool alloc_raw);
+void perf_evlist__free_stats(struct perf_evlist *evlist);
+void perf_evlist__reset_stats(struct perf_evlist *evlist);
 #endif