perf cgroup: Introduce cgroup__new() out of open coded equivalent
To follow the namespacing convention in tools/perf. 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-jaalyl6bkvvji4r5u8wqw4n4@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
@@ -109,6 +109,25 @@ static struct cgroup *evlist__find_cgroup(struct perf_evlist *evlist, char *str)
|
|||||||
return cgrp;
|
return cgrp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct cgroup *cgroup__new(char *name)
|
||||||
|
{
|
||||||
|
struct cgroup *cgroup = zalloc(sizeof(*cgroup));
|
||||||
|
|
||||||
|
if (cgroup != NULL) {
|
||||||
|
cgroup->name = name;
|
||||||
|
refcount_set(&cgroup->refcnt, 1);
|
||||||
|
|
||||||
|
cgroup->fd = open_cgroup(name);
|
||||||
|
if (cgroup->fd == -1)
|
||||||
|
goto out_err;
|
||||||
|
}
|
||||||
|
|
||||||
|
return cgroup;
|
||||||
|
out_err:
|
||||||
|
free(cgroup);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
static int add_cgroup(struct perf_evlist *evlist, char *str)
|
static int add_cgroup(struct perf_evlist *evlist, char *str)
|
||||||
{
|
{
|
||||||
struct perf_evsel *counter;
|
struct perf_evsel *counter;
|
||||||
@@ -116,18 +135,9 @@ static int add_cgroup(struct perf_evlist *evlist, char *str)
|
|||||||
int n;
|
int n;
|
||||||
|
|
||||||
if (!cgrp) {
|
if (!cgrp) {
|
||||||
cgrp = zalloc(sizeof(*cgrp));
|
cgrp = cgroup__new(str);
|
||||||
if (!cgrp)
|
if (!cgrp)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
cgrp->name = str;
|
|
||||||
refcount_set(&cgrp->refcnt, 1);
|
|
||||||
|
|
||||||
cgrp->fd = open_cgroup(str);
|
|
||||||
if (cgrp->fd == -1) {
|
|
||||||
free(cgrp);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
Reference in New Issue
Block a user