aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2011-01-11 20:42:19 -0500
committerArnaldo Carvalho de Melo <acme@redhat.com>2011-01-22 16:56:28 -0500
commitf08199d314458610d4ca52f8e86e0a4ec7a7bc54 (patch)
tree80078cf09949aab97d9470f8126dc2b0ecc9656c
parent5c581041cf97aa7980b442de81ddea8273d6dcde (diff)
perf evsel: Support event groups
The perf_evsel__open now have an extra boolean argument specifying if event grouping is desired. The first file descriptor created on a CPU becomes the group leader. Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Ingo Molnar <mingo@elte.hu> Cc: Mike Galbraith <efault@gmx.de> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephane Eranian <eranian@google.com> Cc: Tom Zanussi <tzanussi@gmail.com> LKML-Reference: <new-submission> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r--tools/perf/builtin-stat.c4
-rw-r--r--tools/perf/builtin-test.c4
-rw-r--r--tools/perf/util/evsel.c27
-rw-r--r--tools/perf/util/evsel.h10
4 files changed, 27 insertions, 18 deletions
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index da9090245934..b5fe522f11dc 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -169,7 +169,7 @@ static int create_perf_stat_counter(struct perf_evsel *evsel)
169 PERF_FORMAT_TOTAL_TIME_RUNNING; 169 PERF_FORMAT_TOTAL_TIME_RUNNING;
170 170
171 if (system_wide) 171 if (system_wide)
172 return perf_evsel__open_per_cpu(evsel, cpus); 172 return perf_evsel__open_per_cpu(evsel, cpus, false);
173 173
174 attr->inherit = !no_inherit; 174 attr->inherit = !no_inherit;
175 if (target_pid == -1 && target_tid == -1) { 175 if (target_pid == -1 && target_tid == -1) {
@@ -177,7 +177,7 @@ static int create_perf_stat_counter(struct perf_evsel *evsel)
177 attr->enable_on_exec = 1; 177 attr->enable_on_exec = 1;
178 } 178 }
179 179
180 return perf_evsel__open_per_thread(evsel, threads); 180 return perf_evsel__open_per_thread(evsel, threads, false);
181} 181}
182 182
183/* 183/*
diff --git a/tools/perf/builtin-test.c b/tools/perf/builtin-test.c
index 5dcdba653d70..4282d671b161 100644
--- a/tools/perf/builtin-test.c
+++ b/tools/perf/builtin-test.c
@@ -289,7 +289,7 @@ static int test__open_syscall_event(void)
289 goto out_thread_map_delete; 289 goto out_thread_map_delete;
290 } 290 }
291 291
292 if (perf_evsel__open_per_thread(evsel, threads) < 0) { 292 if (perf_evsel__open_per_thread(evsel, threads, false) < 0) {
293 pr_debug("failed to open counter: %s, " 293 pr_debug("failed to open counter: %s, "
294 "tweak /proc/sys/kernel/perf_event_paranoid?\n", 294 "tweak /proc/sys/kernel/perf_event_paranoid?\n",
295 strerror(errno)); 295 strerror(errno));
@@ -364,7 +364,7 @@ static int test__open_syscall_event_on_all_cpus(void)
364 goto out_thread_map_delete; 364 goto out_thread_map_delete;
365 } 365 }
366 366
367 if (perf_evsel__open(evsel, cpus, threads) < 0) { 367 if (perf_evsel__open(evsel, cpus, threads, false) < 0) {
368 pr_debug("failed to open counter: %s, " 368 pr_debug("failed to open counter: %s, "
369 "tweak /proc/sys/kernel/perf_event_paranoid?\n", 369 "tweak /proc/sys/kernel/perf_event_paranoid?\n",
370 strerror(errno)); 370 strerror(errno));
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index f5cfed60af98..da473ec93c75 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -128,7 +128,7 @@ int __perf_evsel__read(struct perf_evsel *evsel,
128} 128}
129 129
130static int __perf_evsel__open(struct perf_evsel *evsel, struct cpu_map *cpus, 130static int __perf_evsel__open(struct perf_evsel *evsel, struct cpu_map *cpus,
131 struct thread_map *threads) 131 struct thread_map *threads, bool group)
132{ 132{
133 int cpu, thread; 133 int cpu, thread;
134 134
@@ -137,12 +137,18 @@ static int __perf_evsel__open(struct perf_evsel *evsel, struct cpu_map *cpus,
137 return -1; 137 return -1;
138 138
139 for (cpu = 0; cpu < cpus->nr; cpu++) { 139 for (cpu = 0; cpu < cpus->nr; cpu++) {
140 int group_fd = -1;
141
140 for (thread = 0; thread < threads->nr; thread++) { 142 for (thread = 0; thread < threads->nr; thread++) {
141 FD(evsel, cpu, thread) = sys_perf_event_open(&evsel->attr, 143 FD(evsel, cpu, thread) = sys_perf_event_open(&evsel->attr,
142 threads->map[thread], 144 threads->map[thread],
143 cpus->map[cpu], -1, 0); 145 cpus->map[cpu],
146 group_fd, 0);
144 if (FD(evsel, cpu, thread) < 0) 147 if (FD(evsel, cpu, thread) < 0)
145 goto out_close; 148 goto out_close;
149
150 if (group && group_fd == -1)
151 group_fd = FD(evsel, cpu, thread);
146 } 152 }
147 } 153 }
148 154
@@ -175,10 +181,9 @@ static struct {
175 .threads = { -1, }, 181 .threads = { -1, },
176}; 182};
177 183
178int perf_evsel__open(struct perf_evsel *evsel, 184int perf_evsel__open(struct perf_evsel *evsel, struct cpu_map *cpus,
179 struct cpu_map *cpus, struct thread_map *threads) 185 struct thread_map *threads, bool group)
180{ 186{
181
182 if (cpus == NULL) { 187 if (cpus == NULL) {
183 /* Work around old compiler warnings about strict aliasing */ 188 /* Work around old compiler warnings about strict aliasing */
184 cpus = &empty_cpu_map.map; 189 cpus = &empty_cpu_map.map;
@@ -187,15 +192,17 @@ int perf_evsel__open(struct perf_evsel *evsel,
187 if (threads == NULL) 192 if (threads == NULL)
188 threads = &empty_thread_map.map; 193 threads = &empty_thread_map.map;
189 194
190 return __perf_evsel__open(evsel, cpus, threads); 195 return __perf_evsel__open(evsel, cpus, threads, group);
191} 196}
192 197
193int perf_evsel__open_per_cpu(struct perf_evsel *evsel, struct cpu_map *cpus) 198int perf_evsel__open_per_cpu(struct perf_evsel *evsel,
199 struct cpu_map *cpus, bool group)
194{ 200{
195 return __perf_evsel__open(evsel, cpus, &empty_thread_map.map); 201 return __perf_evsel__open(evsel, cpus, &empty_thread_map.map, group);
196} 202}
197 203
198int perf_evsel__open_per_thread(struct perf_evsel *evsel, struct thread_map *threads) 204int perf_evsel__open_per_thread(struct perf_evsel *evsel,
205 struct thread_map *threads, bool group)
199{ 206{
200 return __perf_evsel__open(evsel, &empty_cpu_map.map, threads); 207 return __perf_evsel__open(evsel, &empty_cpu_map.map, threads, group);
201} 208}
diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
index b2d755fe88a5..0962b500cb6d 100644
--- a/tools/perf/util/evsel.h
+++ b/tools/perf/util/evsel.h
@@ -45,10 +45,12 @@ int perf_evsel__alloc_counts(struct perf_evsel *evsel, int ncpus);
45void perf_evsel__free_fd(struct perf_evsel *evsel); 45void perf_evsel__free_fd(struct perf_evsel *evsel);
46void perf_evsel__close_fd(struct perf_evsel *evsel, int ncpus, int nthreads); 46void perf_evsel__close_fd(struct perf_evsel *evsel, int ncpus, int nthreads);
47 47
48int perf_evsel__open_per_cpu(struct perf_evsel *evsel, struct cpu_map *cpus); 48int perf_evsel__open_per_cpu(struct perf_evsel *evsel,
49int perf_evsel__open_per_thread(struct perf_evsel *evsel, struct thread_map *threads); 49 struct cpu_map *cpus, bool group);
50int perf_evsel__open(struct perf_evsel *evsel, 50int perf_evsel__open_per_thread(struct perf_evsel *evsel,
51 struct cpu_map *cpus, struct thread_map *threads); 51 struct thread_map *threads, bool group);
52int perf_evsel__open(struct perf_evsel *evsel, struct cpu_map *cpus,
53 struct thread_map *threads, bool group);
52 54
53#define perf_evsel__match(evsel, t, c) \ 55#define perf_evsel__match(evsel, t, c) \
54 (evsel->attr.type == PERF_TYPE_##t && \ 56 (evsel->attr.type == PERF_TYPE_##t && \