diff --git a/tools/perf/util/cgroup.c b/tools/perf/util/cgroup.c index 6fd33ffc2488d1ca893887c486eddee9fa04507f..d8cd0e601c560a51aa40378daf84b53edfaa11dd 100644 --- a/tools/perf/util/cgroup.c +++ b/tools/perf/util/cgroup.c @@ -182,6 +182,20 @@ struct cgroup *cgroup__get(struct cgroup *cgroup) return cgroup; } +static void evsel__set_default_cgroup(struct perf_evsel *evsel, struct cgroup *cgroup) +{ + if (evsel->cgrp == NULL) + evsel->cgrp = cgroup__get(cgroup); +} + +void evlist__set_default_cgroup(struct perf_evlist *evlist, struct cgroup *cgroup) +{ + struct perf_evsel *evsel; + + evlist__for_each_entry(evlist, evsel) + evsel__set_default_cgroup(evsel, cgroup); +} + int parse_cgroups(const struct option *opt, const char *str, int unset __maybe_unused) { diff --git a/tools/perf/util/cgroup.h b/tools/perf/util/cgroup.h index 0e377e6340dddbe1835c29db892113679eca76d1..b213f5e9a3ed426633db8bb3604a92db72ee90c8 100644 --- a/tools/perf/util/cgroup.h +++ b/tools/perf/util/cgroup.h @@ -22,6 +22,8 @@ struct perf_evlist; struct cgroup *evlist__findnew_cgroup(struct perf_evlist *evlist, char *name); +void evlist__set_default_cgroup(struct perf_evlist *evlist, struct cgroup *cgroup); + int parse_cgroups(const struct option *opt, const char *str, int unset); #endif /* __CGROUP_H__ */