Use Strace to track mysqld

Source: Internet
Author: User
Tags fpm

Reprint Please specify source: http://www.ttlsa.com/html/1841.html

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 trace the specified process-f trace by the fork child process system call-F to try to trace the Vfork subprocess system, and when the-F occurs simultaneously, the vfork is not tracked-o-filename default strace outputs the result to stdout. The output can be written to the filename file through-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 plus 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 to output all system calls. By default, some frequently called system calls do not output-s specifies the length of each line of output string, which defaults to 32. The 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 Tracking Multiple process methods: when there are many sub-processes, such as PHP-FPM, Nginx, etc., with strace tracking appears very inconvenient. You can use the following methods to track all child processes.

<textarea class="crayon-plain print-no" style="line-height: 15px !important; overflow: hidden; font-size: 12px !important; z-index: 0; opacity: 0; tab-size: 4; -moz-tab-size: 4; -o-tab-size: 4; -webkit-tab-size: 4;" readonly="" data-settings="dblclick"># VIM/ROOT/.BASHRC//Add the following function Straceall {strace $ (pidof "${1}" | sed ' s/\ ([0-9]*\]/-p \1/g ')}# source/root/.ba SHRC</textarea>
12345 # VIM/ROOT/.BASHRC//Add the following contentfunction straceall { strace $(pidof "${1}" | sed ' s/\([0-9]*\)/-p \1/g ') }# SOURCE/ROOT/.BASHRC

Perform:

<textarea class="crayon-plain print-no" style="line-height: 15px !important; overflow: hidden; font-size: 12px !important; z-index: 0; opacity: 0; tab-size: 4; -moz-tab-size: 4; -o-tab-size: 4; -webkit-tab-size: 4;" readonly="" data-settings="dblclick"># Traceall PHP-FPM</textarea>
1 # Traceall PHP-FPM

2. Tracking Web Server system calls

<textarea class="crayon-plain print-no" style="line-height: 15px !important; overflow: hidden; font-size: 12px !important; z-index: 0; opacity: 0; tab-size: 4; -moz-tab-size: 4; -o-tab-size: 4; -webkit-tab-size: 4;" readonly="" data-settings="dblclick"># 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</textarea>
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

<textarea class="crayon-plain print-no" style="line-height: 15px !important; overflow: hidden; font-size: 12px !important; z-index: 0; opacity: 0; tab-size: 4; -moz-tab-size: 4; -o-tab-size: 4; -webkit-tab-size: 4;" readonly="" data-settings="dblclick"># strace-f-f-ff-o mysqld-strace-s 1024-p mysql_pid# find./-name "mysqld-strace*"-type f-print |xargs grep-n "Select.*from"</textarea>
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

<textarea class="crayon-plain print-no" style="line-height: 15px !important; overflow: hidden; font-size: 12px !important; z-index: 0; opacity: 0; tab-size: 4; -moz-tab-size: 4; -o-tab-size: 4; -webkit-tab-size: 4;" readonly="" data-settings="dblclick">#!/bin/bash# This script was from http://poormansprofiler.org/nsamples=1sleeptime=0pid=$ (Pidof $) for x in $ (seq 1 $ns amples) 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</textarea>
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:

<textarea class="crayon-plain print-no" style="line-height: 15px !important; overflow: hidden; font-size: 12px !important; z-index: 0; opacity: 0; tab-size: 4; -moz-tab-size: 4; -o-tab-size: 4; -webkit-tab-size: 4;" readonly="" data-settings="dblclick"># profiler.sh mysqld727 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</textarea>
123456789 # profiler.sh Mysqld727 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

Use Strace to track mysqld

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.