Chinaunix首页 | 论坛 | 博客
  • 博客访问: 163764
  • 博文数量: 67
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 622
  • 用 户 组: 普通用户
  • 注册时间: 2014-11-19 19:12
文章分类

全部博文(67)

分类: LINUX

2015-09-01 13:34:20


strace
    跟踪系统调用和信号,只跟踪系统调用,userspace中的函数不会跟踪。
    常用参数如下:

     -c 统计每一系统调用的所执行的时间,次数和出错的次数等.
 
   -e expr 指定要跟踪的事件,具体格式如下:
   [qualifier=][!]value1[,value2]...
   qualifier可以是trace、abbrev、verbose、raw、signal、read或者write。
   value是qualifier相关的符号或数值。缺省qualifier是trace。!表示取反。
   -eopen等价于-e trace=open,表示只跟踪open系统调用。-etrace=!open是跟踪除open之外的其他系统调用。
       此外value还可以取值all和none。


   -e trace=set
   只跟踪指定的系统调用列表。决定跟踪哪些系统调用时,-c选项很有用。
   trace=open,close,read,write意即只跟踪这四种系统调用,缺省是trace=all
   
   -e trace=file
   以指定文件名做参数的所有系统调用。
   
   -e trace=process
   进程管理相关的事件,如 fork, wait, exec 等.
   
   -e trace=network 所有和网络相关的系统调用
   
   -e trace=signal    signal相关.
   
   -e trace=ipc      IPC相关.
   
   -e abbrev=set
   Abbreviate the output from printing each member of large structures.
   缺省是abbrev=all,-v选项等价于abbrev=none
   
   -e verbose=set
   Dereference structures for the specified set of system calls. 
   The default is verbose=all.
   
   -e raw=set 将指定的系统调用的参数以十六进制显示
   This is mostly useful if you don"t trust the decoding or you need to know the actual numeric value of an argument.
   
   -e signal=set
   只跟踪指定的信号列表,缺省是signal=all。signal=!SIGIO (or signal=!io) 导致 SIGIO 信号不被跟踪
   
   -e read=set 输出从指定文件中读出 的数据.
   Perform a full hexadecimal and ASCII dump of all the data read from 
   file descriptors listed in the specified set. For example, to see all
   input activity on file descriptors 3 and 5 use -e read=3,5. Note that 
   this is independent from the normal tracing of the read(2) system call
   which is controlled by the option -e trace=read.
   
   -e write=set 输出写入到指定文件中的数据.
   Perform a full hexadecimal and ASCII dump of all the data written to 
   file descriptors listed in the specified set. For example, to see all 
   output activity on file descriptors 3 and 5 use -e write=3,5. Note 
   that this is independent from the normal tracing of the write(2) 
   system call which is controlled by the option -e trace=write.
   
   -f   跟踪某个进程时,如果发生fork()调用,则选择跟踪子进程可以参考gdb的set follow-fork-mode设置
   
   -F 
   attempt to follow vforks. Otherwise, vforks will not be followed even if -f has been given.
   
   -ff 
   如果-o file选项有效指定,则跟踪过程中新产生的其他相关进程的信息分别写
   入file.pid,这里pid是各个进程号。
   
   -o filename
   指定保存strace输出信息的文件,默认使用标准错误输出stderr
   
   -p pid
   指定待跟踪的进程号,可以用Ctrl-C终止这种跟踪。可以指定多达32个-p参数同时进行跟踪。
   比如 strace -ff -o output -p 14653 -p 14117
 
   -r 
   Print a relative timestamp upon entry to each system call. This 
   records the time difference between the beginning of successive 
   system calls.
   
   -t   与-r选项类似,只不过-r采用相对时间戳,-t采用绝对时间戳(当前时钟)
   
   -tt  与-t类似,绝对时间戳中包含微秒
   
   -ttt 
   If given thrice, the time printed will include the microseconds and 
   the leading portion will be printed as the number of seconds since 
   the epoch.
   
   -T 显示单个系统调用耗时


用strace调试问题程序时,如程序挂起,但不知由何引起,可用strace -p pid,查看最后一条输入,如果输出完整,则问题不在系统调用上,而在userspace的代码,若最后一条不完整,则是该系统调用挂起。


阅读(992) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~