From: Arnaldo Carvalho de Melo <[email protected]>

To break down complexity in add_cgroup().

Cc: Adrian Hunter <[email protected]>
Cc: David Ahern <[email protected]>
Cc: Jiri Olsa <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Stephane Eranian <[email protected]>
Cc: Wang Nan <[email protected]>
Link: https://lkml.kernel.org/n/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
---
 tools/perf/util/cgroup.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/cgroup.c b/tools/perf/util/cgroup.c
index 8ea964461eb7..84dfc34a6d0f 100644
--- a/tools/perf/util/cgroup.c
+++ b/tools/perf/util/cgroup.c
@@ -90,11 +90,10 @@ static int open_cgroup(char *name)
        return fd;
 }
 
-static int add_cgroup(struct perf_evlist *evlist, char *str)
+static struct cgroup *evlist__find_cgroup(struct perf_evlist *evlist, char 
*str)
 {
        struct perf_evsel *counter;
        struct cgroup *cgrp = NULL;
-       int n;
        /*
         * check if cgrp is already defined, if so we reuse it
         */
@@ -107,6 +106,15 @@ static int add_cgroup(struct perf_evlist *evlist, char 
*str)
                }
        }
 
+       return cgrp;
+}
+
+static int add_cgroup(struct perf_evlist *evlist, char *str)
+{
+       struct perf_evsel *counter;
+       struct cgroup *cgrp = evlist__find_cgroup(evlist, str);
+       int n;
+
        if (!cgrp) {
                cgrp = zalloc(sizeof(*cgrp));
                if (!cgrp)
-- 
2.14.3

Reply via email to