Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I benchmark or trace a specific function in the Linux Kernel?

How do I use ftrace() (or anything else) to trace a specific, user-defined function in the Linux kernel? I'm trying to create and run some microbenchmarks, so I'd like to have the time it takes certain functions to run. I've read through (at least as much as I can) the documentation, but a step in the right direction would be awesome.

I'm leaning towards ftrace(), but having issues getting it to work on Ubuntu 14.04.

like image 878
Ricky Mutschlechner Avatar asked Oct 08 '14 06:10

Ricky Mutschlechner


People also ask

What is tracing in kernel?

Tracing is a useful technique to find bugs in software, and ftrace is the tracing framework built into the Linux kernel.

What does trace do in Linux?

traceroute command in Linux prints the route that a packet takes to reach the host. This command is useful when you want to know about the route and about all the hops that a packet takes.

What is kernel profiling?

A Kernel instrumentation profiler uses a subset of the software tools and libraries included in the Linux® kernel, for monitoring the actions made by the kernel to manage the execution of processes running on the SoC hardware.

What is Kprobe in kernel?

KProbes is a debugging mechanism for the Linux kernel which can also be used for monitoring events inside a production system. You can use it to weed out performance bottlenecks, log specific events, trace problems etc.


1 Answers

Here are a couple of options you may have depending on the version of the kernel you are on:

Systemtap - this is the ideal way check the examples that come with the stap, you may have something ready with minimal modifications to do.

Oprofile - if you are using older versions of the kernel, stap gives better precision compared to oprofile.

debugfs with stack tracer option - good for stack overrun debugging. To do this you would need to turn on depth checking functions by mounting debugfs and then echo 1 > /proc/sys/kernel/stack_tracer_enabled.

strace - if you are looking at identifying the system calls being called by the user space program and some performance numbers. use strace -fc <program name>

Hope this helps!

like image 109
askb Avatar answered Nov 15 '22 05:11

askb