[PATCH 12/54] perf cgroup: Add evlist__add_default_cgroup()
From: Arnaldo Carvalho de Melo
Date: Thu Mar 08 2018 - 15:05:22 EST
From: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
So that tools like 'perf trace' can allow the user to set a cgroup
to be used for all the evsels still without a crgroup setup by
parse_cgroups(), such as the one to use for the syscalls, vfs_getname
and other events involved in strace like syscall tracing.
Cc: Adrian Hunter <adrian.hunter@xxxxxxxxx>
Cc: David Ahern <dsahern@xxxxxxxxx>
Cc: Jiri Olsa <jolsa@xxxxxxxxxx>
Cc: Namhyung Kim <namhyung@xxxxxxxxxx>
Cc: Stephane Eranian <eranian@xxxxxxxxxx>
Cc: Wang Nan <wangnan0@xxxxxxxxxx>
Link: https://lkml.kernel.org/n/tip-zf9jjsbj661r3lk6qb7g8j70@xxxxxxxxxxxxxx
Signed-off-by: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
---
tools/perf/util/cgroup.c | 14 ++++++++++++++
tools/perf/util/cgroup.h | 2 ++
2 files changed, 16 insertions(+)
diff --git a/tools/perf/util/cgroup.c b/tools/perf/util/cgroup.c
index 6fd33ffc2488..d8cd0e601c56 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 0e377e6340dd..b213f5e9a3ed 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__ */
--
2.14.3