Move all stat allocation logic related to evsel
object under single function. This way we can
use it separately for evsel object out of evlist
object.

Link: http://lkml.kernel.org/n/tip-hclg66nszn5mx8t9uwrxx...@git.kernel.org
Signed-off-by: Jiri Olsa <jo...@kernel.org>
---
 tools/perf/util/evlist.c |  7 +------
 tools/perf/util/evsel.c  | 13 +++++++++++++
 tools/perf/util/evsel.h  |  2 ++
 3 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 44d52a07223c..73db625ed1ce 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -1655,14 +1655,9 @@ void perf_evlist__set_tracking_event(struct perf_evlist 
*evlist,
 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))
+               if (perf_evsel__alloc_stats(evsel, alloc_raw))
                        goto out_free;
        }
 
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index d5680f210fc4..1608e29ab83d 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -938,6 +938,19 @@ int perf_evsel__alloc_counts(struct perf_evsel *evsel, int 
ncpus, int nthreads)
        return evsel->counts != NULL ? 0 : -ENOMEM;
 }
 
+int perf_evsel__alloc_stats(struct perf_evsel *evsel, bool alloc_raw)
+{
+       int ncpus = perf_evsel__nr_cpus(evsel);
+       int nthreads = thread_map__nr(evsel->threads);
+
+       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))
+               return -ENOMEM;
+
+       return 0;
+}
+
 static void perf_evsel__free_fd(struct perf_evsel *evsel)
 {
        xyarray__delete(evsel->fd);
diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
index d16ed197c00a..80929965f0f5 100644
--- a/tools/perf/util/evsel.h
+++ b/tools/perf/util/evsel.h
@@ -201,6 +201,8 @@ void perf_evsel__reset_stat_priv(struct perf_evsel *evsel);
 int perf_evsel__alloc_stat_priv(struct perf_evsel *evsel);
 void perf_evsel__free_stat_priv(struct perf_evsel *evsel);
 
+int perf_evsel__alloc_stats(struct perf_evsel *evsel, bool alloc_raw);
+
 void perf_evsel__reset_counts(struct perf_evsel *evsel);
 void perf_evsel__free_counts(struct perf_evsel *evsel);
 void perf_evsel__close_fd(struct perf_evsel *evsel, int ncpus, int nthreads);
-- 
1.9.3

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to