perf, tools: Stop perf stat -p when profiled process exits
PATCH 1/1 perf, tools: Stop perf stat -p when profiled process exits
From: Andi Kleen <[email protected]>
When counting a process with perf stat -p check if the process died and exit collection if yes.
Signed-off-by Andi Kleen <[email protected]>
--- tools/perf/builtin-stat.c | 9 ++++++++- 1 files changed, 8 insertions(+), 1 deletions(-)
tools/perf/builtin-stat.c +8 -1
@@ -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 ();
Signature · 1 line
1.7.7.6
Namhyung Kim
maintainerHi Andi,
Quoted 4 lines · Andi Kleen
From: Andi Kleen <[email protected]>
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.
Quoted 12 lines
Signed-off-by Andi Kleen <[email protected]>--- tools/perf/builtin-stat.c | 9 ++++++++- 1 files changed, 8 insertions(+), 1 deletions(-)tools/perf/builtin-stat.c +0
-0@@ -536,7 +536,14 @@ static int run_perf_stat(int argc __used, const char **argv)if (WIFSIGNALED (status))
tools/perf/builtin-stat.c static int run_perf_stat(int argc __used, const char **argv) · line 545
Quoted 10 lines
tools/perf/builtin-stat.c +7
-1psignal (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