Track multiple processes using Strace

Source: Internet
Author: User
Tags fpm

http://www.ttlsa.com/tools/use-strace-to-track-multiple-processes/Strace is a program debugging tool in the Linux environment that monitors the system calls used by an application and the system information it receives. Trace the entire life cycle of the program runtime, outputting the name of each system call, parameters, return values and elapsed time of execution.

Strace Common parameters:
-P tracks the specified process
-F tracing is called by the fork child process system
-F attempts to trace the Vfork sub-process system, the vfork is not tracked when it appears with-f
-o filename Default strace outputs the result to stdout. The output can be written to the filename file by-O
-FF is often used with the-o option, and system calls from different processes (sub-processes) are output to filename. PID File
-R Prints the relative time of each system call
-T adds time information before each line in the output. The-TT time is determined to the microsecond level. You can also use-TTT to print relative time
-V outputs all system calls. By default, some system calls that are called frequently do not output
-s Specifies the length of each line of output string, default is 32. File name is always output
-C counts the time, number of calls, and number of errors performed by each system call.
-E expr output filter, by expression, you can filter out the output you do not want to

1. Strace tracks multiple process methods:
When there are many sub-processes, such as PHP-FPM, Nginx, and so on, with strace tracking seems very inconvenient. You can use the following methods to track all child processes.

12345 # VIM/ROOT/.BASHRC//Add the following contentfunction straceall { strace $(pidof "${1}" | sed ' s/\([0-9]*\)/-p \1/g ') }# SOURCE/ROOT/.BASHRC

Perform:

1 # Traceall PHP-FPM

2. Tracking Web Server system calls

12 # 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. Track MySQL execution statements

12 # 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---See what the program is doing

1234567891011121314151617 #!/bin/bash# This script was 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:

123456789 # profiler.sh Mysqld727 pthread_cond_wait @@glibc_2.3.2,cache_thread,< Span class= "crayon-v" >put_in_cache=true) Span class= "Crayon-sy" >,handle_one_connectionstart_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

Reprint Please specify source: Use Strace to track multiple processes http://www.ttlsa.com/html/1841.html

Track multiple processes using Strace

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.