如何使用ftrace工具跟踪cp file1 file2
之类的命令?
我希望看到使用cp file1 file2
时调用的所有函数,但我不知道该怎么做。任何人都可以帮助我并在终端中记下确切的命令吗?
答案 0 :(得分:4)
使用以下脚本,您可以使用它来删除您想要的任何命令。取自here,我稍微修改了一下,你可以在/tmp/mytrace.txt获得跟踪输出。用法示例:script.sh cp file1 file2
#!/bin/bash
DPATH="/sys/kernel/debug/tracing"
PID=$$
TEMP="/tmp/mytrace.txt"
## Quick basic checks
[ `id -u` -ne 0 ] && { echo "needs to be root" ; exit 1; } # check for root permissions
[ -z $1 ] && { echo "needs process name as argument" ; exit 1; } # check for args to this function
mount | grep -i debugfs &> /dev/null
[ $? -ne 0 ] && { echo "debugfs not mounted, mount it first"; exit 1; } #checks for debugfs mount
# flush existing trace data
echo nop > $DPATH/current_tracer
# set function tracer
echo function_graph > $DPATH/current_tracer
# enable the current tracer
#echo 1 > $DPATH/tracing_on
# write current process id to set_ftrace_pid file
echo $PID > $DPATH/set_ftrace_pid
# start the tracing
echo 1 > $DPATH/tracing_on
# execute the process
exec $* > /dev/null 2>&1 &
#echo "$*"
`cat $DPATH/trace > $TEMP`
echo 0 > $DPATH/tracing_on
echo nop > $DPATH/current_tracer