From: Andi Kleen <andi@firstfloor.org>
To: linux-kernel@vger.kernel.org
Cc: acme@ghostprotocols.net, dsahern@gmail.com, namhyung@kernel.org,
Andi Kleen <ak@linux.intel.com>
Subject: [PATCH] perf, tools: Stop perf stat -p when profiled process exits v3
Date: Thu, 13 Sep 2012 08:58:51 -0700 [thread overview]
Message-ID: <1347551931-7666-1-git-send-email-andi@firstfloor.org> (raw)
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
next reply other threads:[~2012-09-13 15:58 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-13 15:58 Andi Kleen [this message]
2012-09-13 20:23 ` [PATCH] perf, tools: Stop perf stat -p when profiled process exits v3 David Ahern
2012-09-13 20:26 ` Andi Kleen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1347551931-7666-1-git-send-email-andi@firstfloor.org \
--to=andi@firstfloor.org \
--cc=acme@ghostprotocols.net \
--cc=ak@linux.intel.com \
--cc=dsahern@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=namhyung@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.