Tracing how much time the kernel spends in a function

Using ebpf and the bpftrace command line utility, you can perform simple reporting on function calls. Here’s an example:


/usr/bin/bpftrace -e \
'
BEGIN{@WFE=false}      
kfunc:queue_poll / args.qp->wfe == @WFE / { @start= elapsed}   
kretfunc:queue_poll /args.qp->wfe == @WFE / { @delta = elapsed - @start; @total+=@delta }      
END{  @ = stats(@delta) }'

This is for the function queue_poll, specifically when the wfe field of the gp parameter is set to false. To figure out if you can even look at queue_poll, use the kernel symbols:

grep queue_poll /proc/kallsyms

Simetimes symbols get inlined and you cannot break on them, but this one happens to be in my kernel.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.