Percona-Toolkit 之 pt-pmp


pt-pmp 有两个方便的作用:一是获取进程的堆栈信息,二是对堆栈信息进行汇总。

进程的堆栈信息是通过gdb获取的,所以在获取过程中,会对mysql服务端的性能有一定的影响

pt-pmp脚本本身是用shell写的,用法也比较简单,唯一的要求是服务器上已安装gdb包。

pt-pmp 参数:

[root@hankyoon ~ ]# pt-pmp --help
Usage: pt-pmp [OPTIONS] [FILES]

For more information, 'man pt-pmp' or 'perldoc /usr/bin/pt-pmp'.

Command line options:

  --binary          Which binary to trace.    指定分析的进程名,如果不指定,默认就是mysqld
  --help            Show help and exit.       帮助
  --interval        Number of seconds to sleep between L<"--iterations">.       迭代时间之间的时间间隔
  --iterations      How many traces to gather and aggregate.                    执行gdb命令的次数
  --lines           Aggregate only first specified number of many functions;    指定打印汇总后每一个分类中的头几个函数
                    0=infinity.
  --pid             Process ID of the process to trace; overrides L<"--binary">.指定进程的pid 
  --save-samples    Keep the raw traces in this file after aggregation.         是否将gdb获取的堆栈信息保存在文件中(注意,没有汇总)
  --version         Show version and exit.

Options and values after processing arguments:

  --binary                         mysqld
  --help                           TRUE
  --interval                       0
  --iterations                     1
  --lines                          0
  --pid                            (No value)
  --save-samples                   (No value)
  --version                        FALSE

用法:

1. 汇总pstack获取的结果

 # ps -ef | grep mysqld

 # pstack 7777 > 7777.info

 # pt-pmp 7777.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