Re: [PATCH] perf/core: Add a tracepoint for perf sampling
From: Brendan Gregg
Date: Fri Jul 29 2016 - 15:56:20 EST
On Fri, Jul 29, 2016 at 12:21 PM, Arnaldo Carvalho de Melo
> Em Tue, Jul 19, 2016 at 11:20:48PM +0000, Brendan Gregg escreveu:
>> When perf is performing hrtimer-based sampling, this tracepoint can be used
>> by BPF to run additional logic on each sample. For example, BPF can fetch
>> stack traces and frequency count them in kernel context, for an efficient
> Could you provide a complete experience? I.e. together with this patch a
> bpf script that could then run, with the full set of steps needed to
> show it in use.
There's currently profile.py, in bcc, which will either use this
tracepoint or use a kprobe if it doesn't exist (although the kprobe is
unreliable). profile samples stack traces and shows stack traces with
their occurrence counts. Eg:
Sampling at 49 Hertz of all threads by user + kernel stack... Hit Ctrl-C to end.
- cp (9036)
- swapper/0 (0)
- swapper/1 (0)
Tool and examples are on github . Is this sufficient for this
patch? If not, I could rewrite something for samples/bpf (eg, an IP
sampler, or a task priority sampler), which I may do anyway as a
follow-on if they turned out to be nice examples.
> Also, what would be the value when BPF is not used?
No big reason comes to mind. I could imagine it might be useful when
debugging perf's sampling behavior, and there might be uses with
ftrace as well. But the big reason is extending perf's existing
sampling capabilities for in-kernel frequency counts of stack traces
(which could include custom BPF-based stack walkers), IP, task
priority, etc. Thanks,