0

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?

user2063776
  • 201
  • 1
  • 2
  • 4

1 Answers1

0

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

Justin Yu
  • 61
  • 5
  • Justine- please note that you are referring to the function tracer in which, to the best of my knowledge, this can be done. I'm talking about event tracer in which AFAIK using the filetr in ```set_event``` is not possible before module load (as the event is not there yet) – user2063776 May 25 '22 at 08:55
  • Did you try boot-time tracing? Ref: https://01.org/linuxgraphics/gfx-docs/drm/trace/boottime-trace.html# Or add boot option for early boot debugging? In order to facilitate early boot debugging, use boot option, ex: `trace_event=[event-list]` – Justin Yu May 26 '22 at 05:07
  • Justine- the common usecase is to dynamically load my driver, hence boot-time tracing will not help here (or am I wrong here?) – user2063776 May 29 '22 at 09:16