• 18. pt-pmp


    pt-pmp 是一个非常简单的工具,可以用来获取MySQL的堆栈信息。
    工具首先获取运行过程中的mysqld堆栈信息,
    然后将相似的线程进行汇总排序,根据调用频繁程度从高到低打印出来。

    查看pt-pmp的源代码,我们可以发现pt-pmp本身是一个shell脚本,底层调用的是gdb,所以我们需要事先安装gdp。

    yum -y install gdb

    在pt-pmp的运行过程过程中,他会短暂的冻结mysqld的主程序,导致MySQL无法响应,
    同时当gdb detach的时候,MySQL存在crash的风险。因此如果在一个很繁忙的生产环境中需要谨慎使用。
    但是如果你的MySQL数据库现在已经停止响应了,那么可以使用pt-pmp去跟踪MySQL的堆栈信息,来分析他为什么hang住。

    如下是我用sysbench压测的时候发现开启pt-pmp之后,MySQL在第203秒和204秒的tps为0,所以生产环境使用一定要谨慎!


    pt-pmp --iterations 1 --interval 1 --lines 3
    --save-samples


    Fri Nov 23 13:42:04 CST 2018
    18 __io_getevents_0_4(libaio.so.1),LinuxAIOHandler::collect(os0file.cc:2500),LinuxAIOHandler::poll(os0file.cc:2646)
    8 pthread_cond_wait,native_cond_wait(thr_cond.h:140),my_cond_wait(thr_cond.h:140)
    6 pthread_cond_wait,wait(os0event.cc:165),os_event::wait_low(os0event.cc:165)
    6 pthread_cond_timedwait,os_event::timed_wait(os0event.cc:285),os_event::wait_time_low(os0event.cc:412)
    1 sigwait(libpthread.so.0),signal_hand(mysqld.cc:2101),pfs_spawn_thread(pfs.cc:2190)
    1 sigwaitinfo(libc.so.6),timer_notify_thread_func(posix_timers.c:77),pfs_spawn_thread(pfs.cc:2190)
    1 poll(libc.so.6),Mysqld_socket_listener::listen_for_connection_event(socket_connection.cc:852),connection_event_loop(connection_acceptor.h:66)
    1 nanosleep(libpthread.so.0),os_thread_sleep(os0thread.cc:279),srv_master_sleep(srv0srv.cc:2330)
    1 __lll_lock_wait(libpthread.so.0),_L_lock_812(libpthread.so.0),pthread_mutex_lock(libpthread.so.0)
    1 fsync(libpthread.so.0),os_file_fsync_posix(os0file.cc:3053),os_file_flush_func(os0file.cc:3053)

    [ 10s] threads: 8, tps: 136.72, reads/s: 1925.27, writes/s: 550.08, response time: 251.43ms (99%)
    [ 21s] threads: 8, tps: 79.34, reads/s: 1110.72, writes/s: 317.35, response time: 415.50ms (99%)
    [ 30s] threads: 8, tps: 76.82, reads/s: 1075.46, writes/s: 306.50, response time: 2996.23ms (99%)
    [ 40s] threads: 8, tps: 67.40, reads/s: 943.56, writes/s: 270.29, response time: 5914.77ms (99%)
    [ 50s] threads: 8, tps: 103.60, reads/s: 1450.34, writes/s: 414.38, response time: 244.90ms (99%)
    [ 60s] threads: 8, tps: 118.90, reads/s: 1664.62, writes/s: 475.61, response time: 138.50ms (99%)

    打印堆栈,对系统有很大影响,慎用!!!


    2、参数说明
    --binary

    short form: -b; type: string; default: mysqld
    Which binary to trace.
    指定哪个进行进行跟踪,如果不指定,他默认去寻找mysqld进程。因此pt-pmp也可以跟踪其他进程。

    --help

    Show help and exit.
    打印帮助信息

    --interval

    short form: -s; type: int; default: 0
    Number of seconds to sleep between --iterations.
    每次跟踪的间隔时间,默认为不休眠

    --iterations

    short form: -i; type: int; default: 1
    How many traces to gather and aggregate.
    总共的跟踪次数,默认为跟踪1次

    --lines

    short form: -l; type: int; default: 0
    Aggregate only first specified number of many functions; 0=infinity.
    pt-pmp在第二步聚合的时候只打印相应分类的几个方法,默认会全部打印出来,你可以让他只打印前面2个


    --pid

    short form: -p; type: int
    Process ID of the process to trace; overrides --binary.
    指定哪个进程号进行跟踪,这个参数会覆盖--binary指定的参数值,因此指定pid和binary其中一个即可

    --save-samples

    short form: -k; type: string
    Keep the raw traces in this file after aggregation.
    将跟踪结果保存到文本文件中

    --version

    Show version and exit.
    输出版本信息

    wechat: nick753159 qq: 417966852 email: nzq42@qq.com base: shanghai
  • 相关阅读:
    调用Type.InvokeMember()时出现MissingMethodException
    C#学习之Delegate
    WCF之元数据交换 (Metadata Exchange)
    定义Enum的开始和结束,这样就能循环Enum了
    定制自己的Visual Studio的Debugger Visualizer
    C#中 #if DEBUG 和 Conditional("DEBUG")的区别
    从哪里开始学习Windows 8?(zz)
    Macro 小总结
    WPF应用的图标
    如何把 Visutal studio中的“printonbreakpoint”消息打印在程序的任何地方
  • 原文地址:https://www.cnblogs.com/cyberbit/p/pt-pmp.html
Copyright © 2020-2023  润新知