[PATCH] perf tests: Make leader sampling test work without branch event

James Clark posted 1 patch 6 days, 19 hours ago
tools/perf/tests/shell/record.sh | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
[PATCH] perf tests: Make leader sampling test work without branch event
Posted by James Clark 6 days, 19 hours ago
Arm a57 only has speculative branch events so this test fails there. The
test doesn't depend on branch instructions so change it to instructions
which is pretty much guaranteed to be everywhere. The
test_branch_counter() test above already tests for the existence of the
branches event and skips if its not present.

Signed-off-by: James Clark <james.clark@linaro.org>
---
 tools/perf/tests/shell/record.sh | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/tools/perf/tests/shell/record.sh b/tools/perf/tests/shell/record.sh
index 85d512f5a126..0fc7a909ae9b 100755
--- a/tools/perf/tests/shell/record.sh
+++ b/tools/perf/tests/shell/record.sh
@@ -231,7 +231,8 @@ test_cgroup() {
 
 test_leader_sampling() {
   echo "Basic leader sampling test"
-  if ! perf record -o "${perfdata}" -e "{branches,branches}:Su" perf test -w brstack 2> /dev/null
+  if ! perf record -o "${perfdata}" -e "{instructions,instructions}:Su" -- \
+    perf test -w brstack 2> /dev/null
   then
     echo "Leader sampling [Failed record]"
     err=1
@@ -241,16 +242,16 @@ test_leader_sampling() {
   perf script -i "${perfdata}" > $script_output
   while IFS= read -r line
   do
-    # Check if the two branches counts are equal in each record
-    branches=$(echo $line | awk '{for(i=1;i<=NF;i++) if($i=="branches:") print $(i-1)}')
-    if [ $(($index%2)) -ne 0 ] && [ ${branches}x != ${prev_branches}x ]
+    # Check if the two instruction counts are equal in each record
+    instructions=$(echo $line | awk '{for(i=1;i<=NF;i++) if($i=="instructions:") print $(i-1)}')
+    if [ $(($index%2)) -ne 0 ] && [ ${instructions}x != ${prev_instructions}x ]
     then
-      echo "Leader sampling [Failed inconsistent branches count]"
+      echo "Leader sampling [Failed inconsistent instructions count]"
       err=1
       return
     fi
     index=$(($index+1))
-    prev_branches=$branches
+    prev_instructions=$instructions
   done < $script_output
   echo "Basic leader sampling test [Success]"
 }
-- 
2.34.1
Re: [PATCH] perf tests: Make leader sampling test work without branch event
Posted by Ian Rogers 6 days, 16 hours ago
On Fri, Nov 15, 2024 at 8:16 AM James Clark <james.clark@linaro.org> wrote:
>
> Arm a57 only has speculative branch events so this test fails there. The
> test doesn't depend on branch instructions so change it to instructions
> which is pretty much guaranteed to be everywhere. The
> test_branch_counter() test above already tests for the existence of the
> branches event and skips if its not present.
>
> Signed-off-by: James Clark <james.clark@linaro.org>

Reviewed-by: Ian Rogers <irogers@google.com>

Thanks,
Ian

> ---
>  tools/perf/tests/shell/record.sh | 13 +++++++------
>  1 file changed, 7 insertions(+), 6 deletions(-)
>
> diff --git a/tools/perf/tests/shell/record.sh b/tools/perf/tests/shell/record.sh
> index 85d512f5a126..0fc7a909ae9b 100755
> --- a/tools/perf/tests/shell/record.sh
> +++ b/tools/perf/tests/shell/record.sh
> @@ -231,7 +231,8 @@ test_cgroup() {
>
>  test_leader_sampling() {
>    echo "Basic leader sampling test"
> -  if ! perf record -o "${perfdata}" -e "{branches,branches}:Su" perf test -w brstack 2> /dev/null
> +  if ! perf record -o "${perfdata}" -e "{instructions,instructions}:Su" -- \
> +    perf test -w brstack 2> /dev/null
>    then
>      echo "Leader sampling [Failed record]"
>      err=1
> @@ -241,16 +242,16 @@ test_leader_sampling() {
>    perf script -i "${perfdata}" > $script_output
>    while IFS= read -r line
>    do
> -    # Check if the two branches counts are equal in each record
> -    branches=$(echo $line | awk '{for(i=1;i<=NF;i++) if($i=="branches:") print $(i-1)}')
> -    if [ $(($index%2)) -ne 0 ] && [ ${branches}x != ${prev_branches}x ]
> +    # Check if the two instruction counts are equal in each record
> +    instructions=$(echo $line | awk '{for(i=1;i<=NF;i++) if($i=="instructions:") print $(i-1)}')
> +    if [ $(($index%2)) -ne 0 ] && [ ${instructions}x != ${prev_instructions}x ]
>      then
> -      echo "Leader sampling [Failed inconsistent branches count]"
> +      echo "Leader sampling [Failed inconsistent instructions count]"
>        err=1
>        return
>      fi
>      index=$(($index+1))
> -    prev_branches=$branches
> +    prev_instructions=$instructions
>    done < $script_output
>    echo "Basic leader sampling test [Success]"
>  }
> --
> 2.34.1
>
Re: [PATCH] perf tests: Make leader sampling test work without branch event
Posted by Arnaldo Carvalho de Melo 5 days, 15 hours ago
On Fri, Nov 15, 2024 at 10:54:43AM -0800, Ian Rogers wrote:
> On Fri, Nov 15, 2024 at 8:16 AM James Clark <james.clark@linaro.org> wrote:
> >
> > Arm a57 only has speculative branch events so this test fails there. The
> > test doesn't depend on branch instructions so change it to instructions
> > which is pretty much guaranteed to be everywhere. The
> > test_branch_counter() test above already tests for the existence of the
> > branches event and skips if its not present.
> >
> > Signed-off-by: James Clark <james.clark@linaro.org>
> 
> Reviewed-by: Ian Rogers <irogers@google.com>

Thanks, applied to perf-tools-next,

- Arnaldo