Analysis using MySQL run strace and perf Zhouwan Chun perf strace the pstack Pt - PMP are a class of tools [ the root DB01 @ ~ ] # perf Top the Samples: 330. of Event ' CPU-Clock ' , 4000 Hz, the Event COUNT (. Approx): 42,848,685 Lost: 0 / 0 drop : 0 / 0 Overhead the Shared Object the Symbol 21.09 % [ Kernel ] [ K ] vmw_cmdbuf_header_submit 19.02% [kernel] [k] e1000_xmit_frame 15.93% [kernel] [k] _raw_spin_unlock_irqrestore [root@db01 ~]# cp -a /usr/local/mysql/bin/mysqld /usr/local/mysql/bin/mysqld_bak [root@db01 ~]# ls -lh /usr/local/mysql/bin/mysqld{,_bak} -rwxr-xr-x 1 mysql mysql 249M Sep 27 16:53 /usr/local/mysql/bin/mysqld -rwxr-xr-x 1 mysql mysql 249M Sep 27 16:53 /usr/local/mysql/bin/mysqld_bak [root@db01 ~]# strip /usr/local/mysql/bin/mysqld_bak [root@db01 ~]# ls -lh /usr/local/mysql/bin/mysqld{,_bak} -rwxr-xr-x 1 mysql mysql 249M Sep 27 16:53 /usr/local/mysql/bin/mysqld - rwxr - XR - the X- 1 MySQL MySQL 27M Mar 8 10 : 36 / usr / local / MySQL / bin / mysqld_bak mysqld command consists of more than 200 M becomes more than 20 M strace introduction and use of the MySQL start the default start how many threads how conn_id match and os_thread_id use strace observation client SQL execution using the strace observe server-side implementation whereis pt - PMP strace is one for the diagnosis, analysis tools Linux user mode process pstrace losf gdb pstack Python written in pstrace pstack simple to use strace - T -tt -o /tmp/strace.log CMD strace -T -tt CMD 2>&1 |tee /tmp/strace.log strace -T -tt -s 100 -o /tmp/strace.log CMD strace -T -tt -s 100 -ff /tmp/strace.log the CMD the strace - T - TT - S 100 - E the strace = XXX - O / tmp / the strace. log the CMD the MySQL default number of threads started MySQL - S / tmp / mysql.sock - P use SYS; Show Tables; SELECT * from sys.session; SELECT * from performance_schema.threads; user mode thread, the thread running user SELECT thd_id, conn_id, thread_os_id, name from sys.processlist a,performance_schema.threads b where a.thd_id = b.thread_id and conn_id > 0; [dba@localhost:mysql.sock] [(none)]> select thd_id,conn_id,thread_os_id,name -> from sys.processlist a,performance_schema.threads b -> where a.thd_id = b.thread_id and conn_id > 0; +--------+---------+--------------+--------------------------------+ | thd_id | conn_id | thread_os_id | name | +--------+---------+--------------+--------------------------------+ | 26 | 1 | 23452 | thread/sql/compress_gtid_table | | 656 | 631 | 23475 | thread/sql/one_connection | | 657 | 632 | 5081 | thread/sql/one_connection | + - ------ + --------- + -------------- + ------------- + ------------------- . 3 rows in SET ( 0.13 sec) [ DBA @ localhost: mysql.sock ] [ (none) ] > SELECT * from sys.processlist; operating system View PS - T `pidof mysqld` use pstack pstack` pidof mysqld` recommended MySQL 5 or more .7 version [ dba @ localhost: mysql.sock ] [ (none) ] > the SELECT thread_id, namefrom performance_schema.threads; conn_id and os_thread_id match gdb The attach 3711 to get a thread after thread tracking thread to get strace - T - tt - S 100 - the p- 1042 gdb The attach this action will cause the card to track progress. the strace - T - TT - S 100 - . O / . 3711_c log - P 3711 SELECT thd_id, conn_id, PID, program_name from sys.processlist; SELECT * from sys.processlist WHERE PID= 1086 \ G using the SQL execution strace observation client's Development: Why do you respond to DB's so slow it? A large number of slow queries the application side. DBA little embarrassed: Mangqu view show log clean, had nothing? ? ? ~~~~~~ sitting at home, the pot from the sky. MySQL query does not slow, but the application side there are a lot of slow queries, how do? Strace observed using server-side implementation using strace end observed mysqld performed here need to look at the relevant operation io mysqld MySQL: Read , Write, Open InnoDB: pread64, pwrite64 strace - O / tmp / . Zst_strace log - T - TT - F - the trace E = Read , Open , Write, pwrite64, pread64 -mysqld` the pidof `P the strace - C / usr / local / MySQL / bin / mysqld the strace - O / tmp / . zst_strace log - T - TT - FF - P` the pidof mysqld` - FF parameters, tracing the new thread fork when the thread, will produce a new file storage. Using the acquired thread id in the MySQL query and see all doing? the SELECT thread_id, thread_os_id, name from performance_schema.threads the WHERE thread_os_id in ( 15871 ,15872 , 15 873 , 15901 ); LS - L / proc / 3536 / FD / . 11 yum the install ps_mem capture the tcpdump - I eth0 - S 0 TCP Port 3306 - W xxx.cap binding Wireshark PS - T `the pidof mysqld` Top - H - c - the p-mysqld` `pidof