perf test: Basic branch counter support
PATCH 1/1 perf test: Basic branch counter support
From: Kan Liang <[email protected]>
Add a basic test for the branch counter feature.
The test verifies that
- The new filter can be successfully applied on the supported platforms.
- The counter value can be outputted via the perf report -D
--- tools/perf/tests/shell/record.sh | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)
tools/perf/tests/shell/record.sh +30 -0
@@ -11,6 +11,9 @@ err=0 perfdata=$(mktemp /tmp/__perf_test.perf.data.XXXXX) testprog="perf test -w thloop" testsym="test_loop" +cpu_pmu_dir="/sys/bus/event_source/devices/cpu*" +br_cntr_file="/caps/branch_counter_nr" +br_cntr_output="branch stack counters" cleanup() { rm -rf "${perfdata}"
@@ -154,10 +157,37 @@ test_workload() { echo "Basic target workload test [Success]" } +test_branch_counter() { + echo "Basic branch counter test" + # Check if the branch counter feature is supported + for dir in $cpu_pmu_dir + do + if [ ! -e "$dir$br_cntr_file" ] + then + echo "Not support branch counter feature [Skipped]" + return + fi + done + if ! perf record -o "${perfdata}" -j any,counter ${testprog} 2> /dev/null + then + echo "Basic branch counter test [Failed record]" + err=1 + return + fi + if ! perf report -i "${perfdata}" -D -q | grep -q "$br_cntr_output" + then + echo "Basic branch record test [Failed missing output]" + err=1 + return + fi + echo "Basic branch counter test [Success]" +} + test_per_thread test_register_capture test_system_wide test_workload +test_branch_counter cleanup exit $err
Signature · 1 line
2.35.1
Ian Rogers
reviewerQuoted 10 lines · On Tue, Nov 7, 2023 at 9:44 AM <[email protected]> wrote:
From: Kan Liang <[email protected]>
Add a basic test for the branch counter feature.
The test verifies that
- The new filter can be successfully applied on the supported platforms.
- The counter value can be outputted via the perf report -DSigned-off-by Kan Liang <[email protected]>
Thanks Kan!
Quoted 19 lines
--- tools/perf/tests/shell/record.sh | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)tools/perf/tests/shell/record.sh +3
-0@@ -11,6 +11,9 @@ err=0 perfdata=$(mktemp /tmp/__perf_test.perf.data.XXXXX) testprog="perf test -w thloop" testsym="test_loop" +cpu_pmu_dir="/sys/bus/event_source/devices/cpu*" +br_cntr_file="/caps/branch_counter_nr" +br_cntr_output="branch stack counters" cleanup() { rm -rf "${perfdata}"
tools/perf/tests/shell/record.sh test_workload() { · line 162
Quoted 6 lines
tools/perf/tests/shell/record.sh +3
-0@@ -154,10 +157,37 @@ test_workload() { echo "Basic target workload test [Success]" } +test_branch_counter() { + echo "Basic branch counter test" + # Check if the branch counter feature is supported
If $cpu_pmu_dir is empty, e.g. ARM and S390, this should also skip.
tools/perf/tests/shell/record.sh test_workload() { · line 167
Quoted 5 lines
tools/perf/tests/shell/record.sh +5
-0+ for dir in $cpu_pmu_dir + do + if [ ! -e "$dir$br_cntr_file" ] + then + echo "Not support branch counter feature [Skipped]"
Perhaps here it'd be clearer to output:
echo "branch counter feature not supported on all core PMUs ($dir) [Skipped]"
Thanks,
Ian
Quoted 29 lines
tools/perf/tests/shell/record.sh +19
-1+ return + fi + done + if ! perf record -o "${perfdata}" -j any,counter ${testprog} 2> /dev/null + then + echo "Basic branch counter test [Failed record]" + err=1 + return + fi + if ! perf report -i "${perfdata}" -D -q | grep -q "$br_cntr_output" + then + echo "Basic branch record test [Failed missing output]" + err=1 + return + fi + echo "Basic branch counter test [Success]" +} + test_per_thread test_register_capture test_system_wide test_workload +test_branch_counter cleanup exit $err --2.35.1
Quoted 36 lines · Ian Rogers
Quoted 10 lines · On Tue, Nov 7, 2023 at 9:44 AM <[email protected]> wrote:
From: Kan Liang <[email protected]>
Add a basic test for the branch counter feature.
The test verifies that
- The new filter can be successfully applied on the supported platforms.
- The counter value can be outputted via the perf report -DSigned-off-by Kan Liang <[email protected]>Thanks Kan!
Quoted 22 lines
--- tools/perf/tests/shell/record.sh | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)tools/perf/tests/shell/record.sh +3
-0@@ -11,6 +11,9 @@ err=0 perfdata=$(mktemp /tmp/__perf_test.perf.data.XXXXX) testprog="perf test -w thloop" testsym="test_loop" +cpu_pmu_dir="/sys/bus/event_source/devices/cpu*" +br_cntr_file="/caps/branch_counter_nr" +br_cntr_output="branch stack counters" cleanup() { rm -rf "${perfdata}"@@ -154,10 +157,37 @@ test_workload() { echo "Basic target workload test [Success]" }
Quoted 6 lines
tools/perf/tests/shell/record.sh test_workload() { · line 162
Quoted 3 lines
tools/perf/tests/shell/record.sh +3
-0+test_branch_counter() { + echo "Basic branch counter test" + # Check if the branch counter feature is supportedIf $cpu_pmu_dir is empty, e.g. ARM and S390, this should also skip.
Yes, I've tested with a fake unsupported dir. The test case is skipped as well.
Quoted 9 lines
tools/perf/tests/shell/record.sh test_workload() { · line 167
Quoted 5 lines
tools/perf/tests/shell/record.sh +5
-0+ for dir in $cpu_pmu_dir + do + if [ ! -e "$dir$br_cntr_file" ] + then + echo "Not support branch counter feature [Skipped]"Perhaps here it'd be clearer to output:
echo "branch counter feature not supported on all core PMUs ($dir) [Skipped]"
Sure, I will change it in V2.
Thanks,
Kan
Quoted 33 lines
Thanks,
IanQuoted 29 lines
tools/perf/tests/shell/record.sh +19
-1+ return + fi + done + if ! perf record -o "${perfdata}" -j any,counter ${testprog} 2> /dev/null + then + echo "Basic branch counter test [Failed record]" + err=1 + return + fi + if ! perf report -i "${perfdata}" -D -q | grep -q "$br_cntr_output" + then + echo "Basic branch record test [Failed missing output]" + err=1 + return + fi + echo "Basic branch counter test [Success]" +} + test_per_thread test_register_capture test_system_wide test_workload +test_branch_counter cleanup exit $err --2.35.1