Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 191114
b: refs/heads/master
c: 6be2850
h: refs/heads/master
v: v3
  • Loading branch information
Zhang, Yanmin authored and Ingo Molnar committed Mar 18, 2010
1 parent 75394fc commit 521ba3e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: d6dc0b4ead6e8720096ecfa3d9e899b47ddbc8ed
refs/heads/master: 6be2850effd6a8bae11d623c8c52e88d2fbc0e96
24 changes: 14 additions & 10 deletions trunk/tools/perf/builtin-stat.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,10 @@ static void create_perf_stat_counter(int counter, int pid)
}
} else {
attr->inherit = inherit;
attr->disabled = 1;
attr->enable_on_exec = 1;
if (target_pid == -1) {
attr->disabled = 1;
attr->enable_on_exec = 1;
}

fd[0][counter] = sys_perf_event_open(attr, pid, -1, -1, 0);
if (fd[0][counter] < 0 && verbose)
Expand Down Expand Up @@ -251,9 +253,9 @@ static int run_perf_stat(int argc __used, const char **argv)
unsigned long long t0, t1;
int status = 0;
int counter;
int pid = target_pid;
int pid;
int child_ready_pipe[2], go_pipe[2];
const bool forks = (target_pid == -1 && argc > 0);
const bool forks = (argc > 0);
char buf;

if (!system_wide)
Expand All @@ -265,10 +267,10 @@ static int run_perf_stat(int argc __used, const char **argv)
}

if (forks) {
if ((pid = fork()) < 0)
if ((child_pid = fork()) < 0)
perror("failed to fork");

if (!pid) {
if (!child_pid) {
close(child_ready_pipe[0]);
close(go_pipe[1]);
fcntl(go_pipe[0], F_SETFD, FD_CLOEXEC);
Expand Down Expand Up @@ -297,8 +299,6 @@ static int run_perf_stat(int argc __used, const char **argv)
exit(-1);
}

child_pid = pid;

/*
* Wait for the child to be ready to exec.
*/
Expand All @@ -309,6 +309,10 @@ static int run_perf_stat(int argc __used, const char **argv)
close(child_ready_pipe[0]);
}

if (target_pid == -1)
pid = child_pid;
else
pid = target_pid;
for (counter = 0; counter < nr_counters; counter++)
create_perf_stat_counter(counter, pid);

Expand All @@ -321,7 +325,7 @@ static int run_perf_stat(int argc __used, const char **argv)
close(go_pipe[1]);
wait(&status);
} else {
while(!done);
while(!done) sleep(1);
}

t1 = rdclock();
Expand Down Expand Up @@ -459,7 +463,7 @@ static volatile int signr = -1;

static void skip_signal(int signo)
{
if(target_pid != -1)
if(child_pid == -1)
done = 1;

signr = signo;
Expand Down

0 comments on commit 521ba3e

Please sign in to comment.