perf cgroup: Introduce find_cgroup() method
authorArnaldo Carvalho de Melo <acme@redhat.com>
Tue, 6 Mar 2018 13:27:00 +0000 (10:27 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 7 Mar 2018 13:22:25 +0000 (10:22 -0300)
To break down complexity in add_cgroup().

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Wang Nan <wangnan0@huawei.com>
Link: https://lkml.kernel.org/n/tip-5yqshcf5hm837n7c86u7lhjf@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/cgroup.c

index 8ea964461eb722d2b9e5db64b717ddb0dfebc899..84dfc34a6d0fe364d6386f6dc9ab7a622c5fbd6d 100644 (file)
@@ -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)