Re: [PATCH v1 2/2] perf record: Support weak groups

2018-10-02 Thread Jiri Olsa
On Mon, Oct 01, 2018 at 12:59:27PM -0700, Andi Kleen wrote:
> From: Andi Kleen 
> 
> Implement a weak group fallback for perf record, similar to the existing perf 
> stat support.
> This allows to use groups that might be longer than the available counters 
> without
> failing.
> 
> Before:
> 
> $ perf record  -e 
> '{cycles,cache-misses,cache-references,cpu_clk_unhalted.thread,cycles,cycles,cycles}'
>  -a sleep 1
> Error:
> The sys_perf_event_open() syscall returned with 22 (Invalid argument) for 
> event (cycles).
> /bin/dmesg | grep -i perf may provide additional information.
> 
> After:
> 
> $ ./perf record  -e 
> '{cycles,cache-misses,cache-references,cpu_clk_unhalted.thread,cycles,cycles,cycles}:W'
>  -a sleep 1
> WARNING: No sample_id_all support, falling back to unordered processing
> [ perf record: Woken up 3 times to write data ]
> [ perf record: Captured and wrote 8.136 MB perf.data (134069 samples) ]
> 
> Signed-off-by: Andi Kleen 

Acked-by: Jiri Olsa 

thanks,
jirka


Re: [PATCH v1 2/2] perf record: Support weak groups

2018-10-02 Thread Jiri Olsa
On Mon, Oct 01, 2018 at 12:59:27PM -0700, Andi Kleen wrote:
> From: Andi Kleen 
> 
> Implement a weak group fallback for perf record, similar to the existing perf 
> stat support.
> This allows to use groups that might be longer than the available counters 
> without
> failing.
> 
> Before:
> 
> $ perf record  -e 
> '{cycles,cache-misses,cache-references,cpu_clk_unhalted.thread,cycles,cycles,cycles}'
>  -a sleep 1
> Error:
> The sys_perf_event_open() syscall returned with 22 (Invalid argument) for 
> event (cycles).
> /bin/dmesg | grep -i perf may provide additional information.
> 
> After:
> 
> $ ./perf record  -e 
> '{cycles,cache-misses,cache-references,cpu_clk_unhalted.thread,cycles,cycles,cycles}:W'
>  -a sleep 1
> WARNING: No sample_id_all support, falling back to unordered processing
> [ perf record: Woken up 3 times to write data ]
> [ perf record: Captured and wrote 8.136 MB perf.data (134069 samples) ]
> 
> Signed-off-by: Andi Kleen 

Acked-by: Jiri Olsa 

thanks,
jirka


[PATCH v1 2/2] perf record: Support weak groups

2018-10-01 Thread Andi Kleen
From: Andi Kleen 

Implement a weak group fallback for perf record, similar to the existing perf 
stat support.
This allows to use groups that might be longer than the available counters 
without
failing.

Before:

$ perf record  -e 
'{cycles,cache-misses,cache-references,cpu_clk_unhalted.thread,cycles,cycles,cycles}'
 -a sleep 1
Error:
The sys_perf_event_open() syscall returned with 22 (Invalid argument) for event 
(cycles).
/bin/dmesg | grep -i perf may provide additional information.

After:

$ ./perf record  -e 
'{cycles,cache-misses,cache-references,cpu_clk_unhalted.thread,cycles,cycles,cycles}:W'
 -a sleep 1
WARNING: No sample_id_all support, falling back to unordered processing
[ perf record: Woken up 3 times to write data ]
[ perf record: Captured and wrote 8.136 MB perf.data (134069 samples) ]

Signed-off-by: Andi Kleen 
---
 tools/perf/Documentation/perf-list.txt | 1 -
 tools/perf/builtin-record.c| 7 ++-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/tools/perf/Documentation/perf-list.txt 
b/tools/perf/Documentation/perf-list.txt
index 11300dbe35c5..c50ed1177984 100644
--- a/tools/perf/Documentation/perf-list.txt
+++ b/tools/perf/Documentation/perf-list.txt
@@ -49,7 +49,6 @@ counted. The following modifiers exist:
  S - read sample value (PERF_SAMPLE_READ)
  D - pin the event to the PMU
  W - group is weak and will fallback to non-group if not schedulable,
- only supported in 'perf stat' for now.
 
 The 'p' modifier can be used for specifying how precise the instruction
 address should be. The 'p' modifier can be specified multiple times:
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 22ebeb92ac51..504d89d67b3a 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -388,7 +388,12 @@ static int record__open(struct record *rec)
ui__warning("%s\n", msg);
goto try_again;
}
-
+   if ((errno == EINVAL || errno == EBADF) &&
+   pos->leader != pos &&
+   pos->weak_group) {
+   pos = perf_evlist__reset_weak_group(evlist, 
pos);
+   goto try_again;
+   }
rc = -errno;
perf_evsel__open_strerror(pos, >target,
  errno, msg, sizeof(msg));
-- 
2.17.1



[PATCH v1 2/2] perf record: Support weak groups

2018-10-01 Thread Andi Kleen
From: Andi Kleen 

Implement a weak group fallback for perf record, similar to the existing perf 
stat support.
This allows to use groups that might be longer than the available counters 
without
failing.

Before:

$ perf record  -e 
'{cycles,cache-misses,cache-references,cpu_clk_unhalted.thread,cycles,cycles,cycles}'
 -a sleep 1
Error:
The sys_perf_event_open() syscall returned with 22 (Invalid argument) for event 
(cycles).
/bin/dmesg | grep -i perf may provide additional information.

After:

$ ./perf record  -e 
'{cycles,cache-misses,cache-references,cpu_clk_unhalted.thread,cycles,cycles,cycles}:W'
 -a sleep 1
WARNING: No sample_id_all support, falling back to unordered processing
[ perf record: Woken up 3 times to write data ]
[ perf record: Captured and wrote 8.136 MB perf.data (134069 samples) ]

Signed-off-by: Andi Kleen 
---
 tools/perf/Documentation/perf-list.txt | 1 -
 tools/perf/builtin-record.c| 7 ++-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/tools/perf/Documentation/perf-list.txt 
b/tools/perf/Documentation/perf-list.txt
index 11300dbe35c5..c50ed1177984 100644
--- a/tools/perf/Documentation/perf-list.txt
+++ b/tools/perf/Documentation/perf-list.txt
@@ -49,7 +49,6 @@ counted. The following modifiers exist:
  S - read sample value (PERF_SAMPLE_READ)
  D - pin the event to the PMU
  W - group is weak and will fallback to non-group if not schedulable,
- only supported in 'perf stat' for now.
 
 The 'p' modifier can be used for specifying how precise the instruction
 address should be. The 'p' modifier can be specified multiple times:
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 22ebeb92ac51..504d89d67b3a 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -388,7 +388,12 @@ static int record__open(struct record *rec)
ui__warning("%s\n", msg);
goto try_again;
}
-
+   if ((errno == EINVAL || errno == EBADF) &&
+   pos->leader != pos &&
+   pos->weak_group) {
+   pos = perf_evlist__reset_weak_group(evlist, 
pos);
+   goto try_again;
+   }
rc = -errno;
perf_evsel__open_strerror(pos, >target,
  errno, msg, sizeof(msg));
-- 
2.17.1