如何像cp file1 file2
使用 ftrace 工具一样跟踪命令?
我想查看我使用时调用的所有函数,cp file1 file2
但我不知道该怎么做。任何人都可以帮助我并在终端中写下执行此操作的确切命令吗?
使用以下脚本,您可以使用它来跟踪您想要的任何命令。取自这里,我稍作修改,您可以在 /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