diff options
| author | Ian Rogers <irogers@google.com> | 2026-09-25 23:19:54 -0700 |
|---|---|---|
| committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2026-09-26 20:49:29 +0200 |
| commit | 47b00c38780d27bedb91b8090f74e0523ccbc95e (patch) | |
| tree | 3c864f89bb2809a398e79114400d0bb35ccef3f5 /tools/perf/tests/shell | |
| parent | b83f0bacf5e4f9369257f5c1191df02ab1be5602 (diff) | |
perf python: Port rw-by-file from Perl to perf module
Replace the legacy Perl script rw-by-file.pl with a standalone Python
script in tools/perf/python/rw-by-file.py using the perf Python module.
Improvements compared to the legacy Perl script:
- Remove the dependency on libperl and Perf::Trace::Util.
- Encapsulate per-file-descriptor read/write byte and call count
aggregation in an RwByFile class using perf.session and resolve thread
command names via session.find_thread(pid, sample_tid).
- Add argparse CLI support (-i/--input and target program filter) and
full type annotations.
Add a shell test
(test_rw_by_file_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-x | tools/perf/tests/shell/test_rw_by_file_python.sh | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/tools/perf/tests/shell/test_rw_by_file_python.sh b/tools/perf/tests/shell/test_rw_by_file_python.sh new file mode 100755 index 000000000000..98218bf8a39e --- /dev/null +++ b/tools/perf/tests/shell/test_rw_by_file_python.sh @@ -0,0 +1,68 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +# rw-by-file python test + +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}/rw-by-file.py" + +if ! perf check feature -q libtraceevent > /dev/null 2>&1; then + echo "Skipping test, libtraceevent is disabled" + exit 2 +fi + +if [ ! -f "$script_path" ]; then + echo "Skipping test, rw-by-file.py not found at $script_path" + exit 2 +fi + +err=0 +cleanup() { + rm -f "${temp_data}" "${temp_out}" +} +trap 'cleanup' EXIT TERM INT +temp_data=$(mktemp /tmp/perf.data.XXXXXX) +temp_out=$(mktemp /tmp/perf.out.XXXXXX) + +echo "Testing rw-by-file.py..." + +# Create a perf.data file. Try to get tracepoint data. +if perf list | grep -q "syscalls:sys_enter_read"; then + perf record -e syscalls:sys_enter_read,syscalls:sys_enter_write -a -o "${temp_data}" \ + -- dd if=/dev/urandom of=/dev/null bs=1M count=10 >/dev/null 2>&1 || \ + { echo "Skipping test, perf record failed"; exit 2; } +else + echo "Skipping test, no syscalls:sys_enter_read event" + exit 2 +fi + +if [ ! -s "${temp_data}" ]; then + echo "Skipping test, perf record failed to create data" + exit 2 +fi + +# Check that the script executes - filtering for "dd" since that's what we ran +if ! "$PYTHON" "$script_path" -i "${temp_data}" "dd" > "${temp_out}"; then + echo "rw-by-file.py test failed" + err=1 +else + if ! grep -E -q "^ *[0-9]+" "${temp_out}"; then + echo "Failed to find metric data rows" + err=1 + else + echo "rw-by-file test passed." + fi +fi +rm -f "${temp_out}" + +exit $err |
