public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] perf, tools: Stop perf stat -p when profiled process exits
@ 2012-09-12  6:09 Andi Kleen
  2012-09-12  8:30 ` Namhyung Kim
  0 siblings, 1 reply; 2+ messages in thread
From: Andi Kleen @ 2012-09-12  6:09 UTC (permalink / raw)
  To: acme; +Cc: linux-kernel, 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.

Signed-off-by: Andi Kleen <ak@linux.intel.com>
---
 tools/perf/builtin-stat.c |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)

diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 861f0ae..1313bb5 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -536,7 +536,14 @@ 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];
+		snprintf(piddir, sizeof piddir, "/proc/%d", atoi(target.pid));
+
+		while(!done) {
+			sleep(1);
+			if (target.pid && access(piddir, X_OK) < 0 && errno == ENOENT)
+				break;
+		}
 	}
 
 	t1 = rdclock();
-- 
1.7.7.6


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] perf, tools: Stop perf stat -p when profiled process exits
  2012-09-12  6:09 [PATCH] perf, tools: Stop perf stat -p when profiled process exits Andi Kleen
@ 2012-09-12  8:30 ` Namhyung Kim
  0 siblings, 0 replies; 2+ messages in thread
From: Namhyung Kim @ 2012-09-12  8:30 UTC (permalink / raw)
  To: Andi Kleen; +Cc: acme, linux-kernel, Andi Kleen

Hi Andi,

On Tue, 11 Sep 2012 23:09:04 -0700, 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.

I guess we need something similar for perf record as well.

>
> Signed-off-by: Andi Kleen <ak@linux.intel.com>
> ---
>  tools/perf/builtin-stat.c |    9 ++++++++-
>  1 files changed, 8 insertions(+), 1 deletions(-)
>
> diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
> index 861f0ae..1313bb5 100644
> --- a/tools/perf/builtin-stat.c
> +++ b/tools/perf/builtin-stat.c
> @@ -536,7 +536,14 @@ 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];
> +		snprintf(piddir, sizeof piddir, "/proc/%d", atoi(target.pid));
> +
> +		while(!done) {
> +			sleep(1);
> +			if (target.pid && access(piddir, X_OK) < 0 && errno == ENOENT)
> +				break;

The target.pid might have multiple pid's - e.g. perf stat -p 1234,5678

Thanks,
Namhyung

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-09-12  8:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-09-12  6:09 [PATCH] perf, tools: Stop perf stat -p when profiled process exits Andi Kleen
2012-09-12  8:30 ` Namhyung Kim

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox