linux-如何使用ftrace跟踪shell命令的所有事件?
作者:互联网
如何使用ftrace工具跟踪cp file1 file2之类的命令?
我想查看使用cp file1 file2时调用的所有函数,但我不知道该怎么做.谁能帮助我,并在执行该操作的终端上写下确切的命令?
解决方法:
使用以下脚本,您可以使用它来跟踪所需的任何命令.取自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
标签:cp,ftrace,linux 来源: https://codeday.me/bug/20191030/1967956.html