2

I am trying to use FTRACE for tracing and getting function_graph on a loadable driver module.
But, somehow, I did not see any functions in that module being traced.

Here is what I did (I had the kernel configured to have FTRACE already in the menuconfig)

#echo function_graph > /sys/kernel/debug/tracing/current_tracer
#cat /sys/kernel/debug/tracing/current_tracer
function_graph
#echo 1 > tracing_on
#insmod my_module.ko
#echo 0 > tracing_on
#cat trace

Nothing in the trace file has any functions inside my_module.ko

Do I need to enable some compiler flags when compiling my_module.c? Any ideas what I need to do?

Thanks!

electro
  • 911
  • 4
  • 12
  • 28

2 Answers2

1

I suspect that you don't see any function at all being traced; usually the dynamic ftrace is enable, so you have to manually choose what you want to trace.

cat available_filter_functions

It shows you all function that you can trace (grep for what you want just to be sure that is there). Of course, your module's function are visible only after module loading. So you load the module and then you add your function.

insmod mymodule.ko
echo my_function >> set_ftrace_filter

You can find all the details in the kernel documentation about ftrace

Federico
  • 3,782
  • 32
  • 46
  • Thank you! Is there any way I can set up the trace to trace the init process when module is loaded? – electro Apr 02 '15 at 22:01
  • no, as far as I know, because module functions are available only after module load. Probably you can filter some internal kernel function that then call your `module_init`, but I don't remember the name of this functions – Federico Apr 07 '15 at 10:35
  • You can use trace_printk to trace. – codexplorer May 24 '18 at 09:54
  • 1
    You can always (for most of the modules) unbind and bind back. In this case all module functions (except its `->init()` chain) will be available. – 0andriy Mar 21 '20 at 18:26
0

Try this command:

echo $$ >> /sys/kernel/debug/tracing/set_ftrace_pid
RBT
  • 24,161
  • 21
  • 159
  • 240