aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/builtin-record.c
diff options
context:
space:
mode:
authorEric B Munson <ebmunson@us.ibm.com>2010-03-15 10:46:57 -0400
committerIngo Molnar <mingo@elte.hu>2010-03-15 11:08:22 -0400
commitbedbfdea31daf3880745001d56450c683959ee7e (patch)
treef039ee87fc0c76805f5f42c46b25ee732b8d6e0c /tools/perf/builtin-record.c
parente4495262826d1eabca3529fa6ac22394eb348132 (diff)
perf record: Enable the enable_on_exec flag if record forks the target
When forking its target, perf record can capture data from before the target application is started. Perf stat uses the enable_on_exec flag in the event attributes to keep from displaying events from before the target program starts, this patch adds the same functionality to perf record when it is will fork the target process. Signed-off-by: Eric B Munson <ebmunson@us.ibm.com> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Frederic Weisbecker <fweisbec@gmail.com> LKML-Reference: <1268664418-28328-1-git-send-email-acme@infradead.org> Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'tools/perf/builtin-record.c')
-rw-r--r--tools/perf/builtin-record.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index bed175d59e5..962cdbf44ae 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -225,7 +225,7 @@ static struct perf_header_attr *get_header_attr(struct perf_event_attr *a, int n
225 return h_attr; 225 return h_attr;
226} 226}
227 227
228static void create_counter(int counter, int cpu, pid_t pid) 228static void create_counter(int counter, int cpu, pid_t pid, bool forks)
229{ 229{
230 char *filter = filters[counter]; 230 char *filter = filters[counter];
231 struct perf_event_attr *attr = attrs + counter; 231 struct perf_event_attr *attr = attrs + counter;
@@ -277,6 +277,9 @@ static void create_counter(int counter, int cpu, pid_t pid)
277 attr->inherit = inherit; 277 attr->inherit = inherit;
278 attr->disabled = 1; 278 attr->disabled = 1;
279 279
280 if (forks)
281 attr->enable_on_exec = 1;
282
280try_again: 283try_again:
281 fd[nr_cpu][counter] = sys_perf_event_open(attr, pid, cpu, group_fd, 0); 284 fd[nr_cpu][counter] = sys_perf_event_open(attr, pid, cpu, group_fd, 0);
282 285
@@ -381,13 +384,13 @@ try_again:
381 ioctl(fd[nr_cpu][counter], PERF_EVENT_IOC_ENABLE); 384 ioctl(fd[nr_cpu][counter], PERF_EVENT_IOC_ENABLE);
382} 385}
383 386
384static void open_counters(int cpu, pid_t pid) 387static void open_counters(int cpu, pid_t pid, bool forks)
385{ 388{
386 int counter; 389 int counter;
387 390
388 group_fd = -1; 391 group_fd = -1;
389 for (counter = 0; counter < nr_counters; counter++) 392 for (counter = 0; counter < nr_counters; counter++)
390 create_counter(counter, cpu, pid); 393 create_counter(counter, cpu, pid, forks);
391 394
392 nr_cpu++; 395 nr_cpu++;
393} 396}
@@ -547,11 +550,11 @@ static int __cmd_record(int argc, const char **argv)
547 550
548 551
549 if ((!system_wide && !inherit) || profile_cpu != -1) { 552 if ((!system_wide && !inherit) || profile_cpu != -1) {
550 open_counters(profile_cpu, target_pid); 553 open_counters(profile_cpu, target_pid, forks);
551 } else { 554 } else {
552 nr_cpus = read_cpu_map(); 555 nr_cpus = read_cpu_map();
553 for (i = 0; i < nr_cpus; i++) 556 for (i = 0; i < nr_cpus; i++)
554 open_counters(cpumap[i], target_pid); 557 open_counters(cpumap[i], target_pid, forks);
555 } 558 }
556 559
557 if (file_new) { 560 if (file_new) {