linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] perf, tools: Stop perf stat -p when profiled process exits v2
@ 2012-09-12 14:40 Andi Kleen
  2012-09-12 14:54 ` David Ahern
  0 siblings, 1 reply; 3+ messages in thread
From: Andi Kleen @ 2012-09-12 14:40 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.

v2: Add more checks, handle non -p again. Handle /proc not there.
Signed-off-by: Andi Kleen <ak@linux.intel.com>
---
 tools/perf/builtin-stat.c |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)

diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 861f0ae..2e5b4b3 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -536,7 +536,15 @@ 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];
+		if (target.pid && access("/proc", X_OK) == 0)
+			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] 3+ messages in thread

* Re: [PATCH] perf, tools: Stop perf stat -p when profiled process exits v2
  2012-09-12 14:40 [PATCH] perf, tools: Stop perf stat -p when profiled process exits v2 Andi Kleen
@ 2012-09-12 14:54 ` David Ahern
  2012-09-13 15:52   ` Andi Kleen
  0 siblings, 1 reply; 3+ messages in thread
From: David Ahern @ 2012-09-12 14:54 UTC (permalink / raw)
  To: Andi Kleen; +Cc: acme, linux-kernel, Andi Kleen

On 9/12/12 8:40 AM, Andi Kleen wrote:
> -		while(!done) sleep(1);
> +		char piddir[40];
> +		if (target.pid && access("/proc", X_OK) == 0)
> +			snprintf(piddir, sizeof piddir, "/proc/%d", atoi(target.pid));

else path has piddir not set. Also as Namyhung pointed out target.pid 
can have multiple pids in it, so this fails if a user specified -p 
pid1,pid2 -- it will only check if the first process died.

Perhaps a more generic perf_target__is_alive function is needed that can 
check if the given tid(s) or pid(s) have terminated.

David

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

* Re: [PATCH] perf, tools: Stop perf stat -p when profiled process exits v2
  2012-09-12 14:54 ` David Ahern
@ 2012-09-13 15:52   ` Andi Kleen
  0 siblings, 0 replies; 3+ messages in thread
From: Andi Kleen @ 2012-09-13 15:52 UTC (permalink / raw)
  To: David Ahern; +Cc: Andi Kleen, acme, linux-kernel

On Wed, Sep 12, 2012 at 08:54:18AM -0600, David Ahern wrote:
> On 9/12/12 8:40 AM, Andi Kleen wrote:
> >-		while(!done) sleep(1);
> >+		char piddir[40];
> >+		if (target.pid && access("/proc", X_OK) == 0)
> >+			snprintf(piddir, sizeof piddir, "/proc/%d", atoi(target.pid));
> 
> else path has piddir not set. 

It doesn't need to be set for else?

> target.pid can have multiple pids in it, so this fails if a user
> specified -p pid1,pid2 -- it will only check if the first process
> died.

Ok.   I suppose can make it simply not check for that case.

-Andi

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

end of thread, other threads:[~2012-09-13 15:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-09-12 14:40 [PATCH] perf, tools: Stop perf stat -p when profiled process exits v2 Andi Kleen
2012-09-12 14:54 ` David Ahern
2012-09-13 15:52   ` Andi Kleen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).