Pt-pmp, mysqlptpmp
Pt-pmp has two functions: Obtain the stack information of a process, and summarize the stack information.
The stack information of a process is obtained using gdb. Therefore, the performance of the mysql server may be affected during the process.
In official words:
This will freeze the program for some period of time, ranging from a second or so to much longer on very busy systems with a lot of memory and many threads in the program.In addition to freezing the server, there is also some risk of the server crashing or performing badly after GDB detaches from it.
The pt-pmp script is written in shell and is easy to use. The only requirement is that the gdb package has been installed on the server.
Otherwise, the following error will be reported:
[root@localhost ~]# pt-pmp --binary mysqldSat Oct 29 17:32:34 CST 2016/usr/local/bin/pt-pmp: line 663: gdb: command not found
The following describes the specific parameters.
-- Binary
Specifies the name of the analysis process. If not specified, the default value is mysqld. From this parameter, we can see that pt-pmp is not only applicable to mysqld.
short form: -b; type: string; default: mysqldWhich binary to trace.
-- Help
Show help and exit.
-- Interval
The interval between iterations can be seen from the source code.
for x in $(_seq $OPT_ITERATIONS); do gdb -ex "set pagination 0" \ -ex "thread apply all bt" \ -batch \ -p $OPT_PID \ >> "$output_file" date +'TS %N.%s %F %T' >> "$output_file" sleep $OPT_INTERVAL done
$ OPT_ITERATIONS is the following -- iterations parameter, and $ OPT_INTERVAL is the sleep time.
short form: -s; type: int; default: 0Number of seconds to sleep between --iterations.
-- Iterations
From the source code, we can see that the so-called iteration is actually the number of times the gdb command is executed.
short form: -i; type: int; default: 1How many traces to gather and aggregate.
-- Lines
Specifies the first functions of each category after the summary is printed.
For example, the original summary information is as follows:
# pt-pmp 1.txt 1928 poll(libc.so.6),vio_io_wait(viosocket.c:771),vio_socket_io_wait(viosocket.c:68),vio_read(viosocket.c:123),net_read_raw_loop(net_serv.cc:669),net_read_packet_header(net_serv.cc:751),net_read_packet(net_serv.cc:751),my_net_read(net_serv.cc:894),do_command(sql_parse.cc:969),do_handle_one_connection(sql_connect.cc:982),handle_one_connection(sql_connect.cc:898),pfs_spawn_thread(pfs.cc:1860),start_thread(libpthread.so.0),clone(libc.so.6)
80 libaio::??(libaio.so.1),os_aio_linux_collect(os0file.cc:4977),os_aio_linux_handle(os0file.cc:4977),fil_aio_wait(fil0fil.cc:5809),io_handler_thread(srv0start.cc:492),start_thread(libpthread.so.0),clone(libc.so.6)
69 poll(libc.so.6),vio_io_wait,vio_socket_io_wait,vio_read,net_read_raw_loop,net_read_packet,my_net_read,do_command,do_handle_one_connection,handle_one_connection,pfs_spawn_thread,start_thread(libpthread.so.0),clone(libc.so.6)
...
If the -- line parameter is specified, the output is as follows:
# pt-pmp --lines 2 1.txt 1928 poll(libc.so.6),vio_io_wait(viosocket.c:771) 80 libaio::??(libaio.so.1),os_aio_linux_collect(os0file.cc:4977) 69 poll(libc.so.6),vio_io_wait
short form: -l; type: int; default: 0Aggregate only first specified number of many functions; 0=infinity.
-- Pid
Specifies the pid of the process. This parameter overwrites the -- binary parameter.
short form: -p; type: intProcess ID of the process to trace; overrides --binary.
-- Save-samples
Whether to save the original stack information obtained by gdb (Note: There is no summary) in the file.
short form: -k; type: stringKeep the raw traces in this file after aggregation.
-- Version
Show version and exit.
Therefore, the available usage is summarized as follows:
1. Summarize the results obtained by pstack.
# Ps-ef | grep mysqld
# Pstack 10230> 10230.info
# Pt-pmp 10230.info
2. Summarize stack information directly based on process name
# Pt-pmp -- binary mysqld
3. The preceding command is only the result of one iteration. To iterate multiple times and every iteration is 1 s, you can specify the following:
# Pt-pmp -- binary mysqld -- iterations 2 -- interval 1
4. If you want to retain the stack information before the aggregation, you can specify the -- save-samples parameter.
# Pt-pmp -- binary sshd -- save-samples sshd.txt