pt-pmp


pt-pmp有兩方面的作用:一是獲取進程的堆棧信息,二是對這些堆棧信息進行匯總。

進程的堆棧信息是利用gdb獲取的,所以在獲取的過程中,會對mysql服務端的性能有一定的影響。

用官方的話說:

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.

 

pt-pmp腳本本身是用shell寫的,用法也比較簡單,唯一的要求是服務器上已安裝gdb包。

不然會報如下錯誤:

[root@localhost ~]# pt-pmp --binary mysqld
Sat Oct 29 17:32:34 CST 2016
/usr/local/bin/pt-pmp: line 663: gdb: command not found

 

下面看看其具體參數

--binary

指定分析的進程名,如果不指定,則默認是mysqld,從這個參數可以看出,pt-pmp不僅僅適用於mysqld。

short form: -b; type: string; default: mysqld
Which binary to trace.

 

--help

Show help and exit.

 

--interval

迭代時間之間的間隔,從源代碼也可以看出

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是下面--iterations參數,而$OPT_INTERVAL即sleep的時間。

short form: -s; type: int; default: 0
Number of seconds to sleep between --iterations.

 

 --iterations

從上面的源代碼可以看出,所謂的迭代其實就是執行gdb命令的次數

short form: -i; type: int; default: 1
How many traces to gather and aggregate.

 

--lines

指定打印匯總后每一個分類中的頭幾個函數。

譬如原始匯總信息如下:

# 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)
...

如果指定--line參數,則輸出如下:

# 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: 0
Aggregate only first specified number of many functions; 0=infinity.

 

--pid

指定進程的pid,該參數會覆蓋--binary參數。

short form: -p; type: int
Process ID of the process to trace; overrides --binary.

 

--save-samples

是否將gdb獲取的原始堆棧信息(注意,沒有匯總)保存在文件中。

short form: -k; type: string
Keep the raw traces in this file after aggregation.

 

--version

Show version and exit.

 

所以,總結其可用用法如下:

1. 匯總pstack獲取的結果

   # ps -ef |grep mysqld

   # pstack 10230 > 10230.info

   # pt-pmp 10230.info 

2. 直接根據進程名匯總堆棧信息

   # pt-pmp --binary mysqld

3. 上述命令只是一次迭代的結果,如果要迭代多次,且每次相隔1s,可指定如下:

   # pt-pmp --binary mysqld --iterations 2 --interval 1

4. 如果要同時保留匯總前的堆棧信息,可指定--save-samples參數

   # pt-pmp --binary sshd --save-samples sshd.txt

   

   




免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM