Commit d4db3f16 authored by Arnaldo Carvalho de Melo's avatar Arnaldo Carvalho de Melo Committed by Ingo Molnar

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:

856e9660
"perf record: Properly synchronize child creation"

Also fix the -C usage, i.e. allow for profiling all the tasks in
one CPU.
Reported-by: default avatarPekka Enberg <penberg@cs.helsinki.fi>
Signed-off-by: default avatarArnaldo 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: default avatarIngo Molnar <mingo@elte.hu>
parent 0422a4fc
...@@ -402,7 +402,7 @@ static void atexit_header(void) ...@@ -402,7 +402,7 @@ static void atexit_header(void)
perf_header__write(&session->header, output, true); perf_header__write(&session->header, output, true);
} }
static int __cmd_record(int argc __used, const char **argv) static int __cmd_record(int argc, const char **argv)
{ {
int i, counter; int i, counter;
struct stat st; struct stat st;
...@@ -411,6 +411,7 @@ static int __cmd_record(int argc __used, const char **argv) ...@@ -411,6 +411,7 @@ static int __cmd_record(int argc __used, const char **argv)
int err; int err;
unsigned long waking = 0; unsigned long waking = 0;
int child_ready_pipe[2], go_pipe[2]; int child_ready_pipe[2], go_pipe[2];
const bool forks = target_pid == -1 && argc > 0;
char buf; char buf;
page_size = sysconf(_SC_PAGE_SIZE); page_size = sysconf(_SC_PAGE_SIZE);
...@@ -422,7 +423,7 @@ static int __cmd_record(int argc __used, const char **argv) ...@@ -422,7 +423,7 @@ static int __cmd_record(int argc __used, const char **argv)
signal(SIGCHLD, sig_handler); signal(SIGCHLD, sig_handler);
signal(SIGINT, sig_handler); signal(SIGINT, sig_handler);
if (pipe(child_ready_pipe) < 0 || pipe(go_pipe) < 0) { if (forks && (pipe(child_ready_pipe) < 0 || pipe(go_pipe) < 0)) {
perror("failed to create pipes"); perror("failed to create pipes");
exit(-1); exit(-1);
} }
...@@ -483,7 +484,7 @@ static int __cmd_record(int argc __used, const char **argv) ...@@ -483,7 +484,7 @@ static int __cmd_record(int argc __used, const char **argv)
atexit(atexit_header); atexit(atexit_header);
if (target_pid == -1) { if (forks) {
pid = fork(); pid = fork();
if (pid < 0) { if (pid < 0) {
perror("failed to fork"); perror("failed to fork");
...@@ -550,7 +551,7 @@ static int __cmd_record(int argc __used, const char **argv) ...@@ -550,7 +551,7 @@ static int __cmd_record(int argc __used, const char **argv)
return err; return err;
} }
if (!system_wide) if (!system_wide && profile_cpu == -1)
event__synthesize_thread(pid, process_synthesized_event, event__synthesize_thread(pid, process_synthesized_event,
session); session);
else else
...@@ -569,7 +570,8 @@ static int __cmd_record(int argc __used, const char **argv) ...@@ -569,7 +570,8 @@ static int __cmd_record(int argc __used, const char **argv)
/* /*
* Let the child rip * Let the child rip
*/ */
close(go_pipe[1]); if (forks)
close(go_pipe[1]);
for (;;) { for (;;) {
int hits = samples; int hits = samples;
...@@ -667,7 +669,7 @@ int cmd_record(int argc, const char **argv, const char *prefix __used) ...@@ -667,7 +669,7 @@ int cmd_record(int argc, const char **argv, const char *prefix __used)
argc = parse_options(argc, argv, options, record_usage, argc = parse_options(argc, argv, options, record_usage,
PARSE_OPT_STOP_AT_NON_OPTION); PARSE_OPT_STOP_AT_NON_OPTION);
if (!argc && target_pid == -1 && (!system_wide || profile_cpu == -1)) if (!argc && target_pid == -1 && !system_wide && profile_cpu == -1)
usage_with_options(record_usage, options); usage_with_options(record_usage, options);
symbol__init(); symbol__init();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment