aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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 bed175d59e55..962cdbf44ae9 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) {