How to test or trace a specific function in the Linux kernel?

How to use ftrace () (or something else) to track a specific, user-defined function in the Linux kernel? I am trying to create and run some microobjects, so I would like to have the time needed to perform certain functions. I read (at least as far as possible) the documentation, but a step in the right direction would be awesome.

I tend to ftrace (), but I'm having trouble working on Ubuntu 14.04.

+6
source share
7 answers

Ftrace is a good option and has good documentation .

+1
source

Here are a few options that you may have depending on the version of the kernel you are in:

Systemtap is the perfect way to check out the examples that come with stap, you can have something ready with minimal changes.

Oprofile - if you use older kernel versions, stap gives better accuracy compared to oprofile.

debugfs with the trace stack option is good for debugging. To do this, you need to enable mounting debugfs depth mounting debugfs , and then echo 1 > /proc/sys/kernel/stack_tracer_enabled .

strace - if you want to determine the system calls called by the user space program and some performance numbers. use strace -fc <program name>

Hope this helps!

+4
source

use WARN_ON() It will print some trace of a function called so.

For time tracking, I think you should use the timestamp displayed in the kernel log, or use jiffies counter

+1
source

Also your system will be useful in your situation. Systemtap is a kind of tool in which you can write code, as in scripting languages. It is very powerful, but if you want to know only the runtime, then a certain ftrace function would be better, but if you need a very advanced tool for analyzing, for example, performance problems in kernel space, this can be very useful.

Pls read more: (what you want to do here: - 5.2 Synchronization function execution time) enter the link here

+1
source

If the execution time of the function is interesting, because it causes auxiliary calls for slow / blocking functions, then tracing using instructions can work for you, without excessive distortion due to the "overhead" of the toolkit itself.

 probe kernel.statement(" function_name@dir /file.c:*") { println(tid(), " ", gettimeofday_us(), " ", pn()) } 

will give you a trace of each individual statement in the function name. The delta between adjacent operations is easily computed manually or in a large script. See also https://sourceware.org/systemtap/examples/#profiling/linetimes.stp

+1
source

To get the required accuracy (CPU cycles), I ended up using get_cycles() , which is essentially a wrapper for RDTSC (but portable). ftrace () may still be useful in the future, but all I am doing now is the difference between the initial cycles of the processor and the final cycles of the processor and using this as a reference.

Update. To avoid parallelizing instructions, I actually crashed instead of RDTSCP. I could not use RDTSC + CPUID because it caused a lot of delays with hypercalls (I work in a virtual machine).

0
source
0
source

Source: https://habr.com/ru/post/976401/


All Articles