diff options
| author | 2026-09-25 23:19:48 -0700 | |
|---|---|---|
| committer | 2026-09-26 20:49:29 +0200 | |
| commit | eeb70645a8097437c06cebccda4115f366b928c3 (patch) | |
| tree | 1a3eede27eb30e2998cc4ce717fd0c6db6459638 /tools/perf/tests/shell/test_event_analyzing_sample_python.sh | |
| parent | perf python: Port gecko to perf module (diff) | |
perf python: Port event_analyzing_sample to perf module
Port event_analyzing_sample.py to a standalone script in
tools/perf/python/ using the perf module and standard library sqlite3
module.
Improvements compared to the legacy script:
- Encapsulate database state in a _DB container instead of mutating
module-level globals, and ensure temporary SQLite database files are
cleaned up on exit.
- Add argparse CLI options (-i/--input and -d/--db) while preserving
PerfEvent, PebsEvent, and PebsNHM binary raw_buf unpacking and
symbol/DSO histogram reporting.
- Remove Python 2 compatibility code and add type annotations.
Add a shell test (test_event_analyzing_sample_python.sh) to verify the
standalone script.
Assisted-by: Antigravity:gemini-3.1-pro
Signed-off-by: Ian Rogers <irogers@google.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/tests/shell/test_event_analyzing_sample_python.sh')
| -rwxr-xr-x | tools/perf/tests/shell/test_event_analyzing_sample_python.sh | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/tools/perf/tests/shell/test_event_analyzing_sample_python.sh b/tools/perf/tests/shell/test_event_analyzing_sample_python.sh new file mode 100755 index 000000000000..4678edfd9e5b --- /dev/null +++ b/tools/perf/tests/shell/test_event_analyzing_sample_python.sh @@ -0,0 +1,62 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +# event_analyzing_sample python test + +set -e + +shelldir=$(dirname "$0") +# shellcheck source=lib/setup_python.sh +. "${shelldir}"/lib/setup_python.sh + +# If we don't have the perf python module, we can't test +if ! "$PYTHON" -c 'import perf' > /dev/null 2>&1; then + echo "Skipping test, perf python module not found" + exit 2 +fi + +script_dir="$(dirname "$0")/../../python" +script_path="${script_dir}/event_analyzing_sample.py" + +if [ ! -f "$script_path" ]; then + echo "Skipping test, event_analyzing_sample.py not found at $script_path" + exit 2 +fi + +err=0 +temp_dir="" + +cleanup() { + rm -rf "${temp_dir}" +} + +trap 'cleanup' EXIT TERM INT + +temp_dir=$(mktemp -d /tmp/perf.event_analyzing.XXXXXX) +temp_data="${temp_dir}/perf.data" +temp_db="${temp_dir}/perf.db" + +test_file_mode() { + echo "Testing event_analyzing_sample.py..." + + # Generate some events + if ! perf record -o "${temp_data}" -- perf test -w noploop >/dev/null 2>&1; then + echo "Skipping test, perf record failed" + exit 2 + fi + + # Run the script + if ! "$PYTHON" "$script_path" -i "${temp_data}" -d "${temp_db}" > "${temp_dir}/perf.out" 2>&1; then + echo "File mode test failed." + err=1 + elif ! grep -q "Statistics about the general events" "${temp_dir}/perf.out" || \ + grep -q "Error creating/inserting event" "${temp_dir}/perf.out"; then + echo "Event analysis output validation failed." + err=1 + else + echo "File mode test passed." + fi +} + +test_file_mode + +exit $err |
