diff options
author | Zhang, Yanmin <yanmin_zhang@linux.intel.com> | 2010-03-18 10:36:03 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2010-03-18 11:21:11 -0400 |
commit | 6be2850effd6a8bae11d623c8c52e88d2fbc0e96 (patch) | |
tree | f8a2e34dc16a8e79e87b4c3fbe420c2346343cf1 /tools/perf/builtin-stat.c | |
parent | d6dc0b4ead6e8720096ecfa3d9e899b47ddbc8ed (diff) |
perf stat: Enable counters when collecting process-wide or system-wide data
Command 'perf stat' doesn't enable counters when collecting an
existing (by -p) process or system-wide statistics. Fix the
issue.
Change the condition of fork/exec subcommand. If there is a
subcommand parameter, perf always forks/execs it. The usage
example is:
# perf stat -a sleep 10
So this command could collect statistics for 10 seconds
precisely. User still could stop it by CTRL+C. Without the new
capability, user could only use CTRL+C to stop it without
precise time clock.
Another issue is 'perf stat -a' consumes 100% time of a full
single logical cpu. It has a bad impact on running workload.
Fix it by adding a sleep(1) in the while(!done) loop in function
run_perf_stat.
Signed-off-by: Zhang Yanmin <yanmin_zhang@linux.intel.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Avi Kivity <avi@redhat.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Sheng Yang <sheng@linux.intel.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Joerg Roedel <joro@8bytes.org>
Cc: Jes Sorensen <Jes.Sorensen@redhat.com>
Cc: Gleb Natapov <gleb@redhat.com>
Cc: Zachary Amsden <zamsden@redhat.com>
Cc: <zhiteng.huang@intel.com>
LKML-Reference: <1268922965-14774-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'tools/perf/builtin-stat.c')
-rw-r--r-- | tools/perf/builtin-stat.c | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 95db31cff6fd..5f41244cbbf2 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c | |||
@@ -159,8 +159,10 @@ static void create_perf_stat_counter(int counter, int pid) | |||
159 | } | 159 | } |
160 | } else { | 160 | } else { |
161 | attr->inherit = inherit; | 161 | attr->inherit = inherit; |
162 | attr->disabled = 1; | 162 | if (target_pid == -1) { |
163 | attr->enable_on_exec = 1; | 163 | attr->disabled = 1; |
164 | attr->enable_on_exec = 1; | ||
165 | } | ||
164 | 166 | ||
165 | fd[0][counter] = sys_perf_event_open(attr, pid, -1, -1, 0); | 167 | fd[0][counter] = sys_perf_event_open(attr, pid, -1, -1, 0); |
166 | if (fd[0][counter] < 0 && verbose) | 168 | if (fd[0][counter] < 0 && verbose) |
@@ -251,9 +253,9 @@ static int run_perf_stat(int argc __used, const char **argv) | |||
251 | unsigned long long t0, t1; | 253 | unsigned long long t0, t1; |
252 | int status = 0; | 254 | int status = 0; |
253 | int counter; | 255 | int counter; |
254 | int pid = target_pid; | 256 | int pid; |
255 | int child_ready_pipe[2], go_pipe[2]; | 257 | int child_ready_pipe[2], go_pipe[2]; |
256 | const bool forks = (target_pid == -1 && argc > 0); | 258 | const bool forks = (argc > 0); |
257 | char buf; | 259 | char buf; |
258 | 260 | ||
259 | if (!system_wide) | 261 | if (!system_wide) |
@@ -265,10 +267,10 @@ static int run_perf_stat(int argc __used, const char **argv) | |||
265 | } | 267 | } |
266 | 268 | ||
267 | if (forks) { | 269 | if (forks) { |
268 | if ((pid = fork()) < 0) | 270 | if ((child_pid = fork()) < 0) |
269 | perror("failed to fork"); | 271 | perror("failed to fork"); |
270 | 272 | ||
271 | if (!pid) { | 273 | if (!child_pid) { |
272 | close(child_ready_pipe[0]); | 274 | close(child_ready_pipe[0]); |
273 | close(go_pipe[1]); | 275 | close(go_pipe[1]); |
274 | fcntl(go_pipe[0], F_SETFD, FD_CLOEXEC); | 276 | fcntl(go_pipe[0], F_SETFD, FD_CLOEXEC); |
@@ -297,8 +299,6 @@ static int run_perf_stat(int argc __used, const char **argv) | |||
297 | exit(-1); | 299 | exit(-1); |
298 | } | 300 | } |
299 | 301 | ||
300 | child_pid = pid; | ||
301 | |||
302 | /* | 302 | /* |
303 | * Wait for the child to be ready to exec. | 303 | * Wait for the child to be ready to exec. |
304 | */ | 304 | */ |
@@ -309,6 +309,10 @@ static int run_perf_stat(int argc __used, const char **argv) | |||
309 | close(child_ready_pipe[0]); | 309 | close(child_ready_pipe[0]); |
310 | } | 310 | } |
311 | 311 | ||
312 | if (target_pid == -1) | ||
313 | pid = child_pid; | ||
314 | else | ||
315 | pid = target_pid; | ||
312 | for (counter = 0; counter < nr_counters; counter++) | 316 | for (counter = 0; counter < nr_counters; counter++) |
313 | create_perf_stat_counter(counter, pid); | 317 | create_perf_stat_counter(counter, pid); |
314 | 318 | ||
@@ -321,7 +325,7 @@ static int run_perf_stat(int argc __used, const char **argv) | |||
321 | close(go_pipe[1]); | 325 | close(go_pipe[1]); |
322 | wait(&status); | 326 | wait(&status); |
323 | } else { | 327 | } else { |
324 | while(!done); | 328 | while(!done) sleep(1); |
325 | } | 329 | } |
326 | 330 | ||
327 | t1 = rdclock(); | 331 | t1 = rdclock(); |
@@ -459,7 +463,7 @@ static volatile int signr = -1; | |||
459 | 463 | ||
460 | static void skip_signal(int signo) | 464 | static void skip_signal(int signo) |
461 | { | 465 | { |
462 | if(target_pid != -1) | 466 | if(child_pid == -1) |
463 | done = 1; | 467 | done = 1; |
464 | 468 | ||
465 | signr = signo; | 469 | signr = signo; |