aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2009-12-27 18:36:57 -0500
committerIngo Molnar <mingo@elte.hu>2009-12-28 03:02:50 -0500
commitd4db3f164529013b11a171bb1bd38e8681ddaec8 (patch)
tree0198f14c37e86f88a7bc3443f93abc8cfbb266d4 /tools
parent0422a4fc2c6a41c3d4184984797512af2650014e (diff)
perf record: We should fork only if a program was specified to run
IOW: Now 'perf record -a' works, this was a bug introduced in: 856e96608a72412d319e498a3a7c557571f811bd "perf record: Properly synchronize child creation" Also fix the -C usage, i.e. allow for profiling all the tasks in one CPU. Reported-by: Pekka Enberg <penberg@cs.helsinki.fi> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Frédéric Weisbecker <fweisbec@gmail.com> Cc: Mike Galbraith <efault@gmx.de> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Paul Mackerras <paulus@samba.org> LKML-Reference: <1261957026-15580-1-git-send-email-acme@infradead.org> Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'tools')
-rw-r--r--tools/perf/builtin-record.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 63136d0534d4..265425322734 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -402,7 +402,7 @@ static void atexit_header(void)
402 perf_header__write(&session->header, output, true); 402 perf_header__write(&session->header, output, true);
403} 403}
404 404
405static int __cmd_record(int argc __used, const char **argv) 405static int __cmd_record(int argc, const char **argv)
406{ 406{
407 int i, counter; 407 int i, counter;
408 struct stat st; 408 struct stat st;
@@ -411,6 +411,7 @@ static int __cmd_record(int argc __used, const char **argv)
411 int err; 411 int err;
412 unsigned long waking = 0; 412 unsigned long waking = 0;
413 int child_ready_pipe[2], go_pipe[2]; 413 int child_ready_pipe[2], go_pipe[2];
414 const bool forks = target_pid == -1 && argc > 0;
414 char buf; 415 char buf;
415 416
416 page_size = sysconf(_SC_PAGE_SIZE); 417 page_size = sysconf(_SC_PAGE_SIZE);
@@ -422,7 +423,7 @@ static int __cmd_record(int argc __used, const char **argv)
422 signal(SIGCHLD, sig_handler); 423 signal(SIGCHLD, sig_handler);
423 signal(SIGINT, sig_handler); 424 signal(SIGINT, sig_handler);
424 425
425 if (pipe(child_ready_pipe) < 0 || pipe(go_pipe) < 0) { 426 if (forks && (pipe(child_ready_pipe) < 0 || pipe(go_pipe) < 0)) {
426 perror("failed to create pipes"); 427 perror("failed to create pipes");
427 exit(-1); 428 exit(-1);
428 } 429 }
@@ -483,7 +484,7 @@ static int __cmd_record(int argc __used, const char **argv)
483 484
484 atexit(atexit_header); 485 atexit(atexit_header);
485 486
486 if (target_pid == -1) { 487 if (forks) {
487 pid = fork(); 488 pid = fork();
488 if (pid < 0) { 489 if (pid < 0) {
489 perror("failed to fork"); 490 perror("failed to fork");
@@ -550,7 +551,7 @@ static int __cmd_record(int argc __used, const char **argv)
550 return err; 551 return err;
551 } 552 }
552 553
553 if (!system_wide) 554 if (!system_wide && profile_cpu == -1)
554 event__synthesize_thread(pid, process_synthesized_event, 555 event__synthesize_thread(pid, process_synthesized_event,
555 session); 556 session);
556 else 557 else
@@ -569,7 +570,8 @@ static int __cmd_record(int argc __used, const char **argv)
569 /* 570 /*
570 * Let the child rip 571 * Let the child rip
571 */ 572 */
572 close(go_pipe[1]); 573 if (forks)
574 close(go_pipe[1]);
573 575
574 for (;;) { 576 for (;;) {
575 int hits = samples; 577 int hits = samples;
@@ -667,7 +669,7 @@ int cmd_record(int argc, const char **argv, const char *prefix __used)
667 669
668 argc = parse_options(argc, argv, options, record_usage, 670 argc = parse_options(argc, argv, options, record_usage,
669 PARSE_OPT_STOP_AT_NON_OPTION); 671 PARSE_OPT_STOP_AT_NON_OPTION);
670 if (!argc && target_pid == -1 && (!system_wide || profile_cpu == -1)) 672 if (!argc && target_pid == -1 && !system_wide && profile_cpu == -1)
671 usage_with_options(record_usage, options); 673 usage_with_options(record_usage, options);
672 674
673 symbol__init(); 675 symbol__init();