上一篇: Nginx的WordPress配置
在linux下用strace命令来追踪程序或进程的执行过程
[ 2010/08/23 09:33 | by selboo ]
在linux下有一个strace命令,可以用来追踪程序或进程的执行过程,从中查找和追踪程序的bug,及运行中的瓶颈等。
命令用法,主要有两种方式:
1. strace 程序
strace会运行这个程序,并追踪。
2. strace -p pid
这是追踪一个已经运行的程序。
另外还有一些参数也很有用,如-c可以生成一个统计结果,-o file可以把追踪信息输出到一个文件内。
一个例子:
[root@74-82-173-217 wordpress]# strace -p 9811
Process 9811 attached - interrupt to quit
rt_sigsuspend([] <unfinished ...>
Process 9811 detached
[root@74-82-173-217 wordpress]# strace -p 9812
Process 9812 attached - interrupt to quit
gettimeofday({1282527088, 152573}, NULL) = 0
epoll_wait(8, {{EPOLLIN, {u32=1087393800, u64=1087393800}}}, 512, 19299) = 1
gettimeofday({1282527089, 483627}, NULL) = 0
accept(5, {sa_family=AF_INET, sin_port=htons(41234), sin_addr=inet_addr("174.37.205.87")}, [16]) = 21
ioctl(21, FIONBIO, [1]) = 0
epoll_ctl(8, EPOLL_CTL_ADD, 21, {EPOLLIN|EPOLLET, {u32=1087393985, u64=578985575685574849}}) = 0
epoll_wait(8, {{EPOLLIN, {u32=1087393985, u64=578985575685574849}}}, 512, 17968) = 1
gettimeofday({1282527089, 491507}, NULL) = 0
recv(21, "GET / HTTP/1.1\r\nUser-Agent: Mozi"..., 32768, 0) = 353
stat64("/wwwroot/selboo/tmpselboo/index.php", {st_mode=S_IFREG|0755, st_size=8862, ...}) = 0
epoll_ctl(8, EPOLL_CTL_MOD, 21, {EPOLLIN|EPOLLOUT|EPOLLET, {u32=1087393985, u64=579513225302790337}}) = 0
getsockname(21, {sa_family=AF_INET, sin_port=htons(80), sin_addr=inet_addr("74.82.173.217")}, [16]) = 0
socket(PF_FILE, SOCK_STREAM, 0) = 34
ioctl(34, FIONBIO, [1]) = 0
epoll_ctl(8, EPOLL_CTL_ADD, 34, {EPOLLIN|EPOLLOUT|EPOLLET, {u32=1087396285, u64=579513822303246781}}) = 0
connect(34, {sa_family=AF_FILE, path="/tmp/php-cgi.sock"...}, 110) = 0
getsockopt(34, SOL_SOCKET, SO_ERROR, [0], [4]) = 0
writev(34, [{"\1\1\0\1\0\10\0\0\0\1\0\0\0\0\0\0\1\4\0\1\3\t\7\0\21\7GATEWA"..., 824}], 1) = 824
epoll_wait(8, {{EPOLLOUT, {u32=1087396285, u64=579513822303246781}}, {EPOLLOUT, {u32=1087393985, u64=579513225302790337}}}, 512, 17960) = 2
gettimeofday({1282527089, 493838}, NULL) = 0
recv(21, 0xbfa079cb, 1, MSG_PEEK) = -1 EAGAIN (Resource temporarily unavailable)
epoll_wait(8, {{EPOLLIN|EPOLLOUT, {u32=1087396285, u64=579513822303246781}}}, 512, 17958) = 1
gettimeofday({1282527089, 567134}, NULL) = 0
recv(34, "\1\6\0\1\37\370\0\0Expires: Mon, 26 Jul 199"..., 65536, 0) = 8192
readv(34, 0xbfa07878, 1) = -1 EAGAIN (Resource temporarily unavailable)
epoll_wait(8, {{EPOLLIN|EPOLLOUT, {u32=1087396285, u64=579513822303246781}}}, 512, 17884) = 1
gettimeofday({1282527089, 568199}, NULL) = 0
readv(34, [{"\1\6\0\1\0\242\6\0\212\246t\356\337\255\365\344\263=\370\213B\255\324\27\354\335w\360\263=%\230"..., 57344}], 1) = 176
readv(34, 0xbfa078c8, 1) = -1 EAGAIN (Resource temporarily unavailable)
epoll_wait(8, {{EPOLLIN|EPOLLOUT, {u32=1087396285, u64=579513822303246781}}}, 512, 17883) = 1
gettimeofday({1282527089, 568561}, NULL) = 0
readv(34, [{"\1\3\0\1\0\10\0\0\0\0\0\0\0\255\365\344\304\210\326Q}\271lQ\234\263\31\24\265\262I\302"..., 57168}], 1) = 16
readv(34, 0xbfa078c8, 1) = -1 EAGAIN (Resource temporarily unavailable)
epoll_wait(8, {{EPOLLIN|EPOLLOUT, {u32=1087396285, u64=579513822303246781}}}, 512, 17883) = 1
gettimeofday({1282527089, 568917}, NULL) = 0