[PATCH 4/4] perf tests: Add leader sampling test in record tests

Dapeng Mi posted 4 patches 1 year, 5 months ago
[PATCH 4/4] perf tests: Add leader sampling test in record tests
Posted by Dapeng Mi 1 year, 5 months ago
Add leader sampling test to validate event counts are captured into
record and the count value is consistent.

Suggested-by: Kan Liang <kan.liang@linux.intel.com>
Signed-off-by: Dapeng Mi <dapeng1.mi@linux.intel.com>
---
 tools/perf/tests/shell/record.sh | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/tools/perf/tests/shell/record.sh b/tools/perf/tests/shell/record.sh
index 3d1a7759a7b2..8e3e66780fed 100755
--- a/tools/perf/tests/shell/record.sh
+++ b/tools/perf/tests/shell/record.sh
@@ -17,6 +17,7 @@ skip_test_missing_symbol ${testsym}
 
 err=0
 perfdata=$(mktemp /tmp/__perf_test.perf.data.XXXXX)
+script_output=$(mktemp /tmp/__perf_test.perf.data.XXXXX.script)
 testprog="perf test -w thloop"
 cpu_pmu_dir="/sys/bus/event_source/devices/cpu*"
 br_cntr_file="/caps/branch_counter_nr"
@@ -190,11 +191,38 @@ test_branch_counter() {
   echo "Basic branch counter test [Success]"
 }
 
+test_leader_sampling() {
+  echo "Basic leader sampling test"
+  if ! perf record -o "${perfdata}" -e "{branches,branches}:Su" perf test -w brstack 2> /dev/null
+  then
+    echo "Leader sampling [Failed record]"
+    err=1
+    return
+  fi
+  index=0
+  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 ]
+    then
+      echo "Leader sampling [Failed inconsistent branches count]"
+      err=1
+      return
+    fi
+    index=$(($index+1))
+    prev_branches=$branches
+  done < $script_output
+  echo "Basic leader sampling test [Success]"
+}
+
 test_per_thread
 test_register_capture
 test_system_wide
 test_workload
 test_branch_counter
+test_leader_sampling
 
 cleanup
 exit $err
-- 
2.40.1
Re: [PATCH 4/4] perf tests: Add leader sampling test in record tests
Posted by Liang, Kan 1 year, 5 months ago

On 2024-07-02 6:40 p.m., Dapeng Mi wrote:
> Add leader sampling test to validate event counts are captured into
> record and the count value is consistent.
> 
> Suggested-by: Kan Liang <kan.liang@linux.intel.com>
> Signed-off-by: Dapeng Mi <dapeng1.mi@linux.intel.com>
> ---
>  tools/perf/tests/shell/record.sh | 28 ++++++++++++++++++++++++++++
>  1 file changed, 28 insertions(+)
> 
> diff --git a/tools/perf/tests/shell/record.sh b/tools/perf/tests/shell/record.sh
> index 3d1a7759a7b2..8e3e66780fed 100755
> --- a/tools/perf/tests/shell/record.sh
> +++ b/tools/perf/tests/shell/record.sh
> @@ -17,6 +17,7 @@ skip_test_missing_symbol ${testsym}
>  
>  err=0
>  perfdata=$(mktemp /tmp/__perf_test.perf.data.XXXXX)
> +script_output=$(mktemp /tmp/__perf_test.perf.data.XXXXX.script)
>  testprog="perf test -w thloop"
>  cpu_pmu_dir="/sys/bus/event_source/devices/cpu*"
>  br_cntr_file="/caps/branch_counter_nr"
> @@ -190,11 +191,38 @@ test_branch_counter() {
>    echo "Basic branch counter test [Success]"
>  }
>  
> +test_leader_sampling() {
> +  echo "Basic leader sampling test"
> +  if ! perf record -o "${perfdata}" -e "{branches,branches}:Su" perf test -w brstack 2> /dev/null

I think we still need a case to verify the topdown fix you did in the
patch set.
Since the topdown is platform specific, you may want to skip it on the
platform which doesn't support perf metrics. For example, check if the
slots event exists in the event folder.

Thanks,
Kan
> +  then
> +    echo "Leader sampling [Failed record]"
> +    err=1
> +    return
> +  fi
> +  index=0
> +  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 ]
> +    then
> +      echo "Leader sampling [Failed inconsistent branches count]"
> +      err=1
> +      return
> +    fi
> +    index=$(($index+1))
> +    prev_branches=$branches
> +  done < $script_output
> +  echo "Basic leader sampling test [Success]"
> +}
> +
>  test_per_thread
>  test_register_capture
>  test_system_wide
>  test_workload
>  test_branch_counter
> +test_leader_sampling
>  
>  cleanup
>  exit $err
Re: [PATCH 4/4] perf tests: Add leader sampling test in record tests
Posted by Mi, Dapeng 1 year, 5 months ago
On 7/3/2024 2:07 AM, Liang, Kan wrote:
>
> On 2024-07-02 6:40 p.m., Dapeng Mi wrote:
>> Add leader sampling test to validate event counts are captured into
>> record and the count value is consistent.
>>
>> Suggested-by: Kan Liang <kan.liang@linux.intel.com>
>> Signed-off-by: Dapeng Mi <dapeng1.mi@linux.intel.com>
>> ---
>>  tools/perf/tests/shell/record.sh | 28 ++++++++++++++++++++++++++++
>>  1 file changed, 28 insertions(+)
>>
>> diff --git a/tools/perf/tests/shell/record.sh b/tools/perf/tests/shell/record.sh
>> index 3d1a7759a7b2..8e3e66780fed 100755
>> --- a/tools/perf/tests/shell/record.sh
>> +++ b/tools/perf/tests/shell/record.sh
>> @@ -17,6 +17,7 @@ skip_test_missing_symbol ${testsym}
>>  
>>  err=0
>>  perfdata=$(mktemp /tmp/__perf_test.perf.data.XXXXX)
>> +script_output=$(mktemp /tmp/__perf_test.perf.data.XXXXX.script)
>>  testprog="perf test -w thloop"
>>  cpu_pmu_dir="/sys/bus/event_source/devices/cpu*"
>>  br_cntr_file="/caps/branch_counter_nr"
>> @@ -190,11 +191,38 @@ test_branch_counter() {
>>    echo "Basic branch counter test [Success]"
>>  }
>>  
>> +test_leader_sampling() {
>> +  echo "Basic leader sampling test"
>> +  if ! perf record -o "${perfdata}" -e "{branches,branches}:Su" perf test -w brstack 2> /dev/null
> I think we still need a case to verify the topdown fix you did in the
> patch set.
> Since the topdown is platform specific, you may want to skip it on the
> platform which doesn't support perf metrics. For example, check if the
> slots event exists in the event folder.

Yeah, I would look how to design a test case to verify the topdown case.


>
> Thanks,
> Kan
>> +  then
>> +    echo "Leader sampling [Failed record]"
>> +    err=1
>> +    return
>> +  fi
>> +  index=0
>> +  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 ]
>> +    then
>> +      echo "Leader sampling [Failed inconsistent branches count]"
>> +      err=1
>> +      return
>> +    fi
>> +    index=$(($index+1))
>> +    prev_branches=$branches
>> +  done < $script_output
>> +  echo "Basic leader sampling test [Success]"
>> +}
>> +
>>  test_per_thread
>>  test_register_capture
>>  test_system_wide
>>  test_workload
>>  test_branch_counter
>> +test_leader_sampling
>>  
>>  cleanup
>>  exit $err