Use strace to track multiple processes

strace is a debugging tool in the Linux environment, an application used to monitor the use of system calls and system information it receives. The entire life cycle of the tracking program is running, the output of each system call name, parameters, return values ​​and execution time consumed. strace common parameters: -p -f tracking process specified by the call tracking system -F fork child process child process tries to track vfork system calls inhalation, the event in conjunction with -f, vfork not be tracked strace -o filename will default to output stdout. Output can be written to by -o filename file -ff often used with the -o option, a different process (child process) calls generated output relative to time filename.PID print each file -r -t a system call each row in the output time information before adding. -tt to microsecond time determination. You can also use relative time -v -ttt print output all system calls. By default, the system calls for frequently not output -s specified length of each row of the output string, the default is 32. File name has been all the time -c statistical output for each system call execution, the number of calls, the number of errors. -e expr output filter, through expression, you can filter out out you do not want to output 1. strace to track multiple processes: When multiple children under the circumstances, such as php-fpm, nginx, etc., is very used strace to track inconvenient. You can use the following method to keep track of all child processes.
# vim /root/.bashrc //添加以下内容
function straceall {
strace $(pidof "${1}" | sed 's/\([0-9]*\)/-p \1/g')
}
# source /root/.bashrc
carried out:
# traceall php-fpm
2. The web server system to track calls case
# 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. Execute the statement tracking 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 --- Viewer in doing
#!/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
Output:
# 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
Please indicate the source: use strace to track multiple processes  http://www.ttlsa.com/html/1841.html

Reproduced in: https: //my.oschina.net/766/blog/210931

Guess you like

Origin blog.csdn.net/weixin_33725515/article/details/91492959