Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf cgroup: Add evlist__findnew_cgroup()

Similar to machine__findnew_thread(), etc, i.e. try to find, get a
refcount if found and return it, otherwise return a new cgroup object.

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-im1omevlihhyneiic4nl3g24@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

+14 -7
+10 -7
tools/perf/util/cgroup.c
··· 128 128 return NULL; 129 129 } 130 130 131 + struct cgroup *evlist__findnew_cgroup(struct perf_evlist *evlist, char *name) 132 + { 133 + struct cgroup *cgroup = evlist__find_cgroup(evlist, name); 134 + 135 + return cgroup ?: cgroup__new(name); 136 + } 137 + 131 138 static int add_cgroup(struct perf_evlist *evlist, char *str) 132 139 { 133 140 struct perf_evsel *counter; 134 - struct cgroup *cgrp = evlist__find_cgroup(evlist, str); 141 + struct cgroup *cgrp = evlist__findnew_cgroup(evlist, str); 135 142 int n; 136 143 137 - if (!cgrp) { 138 - cgrp = cgroup__new(str); 139 - if (!cgrp) 140 - return -1; 141 - } 142 - 144 + if (!cgrp) 145 + return -1; 143 146 /* 144 147 * find corresponding event 145 148 * if add cgroup N, then need to find event N
+4
tools/perf/util/cgroup.h
··· 18 18 struct cgroup *cgroup__get(struct cgroup *cgroup); 19 19 void cgroup__put(struct cgroup *cgroup); 20 20 21 + struct perf_evlist; 22 + 23 + struct cgroup *evlist__findnew_cgroup(struct perf_evlist *evlist, char *name); 24 + 21 25 int parse_cgroups(const struct option *opt, const char *str, int unset); 22 26 23 27 #endif /* __CGROUP_H__ */