'Enable event tracing upon kernel module load

I want to use Ftrace event tracer for my kernel module.

It is important to me that I'll be able to trace right when the module loads- in similar fashion to enabling events during boot via the kernel command line.

I had no success with it, I did saw that some effort was made to make this possible (tracing: Enable tracepoints via module parameters).

Can someone point me out if (and if so, how) is this possible?



Solution 1:[1]

Make sure that you have enabled ftrace, debugfs in the kernel config, and those related modules.

After you mount the debugfs, there should be a directory called tracing under the debugfs. Ex /sys/kernel/debug/tracing

You can cat available_tracers to see what are the available tracers and cat available_filter_functions to see what are the filter functions

You can set something like, ex: echo kfree_skb > set_ftrace_filter to enable the filter.

What did you try and failed at which point?

The official document got more details, https://www.kernel.org/doc/Documentation/trace/ftrace.txt

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Justin Yu