diff options
author | Jiri Olsa <jolsa@kernel.org> | 2018-10-22 05:30:15 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2018-10-22 11:37:52 -0400 |
commit | cbb5df7e96070f1f728ff7885443646ebba703d4 (patch) | |
tree | 3ec4f0e283f73e5ceb043b77daf7e0a64928a4ef | |
parent | a937c6658b8e77e1f65cde2be9970811752121bb (diff) |
perf stat: Poll for monitored tasks being alive
Adding the check for tasks we monitor via -p/-t options, and finish stat
if there's no longer task to monitor.
Requested-by: Stephane Eranian <eranian@google.com>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Link: http://lkml.kernel.org/r/20181022093015.9106-1-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r-- | tools/perf/builtin-stat.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index b86aba1c8028..d1028d7755bb 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c | |||
@@ -409,6 +409,28 @@ static struct perf_evsel *perf_evsel__reset_weak_group(struct perf_evsel *evsel) | |||
409 | return leader; | 409 | return leader; |
410 | } | 410 | } |
411 | 411 | ||
412 | static bool is_target_alive(struct target *_target, | ||
413 | struct thread_map *threads) | ||
414 | { | ||
415 | struct stat st; | ||
416 | int i; | ||
417 | |||
418 | if (!target__has_task(_target)) | ||
419 | return true; | ||
420 | |||
421 | for (i = 0; i < threads->nr; i++) { | ||
422 | char path[PATH_MAX]; | ||
423 | |||
424 | scnprintf(path, PATH_MAX, "%s/%d", procfs__mountpoint(), | ||
425 | threads->map[i].pid); | ||
426 | |||
427 | if (!stat(path, &st)) | ||
428 | return true; | ||
429 | } | ||
430 | |||
431 | return false; | ||
432 | } | ||
433 | |||
412 | static int __run_perf_stat(int argc, const char **argv, int run_idx) | 434 | static int __run_perf_stat(int argc, const char **argv, int run_idx) |
413 | { | 435 | { |
414 | int interval = stat_config.interval; | 436 | int interval = stat_config.interval; |
@@ -579,6 +601,8 @@ try_again: | |||
579 | enable_counters(); | 601 | enable_counters(); |
580 | while (!done) { | 602 | while (!done) { |
581 | nanosleep(&ts, NULL); | 603 | nanosleep(&ts, NULL); |
604 | if (!is_target_alive(&target, evsel_list->threads)) | ||
605 | break; | ||
582 | if (timeout) | 606 | if (timeout) |
583 | break; | 607 | break; |
584 | if (interval) { | 608 | if (interval) { |