* [PATCH] perf, tools: Stop perf stat -p when profiled process exits v3
@ 2012-09-13 15:58 Andi Kleen
2012-09-13 20:23 ` David Ahern
0 siblings, 1 reply; 3+ messages in thread
From: Andi Kleen @ 2012-09-13 15:58 UTC (permalink / raw)
To: linux-kernel; +Cc: acme, dsahern, namhyung, Andi Kleen
From: Andi Kleen <ak@linux.intel.com>
When counting a process with perf stat -p check if the process died
and exit collection if yes.
v2: Add more checks, handle non -p again. Handle /proc not there.
v3: Handle multi pid case. Fix non /proc error path
Signed-off-by: Andi Kleen <ak@linux.intel.com>
---
tools/perf/builtin-stat.c | 14 +++++++++++++-
1 files changed, 13 insertions(+), 1 deletions(-)
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 861f0ae..b5e7df2 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -536,7 +536,19 @@ static int run_perf_stat(int argc __used, const char **argv)
if (WIFSIGNALED(status))
psignal(WTERMSIG(status), argv[0]);
} else {
- while(!done) sleep(1);
+ char piddir[40];
+ int check_proc = target.pid &&
+ access("/proc", X_OK) == 0 &&
+ !strchr(target.pid, ',');
+ if (check_proc)
+ snprintf(piddir, sizeof piddir, "/proc/%d",
+ atoi(target.pid));
+ while(!done) {
+ sleep(1);
+ if (check_proc && access(piddir, X_OK) < 0 &&
+ errno == ENOENT)
+ break;
+ }
}
t1 = rdclock();
--
1.7.7.6
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] perf, tools: Stop perf stat -p when profiled process exits v3
2012-09-13 15:58 [PATCH] perf, tools: Stop perf stat -p when profiled process exits v3 Andi Kleen
@ 2012-09-13 20:23 ` David Ahern
2012-09-13 20:26 ` Andi Kleen
0 siblings, 1 reply; 3+ messages in thread
From: David Ahern @ 2012-09-13 20:23 UTC (permalink / raw)
To: Andi Kleen; +Cc: linux-kernel, acme, namhyung, Andi Kleen
On 9/13/12 9:58 AM, Andi Kleen wrote:
> From: Andi Kleen <ak@linux.intel.com>
>
> When counting a process with perf stat -p check if the process died
> and exit collection if yes.
>
> v2: Add more checks, handle non -p again. Handle /proc not there.
> v3: Handle multi pid case. Fix non /proc error path
> Signed-off-by: Andi Kleen <ak@linux.intel.com>
> ---
> tools/perf/builtin-stat.c | 14 +++++++++++++-
> 1 files changed, 13 insertions(+), 1 deletions(-)
>
> diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
> index 861f0ae..b5e7df2 100644
> --- a/tools/perf/builtin-stat.c
> +++ b/tools/perf/builtin-stat.c
> @@ -536,7 +536,19 @@ static int run_perf_stat(int argc __used, const char **argv)
> if (WIFSIGNALED(status))
> psignal(WTERMSIG(status), argv[0]);
> } else {
> - while(!done) sleep(1);
> + char piddir[40];
> + int check_proc = target.pid &&
> + access("/proc", X_OK) == 0 &&
> + !strchr(target.pid, ',');
> + if (check_proc)
> + snprintf(piddir, sizeof piddir, "/proc/%d",
> + atoi(target.pid));
> + while(!done) {
> + sleep(1);
> + if (check_proc && access(piddir, X_OK) < 0 &&
> + errno == ENOENT)
> + break;
> + }
> }
I still think this is the wrong approach. A more complete solution would
monitor all of the targets given by the user. e.g.,
1. create a perf_target__parse_pid - all it needs to do is:
struct strlist *slist = strlist__new(false, pid_str);
and save that into the target struct. That line is currently done in
thread_map.c, thread_map__new_by_pid_str() and
thread_map__new_by_tid_str. Those functions can be altered to take the
slist instead of the string.
2. create a perf_target__is_alive that runs through each entry in the
slist (strlist__for_each(pos, slist)) and checks that it still exists.
As long as 1 target is alive it returns true. If no pid or tid is
specified it always returns true.
The is_alive function can be used by perf-top, perf-stat and perf-record
to know that its target has died so it can stop monitoring.
David
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] perf, tools: Stop perf stat -p when profiled process exits v3
2012-09-13 20:23 ` David Ahern
@ 2012-09-13 20:26 ` Andi Kleen
0 siblings, 0 replies; 3+ messages in thread
From: Andi Kleen @ 2012-09-13 20:26 UTC (permalink / raw)
To: David Ahern; +Cc: Andi Kleen, linux-kernel, acme, namhyung, Andi Kleen
> The is_alive function can be used by perf-top, perf-stat and perf-record
> to know that its target has died so it can stop monitoring.
Sorry that's to complicated and overengineered for me.
My simple patch works for me at least. It's not solving world hunger,
but it wasn't intended to do that.
-Andi
--
ak@linux.intel.com -- Speaking for myself only.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-09-13 20:26 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-09-13 15:58 [PATCH] perf, tools: Stop perf stat -p when profiled process exits v3 Andi Kleen
2012-09-13 20:23 ` David Ahern
2012-09-13 20:26 ` Andi Kleen
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.