2009-12-29 09:05:08

by tip-bot for Liming Wang

[permalink] [raw]
Subject: [PATCH 1/3] 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 <[email protected]>
---
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


2009-12-29 09:05:06

by tip-bot for Liming Wang

[permalink] [raw]
Subject: [PATCH 2/3] perf tools: remove pid option from stat

pid option is useless for stat, so remove it.

Signed-off-by: Liming Wang <[email protected]>
---
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

2009-12-29 09:04:50

by tip-bot for Liming Wang

[permalink] [raw]
Subject: [PATCH 3/3] perf probe: change CONFIG_KPROBE_TRACER to CONFIG_KPROBE_EVENT

make the config name consistent

Signed-off-by: Liming Wang <[email protected]>
---
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

2009-12-29 12:05:19

by Peter Zijlstra

[permalink] [raw]
Subject: Re: [PATCH 2/3] perf tools: remove pid option from stat

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 <[email protected]>
> ---
> 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,

2009-12-30 02:33:36

by Masami Hiramatsu

[permalink] [raw]
Subject: Re: [PATCH 3/3] perf probe: change CONFIG_KPROBE_TRACER to CONFIG_KPROBE_EVENT

Liming Wang wrote:
> make the config name consistent
>
> Signed-off-by: Liming Wang <[email protected]>

Ah, right. Thank you!

Acked-by: Masami Hiramatsu <[email protected]>

> ---
> 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: [email protected]

2009-12-30 09:23:54

by Ingo Molnar

[permalink] [raw]
Subject: Re: [PATCH 2/3] perf tools: remove pid option from stat


* Peter Zijlstra <[email protected]> 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

2009-12-30 09:44:53

by tip-bot for Liming Wang

[permalink] [raw]
Subject: Re: [PATCH 2/3] perf tools: remove pid option from stat

Ingo Molnar wrote:
> * Peter Zijlstra <[email protected]> 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
>

2009-12-30 12:23:45

by tip-bot for Liming Wang

[permalink] [raw]
Subject: [tip:perf/core] perf tools: Unify event type description

Commit-ID: 41bdcb23dab22bf27361c5f2d89fe895d8904915
Gitweb: http://git.kernel.org/tip/41bdcb23dab22bf27361c5f2d89fe895d8904915
Author: Liming Wang <[email protected]>
AuthorDate: Tue, 29 Dec 2009 16:37:07 +0800
Committer: Ingo Molnar <[email protected]>
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 <[email protected]>
Cc: Frederic Weisbecker <[email protected]>
Cc: Masami Hiramatsu <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Peter Zijlstra <[email protected]>
LKML-Reference: <[email protected]>
Signed-off-by: Ingo Molnar <[email protected]>
---
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();

2009-12-30 12:24:09

by tip-bot for Liming Wang

[permalink] [raw]
Subject: [tip:perf/core] perf probe: Change CONFIG_KPROBE_TRACER to CONFIG_KPROBE_EVENT

Commit-ID: 63bbd5e2d539c9290b229c832f62d42aac23db94
Gitweb: http://git.kernel.org/tip/63bbd5e2d539c9290b229c832f62d42aac23db94
Author: Liming Wang <[email protected]>
AuthorDate: Tue, 29 Dec 2009 16:37:09 +0800
Committer: Ingo Molnar <[email protected]>
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 <[email protected]>
Acked-by: Masami Hiramatsu <[email protected]>
Cc: Frederic Weisbecker <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Peter Zijlstra <[email protected]>
LKML-Reference: <[email protected]>
Signed-off-by: Ingo Molnar <[email protected]>
---
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));

2009-12-31 08:32:59

by tip-bot for Liming Wang

[permalink] [raw]
Subject: [PATCH 1/1] 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 <[email protected]>
---
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

2010-01-13 10:32:29

by tip-bot for Liming Wang

[permalink] [raw]
Subject: [tip:perf/core] perf tools: Fix --pid option for stat

Commit-ID: 60666c630bdb33983a894b050b588b663f38f368
Gitweb: http://git.kernel.org/tip/60666c630bdb33983a894b050b588b663f38f368
Author: Liming Wang <[email protected]>
AuthorDate: Thu, 31 Dec 2009 16:05:50 +0800
Committer: Ingo Molnar <[email protected]>
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 <[email protected]>
Cc: Frederic Weisbecker <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Peter Zijlstra <[email protected]>
LKML-Reference: <[email protected]>
Signed-off-by: Ingo Molnar <[email protected]>
---
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);