how to collect information regarding function calls in run time?

Valdis Kl=?utf-8?Q?=c4=93?=tnieks valdis.kletnieks at vt.edu
Tue May 14 13:45:58 EDT 2019


On Tue, 14 May 2019 10:55:40 -0300, Pedro Terra Delboni said:

> Regarding bpftrace: This seemed like the best option since I could use it
> to count frames of the stack with depth 2, allowing me to know precisely
> the amount of times each specific call has been made. However, I could not
> use it because since I have to probe every function, it would raise an
> error related to open file limit. I've tried setting the open file limit to
> unlimited, but the command I used to do so said it was impossible, also the
> current limit is set to 1048576, so I'm guessing that probing every
> function isn't a viable solution.

What problem are you trying to solve?

If you're trying to count how often *every* function is called, and the fact
that one way to do it has an upper limit of a million is a problem, chances are
that you haven't figured out what the *question* is yet.

Usually, the number of calls isn't that important, the total runtime spent in
the function is important.  A one-liner inline accessor function that compiles
down to 2-3 machine opcodes can be called tens of thousands of times a second
and not be noticed.  A function that takes milliseconds to complete will be
noticed if it's called only a few dozen times a second.

If you're trying to figure out how the functions fit together, a static call
graph analysis tool to produce a map of what calls what may be what you need.

Having said that, a kernel built with gcov or ftrace support will give you the
info you need.

See kernel/gcove/Kconfig and http://heim.ifi.uio.no/~knuto/kernel/4.14/dev-tools/gcov.html
if you want to go that route.

Resources for ftrace call counts:

http://www.brendangregg.com/blog/2014-07-13/linux-ftrace-function-counting.html

https://wiki.linaro.org/KenWerner/Sandbox/ftrace and see section 'function profiler'.

Be prepared for your kernel to be quite slow, and have to do a *lot* of data
reduction.

Note that you'll probably need to run for at least several hours, and of course
the function counts will be *very* dependent on what you do - what gets called
while I'm doing stuff like writing e-mail is very different from what happens
during a kernel compile, and both of those are different from the function
counts that happen when I back up my laptop to an external USB disk.

(Note I've not *tried* any of the above - this laptop is slow enough as it is :)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 832 bytes
Desc: not available
URL: <http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20190514/65a8ff52/attachment.sig>


More information about the Kernelnewbies mailing list