Re: [PATCH v2 38/49] perf python: Port arm-cs-trace-disasm to perf module

From: Leo Yan

Date: Wed Sep 23 2026 - 05:24:41 EST


On Sun, Sep 20, 2026 at 10:06:56PM -0700, Ian Rogers wrote:

[...]

> ---
> tools/perf/python/arm-cs-trace-disasm.py | 356 ++++++++++++++++++

A new script is added under tools/perf/python/, but I don't see the
legacy script under tools/perf/scripts/python/ being removed.

Should we maintain two copies of the script for the same purpose?

> --- a/tools/perf/tests/shell/coresight/test_arm_coresight_disasm.sh
> +++ b/tools/perf/tests/shell/coresight/test_arm_coresight_disasm.sh

> @@ -44,8 +56,8 @@ branch_search='[[:space:]](bl|b(\.(eq|ne|cs|cc|mi|pl|vs|vc|hi|ls|ge|lt|gt|le|al)
> if [ "$(id -u)" == 0 ] && [ -e /proc/kcore ]; then
> echo "Testing kernel disassembly"
> perf record -o ${perfdata} -e cs_etm//k --kcore -Se -m,64K -- touch $file > /dev/null 2>&1
> - perf script -i ${perfdata} --itrace=b -s python:${script_path} -- \
> - -d --stop-sample=2 -k ${perfdata}/kcore_dir/kcore 2> /dev/null > ${file}
> + $PYTHON ${script_path} -i ${perfdata} --itrace=b -d --stop-sample=2 \
> + -k ${perfdata}/kcore_dir/kcore 2> /dev/null > ${file}
> grep -q -E ${branch_search} ${file}
> echo "Found kernel branches"
> else
> @@ -56,8 +68,8 @@ fi
> ## Test user ##
> echo "Testing userspace disassembly"
> perf record -o ${perfdata} -e cs_etm//u -Se -m,64K -- touch $file > /dev/null 2>&1
> -perf script -i ${perfdata} --itrace=b -s python:${script_path} -- \
> - -d --stop-sample=2 2> /dev/null > ${file}
> +perf inject --itrace=b -i ${perfdata} -o ${perfdata2}
> +$PYTHON ${script_path} -i ${perfdata2} -d --stop-sample=2 2> /dev/null > ${file}

The perf script command is replaced with perf inject and a Python
command. I learned from the above that we can pass the itrace option to
the Python script.

This is fine with me. I'm just curious why we don't use a single Python
command here.

> grep -q -E ${branch_search} ${file}
> echo "Found userspace branches"
>
> diff --git a/tools/perf/tests/shell/lib/setup_python.sh b/tools/perf/tests/shell/lib/setup_python.sh
> index 2173215a0517..220d9663f81a 100644
> --- a/tools/perf/tests/shell/lib/setup_python.sh
> +++ b/tools/perf/tests/shell/lib/setup_python.sh
> @@ -18,6 +18,10 @@ fi
> # Set PYTHONPATH to find the in-tree built perf.so first, avoiding system-wide perf.so
> if [ -n "$PERF_EXEC_PATH" ] && [ -d "$PERF_EXEC_PATH/python" ]; then
> PYTHONPATH_DIR="$PERF_EXEC_PATH/python"
> +elif [ -n "${BASH_SOURCE[0]}" ] && [ -d "$(dirname "${BASH_SOURCE[0]}")/../../../python" ]; then
> + PYTHONPATH_DIR="$(dirname "${BASH_SOURCE[0]}")/../../../python"
> +elif [ -d "$(dirname "$0")/../../../python" ]; then
> + PYTHONPATH_DIR="$(dirname "$0")/../../../python"

Not sure if this is specific to arm-cs-trace-disasm.py. Would this be a
common change?

Thanks,
Leo