Skip to content

Commit

Permalink
perf record: We should fork only if a program was specified to run
Browse files Browse the repository at this point in the history
IOW: Now 'perf record -a' works, this was a bug introduced in:

856e966
"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 <[email protected]>
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
Cc: Frédéric Weisbecker <[email protected]>
Cc: Mike Galbraith <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Paul Mackerras <[email protected]>
LKML-Reference: <[email protected]>
Signed-off-by: Ingo Molnar <[email protected]>
  • Loading branch information
acmel authored and Ingo Molnar committed Dec 28, 2009
1 parent 0422a4f commit d4db3f1
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions tools/perf/builtin-record.c
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ static void atexit_header(void)
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;
struct stat st;
Expand All @@ -411,6 +411,7 @@ static int __cmd_record(int argc __used, const char **argv)
int err;
unsigned long waking = 0;
int child_ready_pipe[2], go_pipe[2];
const bool forks = target_pid == -1 && argc > 0;
char buf;

page_size = sysconf(_SC_PAGE_SIZE);
Expand All @@ -422,7 +423,7 @@ static int __cmd_record(int argc __used, const char **argv)
signal(SIGCHLD, 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");
exit(-1);
}
Expand Down Expand Up @@ -483,7 +484,7 @@ static int __cmd_record(int argc __used, const char **argv)

atexit(atexit_header);

if (target_pid == -1) {
if (forks) {
pid = fork();
if (pid < 0) {
perror("failed to fork");
Expand Down Expand Up @@ -550,7 +551,7 @@ static int __cmd_record(int argc __used, const char **argv)
return err;
}

if (!system_wide)
if (!system_wide && profile_cpu == -1)
event__synthesize_thread(pid, process_synthesized_event,
session);
else
Expand All @@ -569,7 +570,8 @@ static int __cmd_record(int argc __used, const char **argv)
/*
* Let the child rip
*/
close(go_pipe[1]);
if (forks)
close(go_pipe[1]);

for (;;) {
int hits = samples;
Expand Down Expand Up @@ -667,7 +669,7 @@ int cmd_record(int argc, const char **argv, const char *prefix __used)

argc = parse_options(argc, argv, options, record_usage,
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);

symbol__init();
Expand Down

0 comments on commit d4db3f1

Please sign in to comment.