diff options
author | Stephane Eranian <eranian@google.com> | 2011-02-14 04:20:01 -0500 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2011-02-16 07:30:48 -0500 |
commit | 023695d96ee06f36cf5014e286edcd623e9fb847 (patch) | |
tree | ff7483b7a1aa0cfd5de95475ed059822d2a35499 /tools/perf/util/evsel.c | |
parent | e5d1367f17ba6a6fed5fd8b74e4d5720923e0c25 (diff) |
perf tool: Add cgroup support
This patch adds the ability to filter monitoring based on container groups
(cgroups) for both perf stat and perf record. It is possible to monitor
multiple cgroup in parallel. There is one cgroup per event. The cgroups to
monitor are passed via a new -G option followed by a comma separated list of
cgroup names.
The cgroup filesystem has to be mounted. Given a cgroup name, the perf tool
finds the corresponding directory in the cgroup filesystem and opens it. It
then passes that file descriptor to the kernel.
Example:
$ perf stat -B -a -e cycles:u,cycles:u,cycles:u -G test1,,test2 -- sleep 1
Performance counter stats for 'sleep 1':
2,368,667,414 cycles test1
2,369,661,459 cycles
<not counted> cycles test2
1.001856890 seconds time elapsed
Signed-off-by: Stephane Eranian <eranian@google.com>
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
LKML-Reference: <4d590290.825bdf0a.7d0a.4890@mx.google.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'tools/perf/util/evsel.c')
-rw-r--r-- | tools/perf/util/evsel.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 211063eed474..c974e08d07ab 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c | |||
@@ -85,6 +85,7 @@ void perf_evsel__exit(struct perf_evsel *evsel) | |||
85 | void perf_evsel__delete(struct perf_evsel *evsel) | 85 | void perf_evsel__delete(struct perf_evsel *evsel) |
86 | { | 86 | { |
87 | perf_evsel__exit(evsel); | 87 | perf_evsel__exit(evsel); |
88 | close_cgroup(evsel->cgrp); | ||
88 | free(evsel); | 89 | free(evsel); |
89 | } | 90 | } |
90 | 91 | ||
@@ -163,21 +164,32 @@ static int __perf_evsel__open(struct perf_evsel *evsel, struct cpu_map *cpus, | |||
163 | struct thread_map *threads, bool group, bool inherit) | 164 | struct thread_map *threads, bool group, bool inherit) |
164 | { | 165 | { |
165 | int cpu, thread; | 166 | int cpu, thread; |
167 | unsigned long flags = 0; | ||
168 | int pid = -1; | ||
166 | 169 | ||
167 | if (evsel->fd == NULL && | 170 | if (evsel->fd == NULL && |
168 | perf_evsel__alloc_fd(evsel, cpus->nr, threads->nr) < 0) | 171 | perf_evsel__alloc_fd(evsel, cpus->nr, threads->nr) < 0) |
169 | return -1; | 172 | return -1; |
170 | 173 | ||
174 | if (evsel->cgrp) { | ||
175 | flags = PERF_FLAG_PID_CGROUP; | ||
176 | pid = evsel->cgrp->fd; | ||
177 | } | ||
178 | |||
171 | for (cpu = 0; cpu < cpus->nr; cpu++) { | 179 | for (cpu = 0; cpu < cpus->nr; cpu++) { |
172 | int group_fd = -1; | 180 | int group_fd = -1; |
173 | 181 | ||
174 | evsel->attr.inherit = (cpus->map[cpu] < 0) && inherit; | 182 | evsel->attr.inherit = (cpus->map[cpu] < 0) && inherit; |
175 | 183 | ||
176 | for (thread = 0; thread < threads->nr; thread++) { | 184 | for (thread = 0; thread < threads->nr; thread++) { |
185 | |||
186 | if (!evsel->cgrp) | ||
187 | pid = threads->map[thread]; | ||
188 | |||
177 | FD(evsel, cpu, thread) = sys_perf_event_open(&evsel->attr, | 189 | FD(evsel, cpu, thread) = sys_perf_event_open(&evsel->attr, |
178 | threads->map[thread], | 190 | pid, |
179 | cpus->map[cpu], | 191 | cpus->map[cpu], |
180 | group_fd, 0); | 192 | group_fd, flags); |
181 | if (FD(evsel, cpu, thread) < 0) | 193 | if (FD(evsel, cpu, thread) < 0) |
182 | goto out_close; | 194 | goto out_close; |
183 | 195 | ||