public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] perf stat: Enable counters when collecting process-wide or system-wide data
@ 2010-03-18 14:36 Arnaldo Carvalho de Melo
  2010-03-18 14:36 ` [PATCH 2/3] perf record: Enable counters only when kernel is execing subcommand Arnaldo Carvalho de Melo
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Arnaldo Carvalho de Melo @ 2010-03-18 14:36 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, Zhang, Yanmin, Avi Kivity, Peter Zijlstra,
	Sheng Yang, Marcelo Tosatti, Joerg Roedel, Jes Sorensen,
	Gleb Natapov, Zachary Amsden, zhiteng.huang,
	Arnaldo Carvalho de Melo

From: Zhang, Yanmin <yanmin_zhang@linux.intel.com>

Command 'perf stat' doesn't enable counters when collecting an existing
(by -p) process or a system-wide statistics. Fix the issue.

Change the condition of fork/exec subcommand. If there is a subcommand
parameter, perf always fork/exec it. The usage example is:

 # perf stat -a sleep 10

So this command could collect statistics for 10 seconds precisely. User
still could stop it by CTRL+C. Without the new capability, user could
only use CTRL+C to stop it without precise time clock.

Another issue is 'perf stat -a' consumes 100% time of a full single
logical cpu. It has a bad impact on running workload. Fix it by adding a
sleep(1) in the while(!done) loop in function run_perf_stat.

Signed-off-by: Zhang Yanmin <yanmin_zhang@linux.intel.com>
Cc: Avi Kivity <avi@redhat.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Sheng Yang <sheng@linux.intel.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Joerg Roedel <joro@8bytes.org>
Cc: Jes Sorensen <Jes.Sorensen@redhat.com>
Cc: Gleb Natapov <gleb@redhat.com>
Cc: Zachary Amsden <zamsden@redhat.com>
Cc: <zhiteng.huang@intel.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/builtin-stat.c |   24 ++++++++++++++----------
 1 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 95db31c..5f41244 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -159,8 +159,10 @@ static void create_perf_stat_counter(int counter, int pid)
 		}
 	} else {
 		attr->inherit	     = inherit;
-		attr->disabled	     = 1;
-		attr->enable_on_exec = 1;
+		if (target_pid == -1) {
+			attr->disabled = 1;
+			attr->enable_on_exec = 1;
+		}
 
 		fd[0][counter] = sys_perf_event_open(attr, pid, -1, -1, 0);
 		if (fd[0][counter] < 0 && verbose)
@@ -251,9 +253,9 @@ static int run_perf_stat(int argc __used, const char **argv)
 	unsigned long long t0, t1;
 	int status = 0;
 	int counter;
-	int pid = target_pid;
+	int pid;
 	int child_ready_pipe[2], go_pipe[2];
-	const bool forks = (target_pid == -1 && argc > 0);
+	const bool forks = (argc > 0);
 	char buf;
 
 	if (!system_wide)
@@ -265,10 +267,10 @@ static int run_perf_stat(int argc __used, const char **argv)
 	}
 
 	if (forks) {
-		if ((pid = fork()) < 0)
+		if ((child_pid = fork()) < 0)
 			perror("failed to fork");
 
-		if (!pid) {
+		if (!child_pid) {
 			close(child_ready_pipe[0]);
 			close(go_pipe[1]);
 			fcntl(go_pipe[0], F_SETFD, FD_CLOEXEC);
@@ -297,8 +299,6 @@ static int run_perf_stat(int argc __used, const char **argv)
 			exit(-1);
 		}
 
-		child_pid = pid;
-
 		/*
 		 * Wait for the child to be ready to exec.
 		 */
@@ -309,6 +309,10 @@ static int run_perf_stat(int argc __used, const char **argv)
 		close(child_ready_pipe[0]);
 	}
 
+	if (target_pid == -1)
+		pid = child_pid;
+	else
+		pid = target_pid;
 	for (counter = 0; counter < nr_counters; counter++)
 		create_perf_stat_counter(counter, pid);
 
@@ -321,7 +325,7 @@ static int run_perf_stat(int argc __used, const char **argv)
 		close(go_pipe[1]);
 		wait(&status);
 	} else {
-		while(!done);
+		while(!done) sleep(1);
 	}
 
 	t1 = rdclock();
@@ -459,7 +463,7 @@ static volatile int signr = -1;
 
 static void skip_signal(int signo)
 {
-	if(target_pid != -1)
+	if(child_pid == -1)
 		done = 1;
 
 	signr = signo;
-- 
1.6.2.5


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

end of thread, other threads:[~2010-03-18 17:37 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-03-18 14:36 [PATCH 1/3] perf stat: Enable counters when collecting process-wide or system-wide data Arnaldo Carvalho de Melo
2010-03-18 14:36 ` [PATCH 2/3] perf record: Enable counters only when kernel is execing subcommand Arnaldo Carvalho de Melo
2010-03-18 17:36   ` [tip:perf/core] " tip-bot for Zhang, Yanmin
2010-03-18 14:36 ` [PATCH 3/3] perf events: Change perf parameter --pid to process-wide collection instead of thread-wide Arnaldo Carvalho de Melo
2010-03-18 17:37   ` [tip:perf/core] " tip-bot for Zhang, Yanmin
2010-03-18 17:36 ` [tip:perf/core] perf stat: Enable counters when collecting process-wide or system-wide data tip-bot for Zhang, Yanmin

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