summaryrefslogtreecommitdiff
path: root/tools/perf/tests/shell
diff options
context:
space:
mode:
authorIan Rogers <irogers@google.com>2026-09-25 23:20:07 -0700
committerArnaldo Carvalho de Melo <acme@redhat.com>2026-09-26 20:49:30 +0200
commitd4ce72e9e238fd703306b66a33eb41391e6e5a5a (patch)
tree6befbc09491cf2c643e8b7ab9b03864091bb9a65 /tools/perf/tests/shell
parentd5934ca319a08e41498e47210285b73970cf074a (diff)
perf python: Port intel-pt-events and libxed to perf module
Port intel-pt-events.py and libxed.py from tools/perf/scripts/python/ to standalone modules in tools/perf/python/: - Refactor intel-pt-events.py into an IntelPTAnalyzer class with full type annotations to encapsulate trace state and stashed output. - Configure instruction trace decoding directly via perf.session's itrace option and context_switch callback. - Dynamically select 32-bit vs 64-bit disassembly mode in libxed.py using session.is_64_bit and annotate instructions with source lines via sample.srccode(). - Rename methods in libxed.py to snake_case (instruction, set_mode, disassemble_one) and remove Python 2 compatibility code. Add a shell test (test_intel_pt_events_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')
-rwxr-xr-xtools/perf/tests/shell/test_intel_pt_events_python.sh69
1 files changed, 69 insertions, 0 deletions
diff --git a/tools/perf/tests/shell/test_intel_pt_events_python.sh b/tools/perf/tests/shell/test_intel_pt_events_python.sh
new file mode 100755
index 000000000000..0d397792ced8
--- /dev/null
+++ b/tools/perf/tests/shell/test_intel_pt_events_python.sh
@@ -0,0 +1,69 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# intel-pt-events python test (exclusive)
+
+set -e
+
+shelldir=$(dirname "$0")
+# shellcheck source=lib/setup_python.sh
+. "${shelldir}"/lib/setup_python.sh
+
+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}/intel-pt-events.py"
+
+if [ ! -f "$script_path" ]; then
+ echo "Skipping test, intel-pt-events.py not found at $script_path"
+ exit 2
+fi
+
+err=0
+temp_dir=""
+temp_data=""
+temp_out=""
+
+cleanup() {
+ [ -n "${temp_dir}" ] && rm -rf "${temp_dir}"
+}
+
+trap 'cleanup' EXIT TERM INT
+
+temp_dir=$(mktemp -d /tmp/perf.ipt.XXXXXX)
+temp_data="${temp_dir}/perf.data"
+temp_out="${temp_dir}/perf.out"
+
+test_intel_pt() {
+ echo "Testing intel-pt-events.py with intel_pt..."
+
+ rm -f "${temp_data}" "${temp_out}"
+ # Generate some intel_pt events; use a subshell that waits for uname so
+ # uname's AUX buffer is flushed before the parent workload exits.
+ if ! perf record -B -N --no-bpf-event -e intel_pt//u -o "${temp_data}" \
+ -- sh -c "uname; true" >/dev/null 2>&1; then
+ echo "Skipping intel_pt test, intel_pt not available."
+ exit 2
+ fi
+
+ # Run the script and check output
+ if ! "$PYTHON" "$script_path" -i "${temp_data}" > "${temp_out}"; then
+ echo "intel-pt-events.py test failed."
+ err=1
+ else
+ if ! grep -q "Intel PT Branch Trace" "${temp_out}" || \
+ ! grep -q "uname" "${temp_out}"; then
+ echo "Failed to find expected output: $(cat "${temp_out}")"
+ err=1
+ else
+ echo "intel-pt-events test passed."
+ fi
+ fi
+ rm -f "${temp_out}"
+}
+
+test_intel_pt
+
+exit $err