diff options
author | Namhyung Kim <namhyung.kim@lge.com> | 2013-03-11 03:43:18 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2013-03-15 12:06:04 -0400 |
commit | acf2892270dcc4288c572b1159474c81f3819749 (patch) | |
tree | 8f01c571a93175af211eded4f05be63c7d909840 /tools/perf | |
parent | 55e162ea764cb5b38f27ea0b16ee7d31c1a5aedb (diff) |
perf stat: Use perf_evlist__prepare/start_workload()
The perf stat had an open code to the duplicated work. Use the helper
as it now can be called without struct perf_record_opts.
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1362987798-24969-7-git-send-email-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf')
-rw-r--r-- | tools/perf/builtin-stat.c | 58 |
1 files changed, 7 insertions, 51 deletions
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 20ffaf98782e..69fe6ed89627 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c | |||
@@ -337,16 +337,14 @@ static void print_interval(void) | |||
337 | } | 337 | } |
338 | } | 338 | } |
339 | 339 | ||
340 | static int __run_perf_stat(int argc __maybe_unused, const char **argv) | 340 | static int __run_perf_stat(int argc, const char **argv) |
341 | { | 341 | { |
342 | char msg[512]; | 342 | char msg[512]; |
343 | unsigned long long t0, t1; | 343 | unsigned long long t0, t1; |
344 | struct perf_evsel *counter; | 344 | struct perf_evsel *counter; |
345 | struct timespec ts; | 345 | struct timespec ts; |
346 | int status = 0; | 346 | int status = 0; |
347 | int child_ready_pipe[2], go_pipe[2]; | ||
348 | const bool forks = (argc > 0); | 347 | const bool forks = (argc > 0); |
349 | char buf; | ||
350 | 348 | ||
351 | if (interval) { | 349 | if (interval) { |
352 | ts.tv_sec = interval / 1000; | 350 | ts.tv_sec = interval / 1000; |
@@ -362,55 +360,12 @@ static int __run_perf_stat(int argc __maybe_unused, const char **argv) | |||
362 | return -1; | 360 | return -1; |
363 | } | 361 | } |
364 | 362 | ||
365 | if (forks && (pipe(child_ready_pipe) < 0 || pipe(go_pipe) < 0)) { | ||
366 | perror("failed to create pipes"); | ||
367 | return -1; | ||
368 | } | ||
369 | |||
370 | if (forks) { | 363 | if (forks) { |
371 | if ((child_pid = fork()) < 0) | 364 | if (perf_evlist__prepare_workload(evsel_list, &target, argv, |
372 | perror("failed to fork"); | 365 | false, false) < 0) { |
373 | 366 | perror("failed to prepare workload"); | |
374 | if (!child_pid) { | 367 | return -1; |
375 | close(child_ready_pipe[0]); | ||
376 | close(go_pipe[1]); | ||
377 | fcntl(go_pipe[0], F_SETFD, FD_CLOEXEC); | ||
378 | |||
379 | /* | ||
380 | * Do a dummy execvp to get the PLT entry resolved, | ||
381 | * so we avoid the resolver overhead on the real | ||
382 | * execvp call. | ||
383 | */ | ||
384 | execvp("", (char **)argv); | ||
385 | |||
386 | /* | ||
387 | * Tell the parent we're ready to go | ||
388 | */ | ||
389 | close(child_ready_pipe[1]); | ||
390 | |||
391 | /* | ||
392 | * Wait until the parent tells us to go. | ||
393 | */ | ||
394 | if (read(go_pipe[0], &buf, 1) == -1) | ||
395 | perror("unable to read pipe"); | ||
396 | |||
397 | execvp(argv[0], (char **)argv); | ||
398 | |||
399 | perror(argv[0]); | ||
400 | exit(-1); | ||
401 | } | 368 | } |
402 | |||
403 | if (perf_target__none(&target)) | ||
404 | evsel_list->threads->map[0] = child_pid; | ||
405 | |||
406 | /* | ||
407 | * Wait for the child to be ready to exec. | ||
408 | */ | ||
409 | close(child_ready_pipe[1]); | ||
410 | close(go_pipe[0]); | ||
411 | if (read(child_ready_pipe[0], &buf, 1) == -1) | ||
412 | perror("unable to read pipe"); | ||
413 | close(child_ready_pipe[0]); | ||
414 | } | 369 | } |
415 | 370 | ||
416 | if (group) | 371 | if (group) |
@@ -457,7 +412,8 @@ static int __run_perf_stat(int argc __maybe_unused, const char **argv) | |||
457 | clock_gettime(CLOCK_MONOTONIC, &ref_time); | 412 | clock_gettime(CLOCK_MONOTONIC, &ref_time); |
458 | 413 | ||
459 | if (forks) { | 414 | if (forks) { |
460 | close(go_pipe[1]); | 415 | perf_evlist__start_workload(evsel_list); |
416 | |||
461 | if (interval) { | 417 | if (interval) { |
462 | while (!waitpid(child_pid, &status, WNOHANG)) { | 418 | while (!waitpid(child_pid, &status, WNOHANG)) { |
463 | nanosleep(&ts, NULL); | 419 | nanosleep(&ts, NULL); |