Re: [PATCH 0/1] Introduce an instrumented profiler using BpfTrace

From: Viktor Malik

Date: Wed Jul 01 2026 - 03:01:36 EST


On 6/30/26 16:11, Aaron Lewis wrote:
> I am proposing this patch as a simple way of turning BpfTrace into an
> instrumented profiler. This approach has come in handy for me more than
> once, so I felt like it could be useful for others as well.
>
> I am not entirely sure where something like this should live in the
> kernel tree, so I took a chance and put it in
> "tools/bpftrace/instrumented_profiler". I am not attached to this
> location, so please feel free to recommend a better place for it to live
> if this doesn't seem appropriate.
>
> I have included two samples as examples of how a trace can be set up
> (`kvm_trace.bt` and `vfio_trace.bt`). The included Python script then
> runs over the output of these traces to generate the final profiler
> results. Example output can be seen in the patch itself.
>
> Aaron Lewis (1):
> tools/bpftrace: Add a simple instrumented kernel profiler
>
> .../aggregate_bpf_results.py | 318 ++++++++++++++++++
> .../samples/kvm_trace.bt | 197 +++++++++++
> .../samples/vfio_trace.bt | 315 +++++++++++++++++
> 3 files changed, 830 insertions(+)
> create mode 100644 tools/bpftrace/instrumented_profiler/aggregate_bpf_results.py
> create mode 100644 tools/bpftrace/instrumented_profiler/samples/kvm_trace.bt
> create mode 100644 tools/bpftrace/instrumented_profiler/samples/vfio_trace.bt
>

Agreed with Alexei, this doesn't belong to the kernel tree. For the very
least, the provided bpftrace scripts depend on a specific version of
bpftrace (e.g. they use macros, which are only available from 0.24). But
we could certainly consider it for the bpftrace main repo [1] or the
user-tools repo [2].

Looking at the code, I'm just wondering what value does the Python
script provide. Wouldn't it be possible to do the same in bpftrace
directly? If so, then including such a tool into bpftrace could be
relatively simple.

Thanks!
Viktor

[1] https://github.com/bpftrace/bpftrace
[2] https://github.com/bpftrace/user-tools