perf test: Add a perf event fallback test
PATCH 1/1 perf test: Add a perf event fallback test
This adds test cases to verify the precise ip fallback logic:
- If the system supports precise ip, for an event given with the maximum precision level, it should be able to decrease precise_ip to find a supported level.
- The same fallback behavior should also work in more complex scenarios, such as event groups or when PEBS is involved
Additional fallback tests, such as those covering missing feature cases, can be added in the future.
--- .../tests/shell/test_event_open_fallback.sh | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100755 tools/perf/tests/shell/test_event_open_fallback.sh
tools/perf/tests/shell/test_event_open_fallback.sh new file +86 -0
@@ -0,0 +1,86 @@ +#!/bin/bash +# Perf event open fallback test +# SPDX-License-Identifier: GPL-2.0 + +skip_cnt=0 +ok_cnt=0 +err_cnt=0 + +cleanup() +{ + rm -f perf.data + rm -f perf.data.old + trap - EXIT TERM INT +} + +trap_cleanup() +{ + cleanup + exit 1 +} + +trap trap_cleanup EXIT TERM INT + +perf_record() +{ + perf record "$@" -- true 1>/dev/null 2>&1 +} + +test_decrease_precise_ip() +{ + echo "Decrease precise ip test" + + perf list pmu | grep -q 'cycles' || return 2 + + if ! perf_record -e cycles; then + return 2 + fi + + # It should reduce precision level down to 0 if needed. + if ! perf_record -e cycles:ppp; then + return 1 + fi + return 0 +} + +test_decrease_precise_ip_complicated() +{ + echo "Decrease precise ip test (complicated case)" + + perf list pmu | grep -q 'mem-loads-aux' || return 2 + + if ! perf_record -e '{cpu/mem-loads-aux/S,cpu/mem-loads/PS}'; then + return 1 + fi + return 0 +} + +count_result() +{ + if [ "$1" -eq 2 ] ; then + skip_cnt=$((skip_cnt + 1)) + return + fi + if [ "$1" -eq 0 ] ; then + ok_cnt=$((ok_cnt + 1)) + return + fi + err_cnt=$((err_cnt + 1)) +} + +ret=0 +test_decrease_precise_ip || ret=$? ; count_result $ret ; ret=0 +test_decrease_precise_ip_complicated || ret=$? ; count_result $ret ; ret=0 + +cleanup + +if [ ${err_cnt} -gt 0 ] ; then + exit 1 +fi + +if [ ${ok_cnt} -gt 0 ] ; then + exit 0 +fi + +# Skip +exit 2
Signature · 1 line
2.51.1
Namhyung Kim
maintainerQuoted 55 lines · Zide Chen
This adds test cases to verify the precise ip fallback logic:
- If the system supports precise ip, for an event given with the maximum precision level, it should be able to decrease
precise_ipto find a supported level.
- The same fallback behavior should also work in more complex scenarios, such as event groups or when PEBS is involvedAdditional fallback tests, such as those covering missing feature cases, can be added in the future.
Suggested-by Ian Rogers <[email protected]>Reviewed-by Dapeng Mi <[email protected]>Signed-off-by Zide Chen <[email protected]>--- .../tests/shell/test_event_open_fallback.sh | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100755 tools/perf/tests/shell/test_event_open_fallback.shtools/perf/tests/shell/test_event_open_fallback.sh new file +30
-0@@ -0,0 +1,86 @@ +#!/bin/bash +# Perf event open fallback test +# SPDX-License-Identifier: GPL-2.0 + +skip_cnt=0 +ok_cnt=0 +err_cnt=0 + +cleanup() +{ + rm -f perf.data + rm -f perf.data.old + trap - EXIT TERM INT +} + +trap_cleanup() +{ + cleanup + exit 1 +} + +trap trap_cleanup EXIT TERM INT + +perf_record() +{ + perf record "$@" -- true 1>/dev/null 2>&1 +} + +test_decrease_precise_ip() +{
tools/perf/tests/shell/test_event_open_fallback.sh line 40
Quoted 10 lines
tools/perf/tests/shell/test_event_open_fallback.sh new file +10
-0+ echo "Decrease precise ip test" + + perf list pmu | grep -q 'cycles' || return 2 + + if ! perf_record -e cycles; then + return 2 + fi + + # It should reduce precision level down to 0 if needed. + if ! perf_record -e cycles:ppp; then
I think you need 'P' instead of 'ppp' for automatic precision.
Thanks,
Namhyung
Quoted 49 lines
tools/perf/tests/shell/test_event_open_fallback.sh new file +46
-0+ return 1 + fi + return 0 +} + +test_decrease_precise_ip_complicated() +{ + echo "Decrease precise ip test (complicated case)" + + perf list pmu | grep -q 'mem-loads-aux' || return 2 + + if ! perf_record -e '{cpu/mem-loads-aux/S,cpu/mem-loads/PS}'; then + return 1 + fi + return 0 +} + +count_result() +{ + if [ "$1" -eq 2 ] ; then + skip_cnt=$((skip_cnt + 1)) + return + fi + if [ "$1" -eq 0 ] ; then + ok_cnt=$((ok_cnt + 1)) + return + fi + err_cnt=$((err_cnt + 1)) +} + +ret=0 +test_decrease_precise_ip || ret=$? ; count_result $ret ; ret=0 +test_decrease_precise_ip_complicated || ret=$? ; count_result $ret ; ret=0 + +cleanup + +if [ ${err_cnt} -gt 0 ] ; then + exit 1 +fi + +if [ ${ok_cnt} -gt 0 ] ; then + exit 0 +fi + +# Skip +exit 2Signature · 1 line
2.51.1
Quoted 60 lines · Namhyung Kim
Quoted 59 lines · Zide Chen
This adds test cases to verify the precise ip fallback logic:
- If the system supports precise ip, for an event given with the maximum precision level, it should be able to decrease
precise_ipto find a supported level.
- The same fallback behavior should also work in more complex scenarios, such as event groups or when PEBS is involvedAdditional fallback tests, such as those covering missing feature cases, can be added in the future.
Suggested-by Ian Rogers <[email protected]>Reviewed-by Dapeng Mi <[email protected]>Signed-off-by Zide Chen <[email protected]>--- .../tests/shell/test_event_open_fallback.sh | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100755 tools/perf/tests/shell/test_event_open_fallback.shtools/perf/tests/shell/test_event_open_fallback.sh new file +34
-0@@ -0,0 +1,86 @@ +#!/bin/bash +# Perf event open fallback test +# SPDX-License-Identifier: GPL-2.0 + +skip_cnt=0 +ok_cnt=0 +err_cnt=0 + +cleanup() +{ + rm -f perf.data + rm -f perf.data.old + trap - EXIT TERM INT +} + +trap_cleanup() +{ + cleanup + exit 1 +} + +trap trap_cleanup EXIT TERM INT + +perf_record() +{ + perf record "$@" -- true 1>/dev/null 2>&1 +} + +test_decrease_precise_ip() +{ + echo "Decrease precise ip test" + + perf list pmu | grep -q 'cycles' || return 2 +
Quoted 8 lines
tools/perf/tests/shell/test_event_open_fallback.sh line 40
Quoted 6 lines
tools/perf/tests/shell/test_event_open_fallback.sh new file +6
-0+ if ! perf_record -e cycles; then + return 2 + fi + + # It should reduce precision level down to 0 if needed. + if ! perf_record -e cycles:ppp; thenI think you need 'P' instead of 'ppp' for automatic precision.
Yes, it's better with "-e cycles:P" to explicitly set evsel.precise_max to 1.
Quoted 53 lines
Thanks,
NamhyungQuoted 49 lines
tools/perf/tests/shell/test_event_open_fallback.sh new file +46
-0+ return 1 + fi + return 0 +} + +test_decrease_precise_ip_complicated() +{ + echo "Decrease precise ip test (complicated case)" + + perf list pmu | grep -q 'mem-loads-aux' || return 2 + + if ! perf_record -e '{cpu/mem-loads-aux/S,cpu/mem-loads/PS}'; then + return 1 + fi + return 0 +} + +count_result() +{ + if [ "$1" -eq 2 ] ; then + skip_cnt=$((skip_cnt + 1)) + return + fi + if [ "$1" -eq 0 ] ; then + ok_cnt=$((ok_cnt + 1)) + return + fi + err_cnt=$((err_cnt + 1)) +} + +ret=0 +test_decrease_precise_ip || ret=$? ; count_result $ret ; ret=0 +test_decrease_precise_ip_complicated || ret=$? ; count_result $ret ; ret=0 + +cleanup + +if [ ${err_cnt} -gt 0 ] ; then + exit 1 +fi + +if [ ${ok_cnt} -gt 0 ] ; then + exit 0 +fi + +# Skip +exit 2Signature · 1 line
2.51.1