perf cgroup: Add evlist__findnew_cgroup()
tip-bot for Arnaldo Carvalho de Melo
merge botCommit-ID: 69239ec81d596c57e0cf2d2f26cfe92e8cbd0929 Gitweb: https://git.kernel.org/tip/69239ec81d596c57e0cf2d2f26cfe92e8cbd0929 Author: Arnaldo Carvalho de Melo <[email protected]> AuthorDate: Tue, 6 Mar 2018 15:27:08 -0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 7 Mar 2018 10:22:26 -0300
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 <[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]>
Signed-off-by Arnaldo Carvalho de Melo <[email protected]>
--- tools/perf/util/cgroup.c | 17 ++++++++++------- tools/perf/util/cgroup.h | 4 ++++ 2 files changed, 14 insertions(+), 7 deletions(-)
tools/perf/util/cgroup.c +10 -7
@@ -128,18 +128,21 @@ out_err:return NULL ; } +struct cgroup *evlist__findnew_cgroup (struct perf_evlist *evlist,char *name) +{ +struct cgroup *cgroup =evlist__find_cgroup (evlist, name); + +return cgroup ?:cgroup__new (name); +} +static int add_cgroup (struct perf_evlist *evlist,char *str) {struct perf_evsel *counter; -struct cgroup *cgrp =evlist__find_cgroup (evlist, str); +struct cgroup *cgrp =evlist__findnew_cgroup (evlist, str);int n; -if (!cgrp) { - cgrp =cgroup__new (str); -if (!cgrp) -return -1 ; - } - +if (!cgrp) +return -1 ;/* * find corresponding event * if add cgroup N, then need to find event N
tools/perf/util/cgroup.h +4 -0
@@ -18,6 +18,10 @@ extern int nr_cgroups; /* number of explicit cgroups defined */struct cgroup *cgroup__get (struct cgroup *cgroup);void cgroup__put (struct cgroup *cgroup); +struct perf_evlist ; + +struct cgroup *evlist__findnew_cgroup (struct perf_evlist *evlist,char *name); +int parse_cgroups (const struct option *opt,const char *str,int unset);#endif /* __CGROUP_H__ */