2012-02-13 07:12:25

by Namhyung Kim

[permalink] [raw]
Subject: [PATCH 10/11] perf stat: Fix event grouping on forked task

When event group is enabled for forked task (i.e. no target task was
specified) all events were disabled and marked ->enable_on_exec.
However they are not counted at all since only group leader will be
enabled on exec actually. So the result looked like below:

$ perf stat --group sleep 1

Performance counter stats for 'sleep 1':

0.530891 task-clock # 0.001 CPUs utilized
<not counted> context-switches
<not counted> CPU-migrations
<not counted> page-faults
<not counted> cycles
<not supported> stalled-cycles-frontend
<not supported> stalled-cycles-backend
<not counted> instructions
<not counted> branches
<not counted> branch-misses

1.001140177 seconds time elapsed

Fix it by disabling group leader only.

Signed-off-by: Namhyung Kim <[email protected]>
---
tools/perf/builtin-stat.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index be2667236bea..2a592e52eaee 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -297,7 +297,7 @@ static int create_perf_stat_counter(struct perf_evsel *evsel,
if (maps.system_wide)
return perf_evsel__open_per_cpu(evsel, evsel_list->cpus,
group, group_fd);
- if (no_target_task(&maps)) {
+ if (no_target_task(&maps) && (!group || evsel == first)) {
attr->disabled = 1;
attr->enable_on_exec = 1;
}
--
1.7.9


2012-02-13 18:41:29

by Arnaldo Carvalho de Melo

[permalink] [raw]
Subject: Re: [PATCH 10/11] perf stat: Fix event grouping on forked task

Em Mon, Feb 13, 2012 at 04:27:42PM +0900, Namhyung Kim escreveu:
> When event group is enabled for forked task (i.e. no target task was
> specified) all events were disabled and marked ->enable_on_exec.
> However they are not counted at all since only group leader will be
> enabled on exec actually. So the result looked like below:
>
> $ perf stat --group sleep 1

This one is a bugfix and would be better if we have it isolated from
this patchset, not needing the cleanups, so that we can send it to
perf/urgent and stable@

> Performance counter stats for 'sleep 1':
>
> 0.530891 task-clock # 0.001 CPUs utilized
> <not counted> context-switches
> <not counted> CPU-migrations
> <not counted> page-faults
> <not counted> cycles
> <not supported> stalled-cycles-frontend
> <not supported> stalled-cycles-backend
> <not counted> instructions
> <not counted> branches
> <not counted> branch-misses
>
> 1.001140177 seconds time elapsed
>
> Fix it by disabling group leader only.
>
> Signed-off-by: Namhyung Kim <[email protected]>
> ---
> tools/perf/builtin-stat.c | 2 +-
> 1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
> index be2667236bea..2a592e52eaee 100644
> --- a/tools/perf/builtin-stat.c
> +++ b/tools/perf/builtin-stat.c
> @@ -297,7 +297,7 @@ static int create_perf_stat_counter(struct perf_evsel *evsel,
> if (maps.system_wide)
> return perf_evsel__open_per_cpu(evsel, evsel_list->cpus,
> group, group_fd);
> - if (no_target_task(&maps)) {
> + if (no_target_task(&maps) && (!group || evsel == first)) {
> attr->disabled = 1;
> attr->enable_on_exec = 1;
> }
> --
> 1.7.9

2012-02-14 01:04:08

by Namhyung Kim

[permalink] [raw]
Subject: [PATCH] perf stat: Fix event grouping on forked task

When event group is enabled for forked task (i.e. no target task was
specified) all events were disabled and marked ->enable_on_exec.
However they are not counted at all since only group leader will be
enabled on exec actually. So the result looked like below:

$ ./perf stat --group -- sleep 1

Performance counter stats for 'sleep 1':

0.554926 task-clock # 0.001 CPUs utilized
<not counted> context-switches
<not counted> CPU-migrations
<not counted> page-faults
<not counted> cycles
<not supported> stalled-cycles-frontend
<not supported> stalled-cycles-backend
<not counted> instructions
<not counted> branches
<not counted> branch-misses

1.001228093 seconds time elapsed

Fix it by disabling group leader only.

Signed-off-by: Namhyung Kim <[email protected]>
---
tools/perf/builtin-stat.c | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index d14b37ad7638..b2fa61e539c0 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -296,7 +296,8 @@ static int create_perf_stat_counter(struct perf_evsel *evsel,
if (system_wide)
return perf_evsel__open_per_cpu(evsel, evsel_list->cpus,
group, group_fd);
- if (target_pid == -1 && target_tid == -1) {
+ if (target_pid == -1 && target_tid == -1 &&
+ (!group || evsel == first)) {
attr->disabled = 1;
attr->enable_on_exec = 1;
}
--
1.7.9