* [PATCH 1/3] perf tools: unify event type description
@ 2009-12-29 8:37 Liming Wang
2009-12-29 8:37 ` [PATCH 2/3] perf tools: remove pid option from stat Liming Wang
2009-12-30 12:22 ` [tip:perf/core] perf tools: Unify event type description tip-bot for Liming Wang
0 siblings, 2 replies; 11+ messages in thread
From: Liming Wang @ 2009-12-29 8:37 UTC (permalink / raw)
To: Ingo Molnar
Cc: Frederic Weisbecker, Masami Hiramatsu, Paul Mackerras,
Thomas Gleixner, Peter Zijlstra, linux-kernel, Liming Wang
make event type description to a unified array and
the array index consistent to perf_type_id.
Signed-off-by: Liming Wang <liming.wang@windriver.com>
---
tools/perf/util/parse-events.c | 19 ++++++++++---------
1 files changed, 10 insertions(+), 9 deletions(-)
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index e5bc0fb..dc585a8 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -835,11 +835,12 @@ int parse_filter(const struct option *opt __used, const char *str,
}
static const char * const event_type_descriptors[] = {
- "",
"Hardware event",
"Software event",
"Tracepoint event",
"Hardware cache event",
+ "Raw hardware event descriptor",
+ "Hardware breakpoint",
};
/*
@@ -872,7 +873,7 @@ static void print_tracepoint_events(void)
snprintf(evt_path, MAXPATHLEN, "%s:%s",
sys_dirent.d_name, evt_dirent.d_name);
printf(" %-42s [%s]\n", evt_path,
- event_type_descriptors[PERF_TYPE_TRACEPOINT+1]);
+ event_type_descriptors[PERF_TYPE_TRACEPOINT]);
}
closedir(evt_dir);
}
@@ -892,9 +893,7 @@ void print_events(void)
printf("List of pre-defined events (to be used in -e):\n");
for (i = 0; i < ARRAY_SIZE(event_symbols); i++, syms++) {
- type = syms->type + 1;
- if (type >= ARRAY_SIZE(event_type_descriptors))
- type = 0;
+ type = syms->type;
if (type != prev_type)
printf("\n");
@@ -919,17 +918,19 @@ void print_events(void)
for (i = 0; i < PERF_COUNT_HW_CACHE_RESULT_MAX; i++) {
printf(" %-42s [%s]\n",
event_cache_name(type, op, i),
- event_type_descriptors[4]);
+ event_type_descriptors[PERF_TYPE_HW_CACHE]);
}
}
}
printf("\n");
- printf(" %-42s [raw hardware event descriptor]\n",
- "rNNN");
+ printf(" %-42s [%s]\n",
+ "rNNN", event_type_descriptors[PERF_TYPE_RAW]);
printf("\n");
- printf(" %-42s [hardware breakpoint]\n", "mem:<addr>[:access]");
+ printf(" %-42s [%s]\n",
+ "mem:<addr>[:access]",
+ event_type_descriptors[PERF_TYPE_BREAKPOINT]);
printf("\n");
print_tracepoint_events();
--
1.6.0.3
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 2/3] perf tools: remove pid option from stat
2009-12-29 8:37 [PATCH 1/3] perf tools: unify event type description Liming Wang
@ 2009-12-29 8:37 ` Liming Wang
2009-12-29 8:37 ` [PATCH 3/3] perf probe: change CONFIG_KPROBE_TRACER to CONFIG_KPROBE_EVENT Liming Wang
2009-12-29 12:04 ` [PATCH 2/3] perf tools: remove pid option from stat Peter Zijlstra
2009-12-30 12:22 ` [tip:perf/core] perf tools: Unify event type description tip-bot for Liming Wang
1 sibling, 2 replies; 11+ messages in thread
From: Liming Wang @ 2009-12-29 8:37 UTC (permalink / raw)
To: Ingo Molnar
Cc: Frederic Weisbecker, Masami Hiramatsu, Paul Mackerras,
Thomas Gleixner, Peter Zijlstra, linux-kernel, Liming Wang
pid option is useless for stat, so remove it.
Signed-off-by: Liming Wang <liming.wang@windriver.com>
---
tools/perf/builtin-stat.c | 3 ---
1 files changed, 0 insertions(+), 3 deletions(-)
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index c70d720..e3b31a3 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -71,7 +71,6 @@ static int run_idx = 0;
static int run_count = 1;
static int inherit = 1;
static int scale = 1;
-static pid_t target_pid = -1;
static pid_t child_pid = -1;
static int null_run = 0;
@@ -471,8 +470,6 @@ static const struct option options[] = {
parse_events),
OPT_BOOLEAN('i', "inherit", &inherit,
"child tasks inherit counters"),
- OPT_INTEGER('p', "pid", &target_pid,
- "stat events on existing pid"),
OPT_BOOLEAN('a', "all-cpus", &system_wide,
"system-wide collection from all CPUs"),
OPT_BOOLEAN('c', "scale", &scale,
--
1.6.0.3
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 3/3] perf probe: change CONFIG_KPROBE_TRACER to CONFIG_KPROBE_EVENT
2009-12-29 8:37 ` [PATCH 2/3] perf tools: remove pid option from stat Liming Wang
@ 2009-12-29 8:37 ` Liming Wang
2009-12-30 2:32 ` Masami Hiramatsu
2009-12-30 12:23 ` [tip:perf/core] perf probe: Change " tip-bot for Liming Wang
2009-12-29 12:04 ` [PATCH 2/3] perf tools: remove pid option from stat Peter Zijlstra
1 sibling, 2 replies; 11+ messages in thread
From: Liming Wang @ 2009-12-29 8:37 UTC (permalink / raw)
To: Ingo Molnar
Cc: Frederic Weisbecker, Masami Hiramatsu, Paul Mackerras,
Thomas Gleixner, Peter Zijlstra, linux-kernel, Liming Wang
make the config name consistent
Signed-off-by: Liming Wang <liming.wang@windriver.com>
---
tools/perf/util/probe-event.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index 29465d4..8e532d9 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -368,7 +368,7 @@ static int open_kprobe_events(int flags, int mode)
if (ret < 0) {
if (errno == ENOENT)
die("kprobe_events file does not exist -"
- " please rebuild with CONFIG_KPROBE_TRACER.");
+ " please rebuild with CONFIG_KPROBE_EVENT.");
else
die("Could not open kprobe_events file: %s",
strerror(errno));
--
1.6.0.3
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH 2/3] perf tools: remove pid option from stat
2009-12-29 8:37 ` [PATCH 2/3] perf tools: remove pid option from stat Liming Wang
2009-12-29 8:37 ` [PATCH 3/3] perf probe: change CONFIG_KPROBE_TRACER to CONFIG_KPROBE_EVENT Liming Wang
@ 2009-12-29 12:04 ` Peter Zijlstra
2009-12-30 9:23 ` Ingo Molnar
1 sibling, 1 reply; 11+ messages in thread
From: Peter Zijlstra @ 2009-12-29 12:04 UTC (permalink / raw)
To: Liming Wang
Cc: Ingo Molnar, Frederic Weisbecker, Masami Hiramatsu,
Paul Mackerras, Thomas Gleixner, linux-kernel
On Tue, 2009-12-29 at 16:37 +0800, Liming Wang wrote:
> pid option is useless for stat, so remove it.
Hmm, it shouldn't be.. and instead of removing it I would suggesting
fixing this.
> Signed-off-by: Liming Wang <liming.wang@windriver.com>
> ---
> tools/perf/builtin-stat.c | 3 ---
> 1 files changed, 0 insertions(+), 3 deletions(-)
>
> diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
> index c70d720..e3b31a3 100644
> --- a/tools/perf/builtin-stat.c
> +++ b/tools/perf/builtin-stat.c
> @@ -71,7 +71,6 @@ static int run_idx = 0;
> static int run_count = 1;
> static int inherit = 1;
> static int scale = 1;
> -static pid_t target_pid = -1;
> static pid_t child_pid = -1;
> static int null_run = 0;
>
> @@ -471,8 +470,6 @@ static const struct option options[] = {
> parse_events),
> OPT_BOOLEAN('i', "inherit", &inherit,
> "child tasks inherit counters"),
> - OPT_INTEGER('p', "pid", &target_pid,
> - "stat events on existing pid"),
> OPT_BOOLEAN('a', "all-cpus", &system_wide,
> "system-wide collection from all CPUs"),
> OPT_BOOLEAN('c', "scale", &scale,
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 3/3] perf probe: change CONFIG_KPROBE_TRACER to CONFIG_KPROBE_EVENT
2009-12-29 8:37 ` [PATCH 3/3] perf probe: change CONFIG_KPROBE_TRACER to CONFIG_KPROBE_EVENT Liming Wang
@ 2009-12-30 2:32 ` Masami Hiramatsu
2009-12-30 12:23 ` [tip:perf/core] perf probe: Change " tip-bot for Liming Wang
1 sibling, 0 replies; 11+ messages in thread
From: Masami Hiramatsu @ 2009-12-30 2:32 UTC (permalink / raw)
To: Liming Wang
Cc: Ingo Molnar, Frederic Weisbecker, Paul Mackerras,
Thomas Gleixner, Peter Zijlstra, linux-kernel
Liming Wang wrote:
> make the config name consistent
>
> Signed-off-by: Liming Wang <liming.wang@windriver.com>
Ah, right. Thank you!
Acked-by: Masami Hiramatsu <mhiramat@redhat.com>
> ---
> tools/perf/util/probe-event.c | 2 +-
> 1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
> index 29465d4..8e532d9 100644
> --- a/tools/perf/util/probe-event.c
> +++ b/tools/perf/util/probe-event.c
> @@ -368,7 +368,7 @@ static int open_kprobe_events(int flags, int mode)
> if (ret < 0) {
> if (errno == ENOENT)
> die("kprobe_events file does not exist -"
> - " please rebuild with CONFIG_KPROBE_TRACER.");
> + " please rebuild with CONFIG_KPROBE_EVENT.");
> else
> die("Could not open kprobe_events file: %s",
> strerror(errno));
--
Masami Hiramatsu
Software Engineer
Hitachi Computer Products (America), Inc.
Software Solutions Division
e-mail: mhiramat@redhat.com
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 2/3] perf tools: remove pid option from stat
2009-12-29 12:04 ` [PATCH 2/3] perf tools: remove pid option from stat Peter Zijlstra
@ 2009-12-30 9:23 ` Ingo Molnar
2009-12-30 9:29 ` Wang Liming
2009-12-31 8:05 ` [PATCH 1/1] perf tools: fix pid option for stat Liming Wang
0 siblings, 2 replies; 11+ messages in thread
From: Ingo Molnar @ 2009-12-30 9:23 UTC (permalink / raw)
To: Peter Zijlstra
Cc: Liming Wang, Frederic Weisbecker, Masami Hiramatsu,
Paul Mackerras, Thomas Gleixner, linux-kernel
* Peter Zijlstra <peterz@infradead.org> wrote:
> On Tue, 2009-12-29 at 16:37 +0800, Liming Wang wrote:
> > pid option is useless for stat, so remove it.
>
> Hmm, it shouldn't be.. and instead of removing it I would suggesting fixing
> this.
Yes. For exampe something like:
perf stat --repeat 10 --pid $(pidof firefox) sleep 1
Should show firefox's resource usage sampled over 10 seconds.
If this doesnt work it should be fixed. Plus i suspect we should allow:
perf stat --pid $(pidof firefox)
to run until Ctrl-C - like perf record allows.
Ingo
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 2/3] perf tools: remove pid option from stat
2009-12-30 9:23 ` Ingo Molnar
@ 2009-12-30 9:29 ` Wang Liming
2009-12-31 8:05 ` [PATCH 1/1] perf tools: fix pid option for stat Liming Wang
1 sibling, 0 replies; 11+ messages in thread
From: Wang Liming @ 2009-12-30 9:29 UTC (permalink / raw)
To: Ingo Molnar
Cc: Peter Zijlstra, Frederic Weisbecker, Masami Hiramatsu,
Paul Mackerras, Thomas Gleixner, linux-kernel
Ingo Molnar wrote:
> * Peter Zijlstra <peterz@infradead.org> wrote:
>
>> On Tue, 2009-12-29 at 16:37 +0800, Liming Wang wrote:
>>> pid option is useless for stat, so remove it.
>> Hmm, it shouldn't be.. and instead of removing it I would suggesting fixing
>> this.
>
> Yes. For exampe something like:
>
> perf stat --repeat 10 --pid $(pidof firefox) sleep 1
>
> Should show firefox's resource usage sampled over 10 seconds.
>
> If this doesnt work it should be fixed. Plus i suspect we should allow:
>
> perf stat --pid $(pidof firefox)
>
> to run until Ctrl-C - like perf record allows.
Yes, perf record works well with "--pid".
I think stat can borrow come code from record.
Please discard this patch.
Liming Wang
>
> Ingo
>
^ permalink raw reply [flat|nested] 11+ messages in thread
* [tip:perf/core] perf tools: Unify event type description
2009-12-29 8:37 [PATCH 1/3] perf tools: unify event type description Liming Wang
2009-12-29 8:37 ` [PATCH 2/3] perf tools: remove pid option from stat Liming Wang
@ 2009-12-30 12:22 ` tip-bot for Liming Wang
1 sibling, 0 replies; 11+ messages in thread
From: tip-bot for Liming Wang @ 2009-12-30 12:22 UTC (permalink / raw)
To: linux-tip-commits
Cc: linux-kernel, paulus, hpa, mingo, peterz, fweisbec, tglx,
liming.wang, mhiramat, mingo
Commit-ID: 41bdcb23dab22bf27361c5f2d89fe895d8904915
Gitweb: http://git.kernel.org/tip/41bdcb23dab22bf27361c5f2d89fe895d8904915
Author: Liming Wang <liming.wang@windriver.com>
AuthorDate: Tue, 29 Dec 2009 16:37:07 +0800
Committer: Ingo Molnar <mingo@elte.hu>
CommitDate: Wed, 30 Dec 2009 11:58:53 +0100
perf tools: Unify event type description
make event type description to a unified array and
the array index consistent to perf_type_id.
Signed-off-by: Liming Wang <liming.wang@windriver.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
LKML-Reference: <1262075829-16257-1-git-send-email-liming.wang@windriver.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
tools/perf/util/parse-events.c | 19 ++++++++++---------
1 files changed, 10 insertions(+), 9 deletions(-)
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index e5bc0fb..dc585a8 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -835,11 +835,12 @@ int parse_filter(const struct option *opt __used, const char *str,
}
static const char * const event_type_descriptors[] = {
- "",
"Hardware event",
"Software event",
"Tracepoint event",
"Hardware cache event",
+ "Raw hardware event descriptor",
+ "Hardware breakpoint",
};
/*
@@ -872,7 +873,7 @@ static void print_tracepoint_events(void)
snprintf(evt_path, MAXPATHLEN, "%s:%s",
sys_dirent.d_name, evt_dirent.d_name);
printf(" %-42s [%s]\n", evt_path,
- event_type_descriptors[PERF_TYPE_TRACEPOINT+1]);
+ event_type_descriptors[PERF_TYPE_TRACEPOINT]);
}
closedir(evt_dir);
}
@@ -892,9 +893,7 @@ void print_events(void)
printf("List of pre-defined events (to be used in -e):\n");
for (i = 0; i < ARRAY_SIZE(event_symbols); i++, syms++) {
- type = syms->type + 1;
- if (type >= ARRAY_SIZE(event_type_descriptors))
- type = 0;
+ type = syms->type;
if (type != prev_type)
printf("\n");
@@ -919,17 +918,19 @@ void print_events(void)
for (i = 0; i < PERF_COUNT_HW_CACHE_RESULT_MAX; i++) {
printf(" %-42s [%s]\n",
event_cache_name(type, op, i),
- event_type_descriptors[4]);
+ event_type_descriptors[PERF_TYPE_HW_CACHE]);
}
}
}
printf("\n");
- printf(" %-42s [raw hardware event descriptor]\n",
- "rNNN");
+ printf(" %-42s [%s]\n",
+ "rNNN", event_type_descriptors[PERF_TYPE_RAW]);
printf("\n");
- printf(" %-42s [hardware breakpoint]\n", "mem:<addr>[:access]");
+ printf(" %-42s [%s]\n",
+ "mem:<addr>[:access]",
+ event_type_descriptors[PERF_TYPE_BREAKPOINT]);
printf("\n");
print_tracepoint_events();
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [tip:perf/core] perf probe: Change CONFIG_KPROBE_TRACER to CONFIG_KPROBE_EVENT
2009-12-29 8:37 ` [PATCH 3/3] perf probe: change CONFIG_KPROBE_TRACER to CONFIG_KPROBE_EVENT Liming Wang
2009-12-30 2:32 ` Masami Hiramatsu
@ 2009-12-30 12:23 ` tip-bot for Liming Wang
1 sibling, 0 replies; 11+ messages in thread
From: tip-bot for Liming Wang @ 2009-12-30 12:23 UTC (permalink / raw)
To: linux-tip-commits
Cc: linux-kernel, paulus, hpa, mingo, peterz, fweisbec, tglx,
liming.wang, mhiramat, mingo
Commit-ID: 63bbd5e2d539c9290b229c832f62d42aac23db94
Gitweb: http://git.kernel.org/tip/63bbd5e2d539c9290b229c832f62d42aac23db94
Author: Liming Wang <liming.wang@windriver.com>
AuthorDate: Tue, 29 Dec 2009 16:37:09 +0800
Committer: Ingo Molnar <mingo@elte.hu>
CommitDate: Wed, 30 Dec 2009 11:59:34 +0100
perf probe: Change CONFIG_KPROBE_TRACER to CONFIG_KPROBE_EVENT
make the config name consistent
Signed-off-by: Liming Wang <liming.wang@windriver.com>
Acked-by: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
LKML-Reference: <1262075829-16257-3-git-send-email-liming.wang@windriver.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
tools/perf/util/probe-event.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index 29465d4..8e532d9 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -368,7 +368,7 @@ static int open_kprobe_events(int flags, int mode)
if (ret < 0) {
if (errno == ENOENT)
die("kprobe_events file does not exist -"
- " please rebuild with CONFIG_KPROBE_TRACER.");
+ " please rebuild with CONFIG_KPROBE_EVENT.");
else
die("Could not open kprobe_events file: %s",
strerror(errno));
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 1/1] perf tools: fix pid option for stat
2009-12-30 9:23 ` Ingo Molnar
2009-12-30 9:29 ` Wang Liming
@ 2009-12-31 8:05 ` Liming Wang
2010-01-13 10:31 ` [tip:perf/core] perf tools: Fix --pid " tip-bot for Liming Wang
1 sibling, 1 reply; 11+ messages in thread
From: Liming Wang @ 2009-12-31 8:05 UTC (permalink / raw)
To: Ingo Molnar
Cc: Frederic Weisbecker, Paul Mackerras, Thomas Gleixner,
Peter Zijlstra, linux-kernel, Liming Wang
current pid option doesn't work for perf stat. Change it to what
perf record --pid acts as.
Signed-off-by: Liming Wang <liming.wang@windriver.com>
---
tools/perf/builtin-stat.c | 106 ++++++++++++++++++++++++++-------------------
1 files changed, 61 insertions(+), 45 deletions(-)
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index c70d720..e8c85d5 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -44,6 +44,7 @@
#include "util/parse-events.h"
#include "util/event.h"
#include "util/debug.h"
+#include "util/header.h"
#include <sys/prctl.h>
#include <math.h>
@@ -79,6 +80,8 @@ static int fd[MAX_NR_CPUS][MAX_COUNTERS];
static int event_scaled[MAX_COUNTERS];
+static volatile int done = 0;
+
struct stats
{
double n, mean, M2;
@@ -247,61 +250,64 @@ static int run_perf_stat(int argc __used, const char **argv)
unsigned long long t0, t1;
int status = 0;
int counter;
- int pid;
+ int pid = target_pid;
int child_ready_pipe[2], go_pipe[2];
+ const bool forks = (target_pid == -1 && argc > 0);
char buf;
if (!system_wide)
nr_cpus = 1;
- if (pipe(child_ready_pipe) < 0 || pipe(go_pipe) < 0) {
+ if (forks && (pipe(child_ready_pipe) < 0 || pipe(go_pipe) < 0)) {
perror("failed to create pipes");
exit(1);
}
- if ((pid = fork()) < 0)
- perror("failed to fork");
+ if (forks) {
+ if ((pid = fork()) < 0)
+ perror("failed to fork");
+
+ if (!pid) {
+ close(child_ready_pipe[0]);
+ close(go_pipe[1]);
+ fcntl(go_pipe[0], F_SETFD, FD_CLOEXEC);
+
+ /*
+ * Do a dummy execvp to get the PLT entry resolved,
+ * so we avoid the resolver overhead on the real
+ * execvp call.
+ */
+ execvp("", (char **)argv);
+
+ /*
+ * Tell the parent we're ready to go
+ */
+ close(child_ready_pipe[1]);
+
+ /*
+ * Wait until the parent tells us to go.
+ */
+ if (read(go_pipe[0], &buf, 1) == -1)
+ perror("unable to read pipe");
+
+ execvp(argv[0], (char **)argv);
+
+ perror(argv[0]);
+ exit(-1);
+ }
- if (!pid) {
- close(child_ready_pipe[0]);
- close(go_pipe[1]);
- fcntl(go_pipe[0], F_SETFD, FD_CLOEXEC);
+ child_pid = pid;
/*
- * Do a dummy execvp to get the PLT entry resolved,
- * so we avoid the resolver overhead on the real
- * execvp call.
- */
- execvp("", (char **)argv);
-
- /*
- * Tell the parent we're ready to go
+ * Wait for the child to be ready to exec.
*/
close(child_ready_pipe[1]);
-
- /*
- * Wait until the parent tells us to go.
- */
- if (read(go_pipe[0], &buf, 1) == -1)
+ close(go_pipe[0]);
+ if (read(child_ready_pipe[0], &buf, 1) == -1)
perror("unable to read pipe");
-
- execvp(argv[0], (char **)argv);
-
- perror(argv[0]);
- exit(-1);
+ close(child_ready_pipe[0]);
}
- child_pid = pid;
-
- /*
- * Wait for the child to be ready to exec.
- */
- close(child_ready_pipe[1]);
- close(go_pipe[0]);
- if (read(child_ready_pipe[0], &buf, 1) == -1)
- perror("unable to read pipe");
- close(child_ready_pipe[0]);
-
for (counter = 0; counter < nr_counters; counter++)
create_perf_stat_counter(counter, pid);
@@ -310,8 +316,12 @@ static int run_perf_stat(int argc __used, const char **argv)
*/
t0 = rdclock();
- close(go_pipe[1]);
- wait(&status);
+ if (forks) {
+ close(go_pipe[1]);
+ wait(&status);
+ } else {
+ while(!done);
+ }
t1 = rdclock();
@@ -417,10 +427,13 @@ static void print_stat(int argc, const char **argv)
fflush(stdout);
fprintf(stderr, "\n");
- fprintf(stderr, " Performance counter stats for \'%s", argv[0]);
-
- for (i = 1; i < argc; i++)
- fprintf(stderr, " %s", argv[i]);
+ fprintf(stderr, " Performance counter stats for ");
+ if(target_pid == -1) {
+ fprintf(stderr, "\'%s", argv[0]);
+ for (i = 1; i < argc; i++)
+ fprintf(stderr, " %s", argv[i]);
+ }else
+ fprintf(stderr, "task pid \'%d", target_pid);
fprintf(stderr, "\'");
if (run_count > 1)
@@ -445,6 +458,9 @@ static volatile int signr = -1;
static void skip_signal(int signo)
{
+ if(target_pid != -1)
+ done = 1;
+
signr = signo;
}
@@ -461,7 +477,7 @@ static void sig_atexit(void)
}
static const char * const stat_usage[] = {
- "perf stat [<options>] <command>",
+ "perf stat [<options>] [<command>]",
NULL
};
@@ -492,7 +508,7 @@ int cmd_stat(int argc, const char **argv, const char *prefix __used)
argc = parse_options(argc, argv, options, stat_usage,
PARSE_OPT_STOP_AT_NON_OPTION);
- if (!argc)
+ if (!argc && target_pid == -1)
usage_with_options(stat_usage, options);
if (run_count <= 0)
usage_with_options(stat_usage, options);
--
1.6.0.3
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [tip:perf/core] perf tools: Fix --pid option for stat
2009-12-31 8:05 ` [PATCH 1/1] perf tools: fix pid option for stat Liming Wang
@ 2010-01-13 10:31 ` tip-bot for Liming Wang
0 siblings, 0 replies; 11+ messages in thread
From: tip-bot for Liming Wang @ 2010-01-13 10:31 UTC (permalink / raw)
To: linux-tip-commits
Cc: linux-kernel, paulus, hpa, mingo, peterz, fweisbec, tglx,
liming.wang, mingo
Commit-ID: 60666c630bdb33983a894b050b588b663f38f368
Gitweb: http://git.kernel.org/tip/60666c630bdb33983a894b050b588b663f38f368
Author: Liming Wang <liming.wang@windriver.com>
AuthorDate: Thu, 31 Dec 2009 16:05:50 +0800
Committer: Ingo Molnar <mingo@elte.hu>
CommitDate: Wed, 13 Jan 2010 10:09:08 +0100
perf tools: Fix --pid option for stat
current pid option doesn't work for perf stat. Change it to what
perf record --pid acts as.
Signed-off-by: Liming Wang <liming.wang@windriver.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
LKML-Reference: <1262246750-2191-1-git-send-email-liming.wang@windriver.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
tools/perf/builtin-stat.c | 106 ++++++++++++++++++++++++++-------------------
1 files changed, 61 insertions(+), 45 deletions(-)
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index c70d720..e8c85d5 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -44,6 +44,7 @@
#include "util/parse-events.h"
#include "util/event.h"
#include "util/debug.h"
+#include "util/header.h"
#include <sys/prctl.h>
#include <math.h>
@@ -79,6 +80,8 @@ static int fd[MAX_NR_CPUS][MAX_COUNTERS];
static int event_scaled[MAX_COUNTERS];
+static volatile int done = 0;
+
struct stats
{
double n, mean, M2;
@@ -247,61 +250,64 @@ static int run_perf_stat(int argc __used, const char **argv)
unsigned long long t0, t1;
int status = 0;
int counter;
- int pid;
+ int pid = target_pid;
int child_ready_pipe[2], go_pipe[2];
+ const bool forks = (target_pid == -1 && argc > 0);
char buf;
if (!system_wide)
nr_cpus = 1;
- if (pipe(child_ready_pipe) < 0 || pipe(go_pipe) < 0) {
+ if (forks && (pipe(child_ready_pipe) < 0 || pipe(go_pipe) < 0)) {
perror("failed to create pipes");
exit(1);
}
- if ((pid = fork()) < 0)
- perror("failed to fork");
+ if (forks) {
+ if ((pid = fork()) < 0)
+ perror("failed to fork");
+
+ if (!pid) {
+ close(child_ready_pipe[0]);
+ close(go_pipe[1]);
+ fcntl(go_pipe[0], F_SETFD, FD_CLOEXEC);
+
+ /*
+ * Do a dummy execvp to get the PLT entry resolved,
+ * so we avoid the resolver overhead on the real
+ * execvp call.
+ */
+ execvp("", (char **)argv);
+
+ /*
+ * Tell the parent we're ready to go
+ */
+ close(child_ready_pipe[1]);
+
+ /*
+ * Wait until the parent tells us to go.
+ */
+ if (read(go_pipe[0], &buf, 1) == -1)
+ perror("unable to read pipe");
+
+ execvp(argv[0], (char **)argv);
+
+ perror(argv[0]);
+ exit(-1);
+ }
- if (!pid) {
- close(child_ready_pipe[0]);
- close(go_pipe[1]);
- fcntl(go_pipe[0], F_SETFD, FD_CLOEXEC);
+ child_pid = pid;
/*
- * Do a dummy execvp to get the PLT entry resolved,
- * so we avoid the resolver overhead on the real
- * execvp call.
- */
- execvp("", (char **)argv);
-
- /*
- * Tell the parent we're ready to go
+ * Wait for the child to be ready to exec.
*/
close(child_ready_pipe[1]);
-
- /*
- * Wait until the parent tells us to go.
- */
- if (read(go_pipe[0], &buf, 1) == -1)
+ close(go_pipe[0]);
+ if (read(child_ready_pipe[0], &buf, 1) == -1)
perror("unable to read pipe");
-
- execvp(argv[0], (char **)argv);
-
- perror(argv[0]);
- exit(-1);
+ close(child_ready_pipe[0]);
}
- child_pid = pid;
-
- /*
- * Wait for the child to be ready to exec.
- */
- close(child_ready_pipe[1]);
- close(go_pipe[0]);
- if (read(child_ready_pipe[0], &buf, 1) == -1)
- perror("unable to read pipe");
- close(child_ready_pipe[0]);
-
for (counter = 0; counter < nr_counters; counter++)
create_perf_stat_counter(counter, pid);
@@ -310,8 +316,12 @@ static int run_perf_stat(int argc __used, const char **argv)
*/
t0 = rdclock();
- close(go_pipe[1]);
- wait(&status);
+ if (forks) {
+ close(go_pipe[1]);
+ wait(&status);
+ } else {
+ while(!done);
+ }
t1 = rdclock();
@@ -417,10 +427,13 @@ static void print_stat(int argc, const char **argv)
fflush(stdout);
fprintf(stderr, "\n");
- fprintf(stderr, " Performance counter stats for \'%s", argv[0]);
-
- for (i = 1; i < argc; i++)
- fprintf(stderr, " %s", argv[i]);
+ fprintf(stderr, " Performance counter stats for ");
+ if(target_pid == -1) {
+ fprintf(stderr, "\'%s", argv[0]);
+ for (i = 1; i < argc; i++)
+ fprintf(stderr, " %s", argv[i]);
+ }else
+ fprintf(stderr, "task pid \'%d", target_pid);
fprintf(stderr, "\'");
if (run_count > 1)
@@ -445,6 +458,9 @@ static volatile int signr = -1;
static void skip_signal(int signo)
{
+ if(target_pid != -1)
+ done = 1;
+
signr = signo;
}
@@ -461,7 +477,7 @@ static void sig_atexit(void)
}
static const char * const stat_usage[] = {
- "perf stat [<options>] <command>",
+ "perf stat [<options>] [<command>]",
NULL
};
@@ -492,7 +508,7 @@ int cmd_stat(int argc, const char **argv, const char *prefix __used)
argc = parse_options(argc, argv, options, stat_usage,
PARSE_OPT_STOP_AT_NON_OPTION);
- if (!argc)
+ if (!argc && target_pid == -1)
usage_with_options(stat_usage, options);
if (run_count <= 0)
usage_with_options(stat_usage, options);
^ permalink raw reply related [flat|nested] 11+ messages in thread
end of thread, other threads:[~2010-01-13 10:32 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-12-29 8:37 [PATCH 1/3] perf tools: unify event type description Liming Wang
2009-12-29 8:37 ` [PATCH 2/3] perf tools: remove pid option from stat Liming Wang
2009-12-29 8:37 ` [PATCH 3/3] perf probe: change CONFIG_KPROBE_TRACER to CONFIG_KPROBE_EVENT Liming Wang
2009-12-30 2:32 ` Masami Hiramatsu
2009-12-30 12:23 ` [tip:perf/core] perf probe: Change " tip-bot for Liming Wang
2009-12-29 12:04 ` [PATCH 2/3] perf tools: remove pid option from stat Peter Zijlstra
2009-12-30 9:23 ` Ingo Molnar
2009-12-30 9:29 ` Wang Liming
2009-12-31 8:05 ` [PATCH 1/1] perf tools: fix pid option for stat Liming Wang
2010-01-13 10:31 ` [tip:perf/core] perf tools: Fix --pid " tip-bot for Liming Wang
2009-12-30 12:22 ` [tip:perf/core] perf tools: Unify event type description tip-bot for Liming Wang
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).