• 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

       

       



  • 相关阅读:
    指针总结与地址
    寻址方式
    为什么要有指针?
    指针与变量
    Wired Memory
    Memory Usage Performance Guidelines
    内存管理与运行时
    Java jvm 内存回收机制
    GC详解及Minor GC和Full GC触发条件总结
    Java的内存回收机制详解X
  • 原文地址:https://www.cnblogs.com/ivictor/p/6012183.html
Copyright © 2020-2023  润新知