ftrace is powerful tool used for debugging in Linux. Lets go through a simple example of generating a function graph using ftrace.
Following steps will help in generating function graph of selected linux function.
Enable Tracing:
In this example I have selected the filter function as "generic_make_request". As such the step 3 sets the graph function to "generic_make_request" linux function. Then we have set the graph depth to 10 in step 4. Step 5 sets the current tracer as "function_graph". After all these are set we enable the tracing.
Action:
Now we perform action for which we wanted a linux trace. In this example we perform an I/O with dd command. This command will hit the generic_make_request function and the file /sys/kernel/debug/tracing/trace will be filled with the function graph.
Disable Tracing:
Steps 9, 10, 11 will disable the tracing
how ftrace works:
http://www.linuxplumbersconf.org/2014/ocw/system/presentations/1773/original/ftrace-kernel-hooks-2014.pdf
References
http://lwn.net/Articles/365835/
http://lwn.net/Articles/366796/
http://lwn.net/Articles/370423/
Stack Tracer:
https://lwn.net/Articles/366796/
To enable the stack tracer, echo 1 into /proc/sys/kernel/stack_tracer_enabled
/sys/kernel/debug/tracing # cat stack_trace
Depth Size Location (25 entries)
----- ---- --------
0) 2736 120 kmem_cache_alloc_node_trace+0x306/0x5c0
...
...
23) 240 64 kthread+0x11a/0x130
24) 176 176 ret_from_fork+0x35/0x40
/sys/kernel/debug/tracing # cat stack_max_size
2736
Following steps will help in generating function graph of selected linux function.
- cd /sys/kernel/debug/tracing
- cat /dev/null > trace
- echo generic_make_request > set_graph_function
- echo 10 > max_graph_depth
- echo function_graph > current_tracer
- echo 1 > tracing_on
- dd if=/dev/sddk of=~/test bs=512 count=5
- cp trace ~/dd_trace_depth10
- echo 0 > tracing_on
- echo > set_graph_function
- echo 0 > max_graph_depth
- cat /dev/null > trace
Enable Tracing:
In this example I have selected the filter function as "generic_make_request". As such the step 3 sets the graph function to "generic_make_request" linux function. Then we have set the graph depth to 10 in step 4. Step 5 sets the current tracer as "function_graph". After all these are set we enable the tracing.
Action:
Now we perform action for which we wanted a linux trace. In this example we perform an I/O with dd command. This command will hit the generic_make_request function and the file /sys/kernel/debug/tracing/trace will be filled with the function graph.
Disable Tracing:
Steps 9, 10, 11 will disable the tracing
how ftrace works:
http://www.linuxplumbersconf.org/2014/ocw/system/presentations/1773/original/ftrace-kernel-hooks-2014.pdf
References
http://lwn.net/Articles/365835/
http://lwn.net/Articles/366796/
http://lwn.net/Articles/370423/
Stack Tracer:
https://lwn.net/Articles/366796/
To enable the stack tracer, echo 1 into /proc/sys/kernel/stack_tracer_enabled
/sys/kernel/debug/tracing # cat stack_trace
Depth Size Location (25 entries)
----- ---- --------
0) 2736 120 kmem_cache_alloc_node_trace+0x306/0x5c0
...
...
23) 240 64 kthread+0x11a/0x130
24) 176 176 ret_from_fork+0x35/0x40
/sys/kernel/debug/tracing # cat stack_max_size
2736
No comments:
Post a Comment