Does ftrace allow capture of system call arguments to the Linux kernel, or only function names?

无人久伴 提交于 2019-12-04 06:01:55

I have limited experience with ftrace, although I have used it for for function stack traces and latency issues. (People with more experience can possibly suggest) Its pretty much the same experience using trace-cmd and kernelshark.

However, if you want to trace syscalls, function params, kernel APIs and return values etc. within the kernel space a better choice would be to go with systemtap. It has an extensive list of Samples & Doc which is good for function call tracing, argument values passed etc. You may want to look at some samples and taylor them to your requirement. See general/para-callgraph-verbose.stp and process/sleeptime.stp

"

general/para-callgraph-verbose.stp - Callgraph Tracing with Verbose Arguments keywords: TRACE CALLGRAPH

Print a timed per-thread microsecond-timed callgraph, complete with pretty-printed function parameters and return values. The first parameter names the function probe points to trace. The optional second parameter names the probe points for trigger functions, which acts to enable tracing for only those functions that occur while the current thread is nested within the trigger.

stap para-callgraph-verbose.stp 'kernel.function("*@fs/proc*.c")' \
'kernel.function("vfs_read")' -c "cat /proc/sys/vm/* || true"

process/strace.stp - Trace system calls keywords: _BEST PROCESS SYSCALL

The script loosely emulates strace, when applied to individual processes or hierarchies (via -c/-x), or the entire system (without -c/-x). A few output configuration parameters may be set with -G.

stap strace.stp -c "sleep 1"

"

Note you will need to install the correct version of the debug kernel and kernel-devel rpms/deb for stap to work correctly. For this just use stap-prep and install the dependencies shown depending on the flavour you are on.

Give "STRACE" a shot. It monitors the interaction betn userspace and kernel.

A sample output can be found here : http://www.thegeekstuff.com/2011/11/strace-examples/

Alternatively, Since you are saying specific system calls, i am assuming you are interested in only a couple of them.

If you have to use FTRACE alone, you can add your own trace event in the relevant header files in include/trace/events/.h, using TRACE_EVENT macro and call this new trace function during the sytem call handler inside the kernel.

Of course, this requires some code modification, but should be easy enough to get you going quickly.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!