为什么80%的码农都做不了架构师?>>>
# vim /root/.bashrc //添加以下内容
function straceall {
strace $(pidof "${1}" | sed 's/\([0-9]*\)/-p \1/g')
}
# source /root/.bashrc
执行:
# traceall php-fpm
2. 追踪web服务器系统调用情况
# strace -f -F -s 1024 -o nginx-strace /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
# strace -f -F -o php-fpm-strace /usr/local/php/sbin/php-fpm -y /usr/local/php/etc/php-fpm.conf
3. 追踪mysql执行语句
# strace -f -F -ff -o mysqld-strace -s 1024 -p mysql_pid
# find ./ -name "mysqld-strace*" -type f -print |xargs grep -n "SELECT.*FROM"
4. whatisdong---查看程序在干啥
#!/bin/bash
# This script is from http://poormansprofiler.org/
nsamples=1
sleeptime=0
pid=$(pidof $1)
for x in $(seq 1 $nsamples)
do
gdb -ex "set pagination 0" -ex "thread apply all bt" -batch -p $pid
sleep $sleeptime
done | \
awk '
BEGIN { s = ""; }
/^Thread/ { print s; s = ""; }
/^\#/ { if (s != "" ) { s = s "," $4} else { s = $4 } }
END { print s }' | \
sort | uniq -c | sort -r -n -k 1,1
输出:
# profiler.sh mysqld
727 pthread_cond_wait@@GLIBC_2.3.2,cache_thread,put_in_cache=true),handle_one_connection,start_thread,??
4 pthread_cond_wait@@GLIBC_2.3.2,os_event_wait_low,os_aio_simulated_handle,fil_aio_wait,io_handler_thread,start_thread,??
4 ??,??
2 read,my_real_read,my_net_read,do_command,handle_one_connection,start_thread,??
1 pthread_cond_wait@@GLIBC_2.3.2,os_event_wait_low,srv_master_thread,start_thread,??
1 pthread_cond_wait@@GLIBC_2.3.2,MYSQL_BIN_LOG::wait_for_update,mysql_binlog_send,dispatch_command,do_command,handle_one_connection,start_thread,??
1 do_sigwait,sigwait,signal_hand,start_thread,??
1
转载请注明出处: 使用strace追踪多个进程 http://www.ttlsa.com/html/1841.html