perf stat: Factor out event handling loop into dispatch_events()
Consolidate event dispatching loops for fork, attach and system wide monitoring use cases into common dispatch_events() function. Signed-off-by: Alexey Budankov <alexey.budankov@linux.intel.com> Acked-by: Jiri Olsa <jolsa@redhat.com> Acked-by: Namhyung Kim <namhyung@kernel.org> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Andi Kleen <ak@linux.intel.com> Cc: Peter Zijlstra <peterz@infradead.org> Link: http://lore.kernel.org/lkml/8a900bd5-200a-9b0f-7154-80a2343bfd1a@linux.intel.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
parent
b0ce0c8df4
commit
987b823813
@ -550,6 +550,27 @@ static bool is_target_alive(struct target *_target,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int dispatch_events(bool forks, int timeout, int interval, int *times, struct timespec *ts)
|
||||||
|
{
|
||||||
|
int child_exited = 0, status = 0;
|
||||||
|
|
||||||
|
while (!done) {
|
||||||
|
if (forks)
|
||||||
|
child_exited = waitpid(child_pid, &status, WNOHANG);
|
||||||
|
else
|
||||||
|
child_exited = !is_target_alive(&target, evsel_list->core.threads) ? 1 : 0;
|
||||||
|
|
||||||
|
if (child_exited)
|
||||||
|
break;
|
||||||
|
|
||||||
|
nanosleep(ts, NULL);
|
||||||
|
if (timeout || handle_interval(interval, times))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
enum counter_recovery {
|
enum counter_recovery {
|
||||||
COUNTER_SKIP,
|
COUNTER_SKIP,
|
||||||
COUNTER_RETRY,
|
COUNTER_RETRY,
|
||||||
@ -789,13 +810,8 @@ try_again_reset:
|
|||||||
perf_evlist__start_workload(evsel_list);
|
perf_evlist__start_workload(evsel_list);
|
||||||
enable_counters();
|
enable_counters();
|
||||||
|
|
||||||
if (interval || timeout) {
|
if (interval || timeout)
|
||||||
while (!waitpid(child_pid, &status, WNOHANG)) {
|
status = dispatch_events(forks, timeout, interval, ×, &ts);
|
||||||
nanosleep(&ts, NULL);
|
|
||||||
if (timeout || handle_interval(interval, ×))
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (child_pid != -1) {
|
if (child_pid != -1) {
|
||||||
if (timeout)
|
if (timeout)
|
||||||
kill(child_pid, SIGTERM);
|
kill(child_pid, SIGTERM);
|
||||||
@ -812,11 +828,7 @@ try_again_reset:
|
|||||||
psignal(WTERMSIG(status), argv[0]);
|
psignal(WTERMSIG(status), argv[0]);
|
||||||
} else {
|
} else {
|
||||||
enable_counters();
|
enable_counters();
|
||||||
while (!done && is_target_alive(&target, evsel_list->core.threads)) {
|
status = dispatch_events(forks, timeout, interval, ×, &ts);
|
||||||
nanosleep(&ts, NULL);
|
|
||||||
if (timeout || handle_interval(interval, ×))
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
disable_counters();
|
disable_counters();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user