Re: [PATCH v2 38/49] perf python: Port arm-cs-trace-disasm to perf module
From: Ian Rogers
Date: Fri Sep 25 2026 - 17:45:46 EST
On Thu, Sep 24, 2026 at 8:41 AM Leo Yan <leo.yan@xxxxxxx> wrote:
>
> On Wed, Sep 23, 2026 at 06:40:57AM -0700, Ian Rogers wrote:
>
> [...]
>
> > > > @@ -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.
> >
> > A single Python command that would handle both the itrace and file
> > processing? We could. Having the script command also perform an
> > inject-like rewrite of the data seemed less obvious to me than just
> > having perf inject do the work and then running the script. It does
> > mean a change for people using the script, and two commands could be
> > less convenient than one. We could expand the Python module "session"
> > code to include the ability to rewrite itrace data specifically for
> > this script. I'm hoping that we can have more composable perf_tools in
> > the code, similar to the ASLR code.
>
> > It would be nice to add itrace support to the Python code with
> > composing tools in mind. I was just putting off worrying about this
> > for now.
>
> Sorry for the confusion. I should have made this clearer in my previous
> reply.
>
> I was referring to this change:
>
> + $PYTHON ${script_path} -i ${perfdata} --itrace=b -d --stop-sample=2 \
> + -k ${perfdata}/kcore_dir/kcore 2> /dev/null > ${file}
>
> If itrace processing is not currently supported by the Python code,
> wouldn't adding --itrace=b here break the test?
Thanks Leo, so I misspoke before. The LLM already added the itrace
support into the Python session API in patch 9 ("perf python: Add
Intel PT call_return and itrace capability"). It adds `itrace`
support directly to `perf.session()` in the C extension (calling
`itrace_do_parse_synth_opts()` on the session's `itrace_synth_opts`),
and `arm-cs-trace-disasm.py` defaults `--itrace` to `"b"` and passes
`itrace=self.options.itrace` when constructing `perf.session()`.
Because `arm-cs-trace-disasm.py` already defaults to `itrace="b"`
(matching commit 89db7f0db172 ("perf cs-etm: Filter synthesized branch
samples")), passing `--itrace=b` in `test_arm_coresight_disasm.sh` is
redundant. In v4, I will remove `--itrace=b` from
`test_arm_coresight_disasm.sh`, add `PERF_ITRACE` forwarding when
`perf script --itrace=... <script>` is used, and fix two issues found
while inspecting the CoreSight disassembly flow
(`symbol_conf.vmlinux_name` initialization order before
`perf_session__new()` when `--kcore` is present, and recording the
initial `CS_ETM_TRACE_ON` sample's `sample_addr` before filtering `dso
== '[unknown]'`).
Thanks,
Ian
> Thanks,
> Leo