Preface
 
    Sometimes we need to know the details of a program(porcess) when it is running even it's on the edge of crach.There's a lot of tools can be used to do these kind of job such as truss,strace,ltrace,pstack,gstack,gdb,etc.Truss and strace is focus on system call and signal generation whereas pstack,gstack,gdb are relevant with function call.Actually,pstack is a soft link of gstack,and gstack is a shell packaging script of gdb.
 
Introduce
 
    pt-pmp is also relies on linux gdb.It's a tool which aggregate gdb statck traces for a specified program especially for MySQL.pt-pmp can create and summarize full stack traces of linux process by which we can diagnose what the process is waiting for.It is mostly used in performance tuning scenarios.
 
Procedure
 
Usage
 pt-pmp [OPTIONS] [FILES]
Parameters(few parameters in this tool)
 --binary //Specify which binary program to trace(default 'mysqld').
--pid //Specify a process id to trace.
--iterations //Specify trace times(default "1").
--interval //Number of seconds every time(default "0").
--lines //Specify the number of functions to trace(default "0" means infinite).
--save-samples //output aggregation into a file for later analysis.
Exapmle
 
Trace gdb stack of mysqld into a file(start mysqld and then execute pt-pmp).
 [root@zlm1 :: ~]
#pt-pmp --save-samples pmp.log
Sun Jul :: CEST
/usr/bin/pt-pmp: line : gdb: command not found //gdb package is not installed. [root@zlm1 :: ~]
#yum install gdb //Install gdb package first.
//Omitted
Installed:
gdb.x86_64 :7.6.-.el7 Complete! [root@zlm1 :: ~]
#pt-pmp --save-samples pmp.log
Sun Jul :: CEST
__io_getevents_0_4(libaio.so.),LinuxAIOHandler::collect(os0file.cc:),LinuxAIOHandler::poll(os0file.cc:),os_aio_linux_handler(os0file.cc:),os_aio_handler(os0file.cc:),fil_aio_wait(fil0fil.cc:),io_handler_thread(srv0start.cc:),start_thread(libpthread.so.),clone(libc.so.)
pthread_cond_wait,wait(os0event.cc:),os_event::wait_low(os0event.cc:),srv_worker_thread(srv0srv.cc:),start_thread(libpthread.so.),clone(libc.so.)
sigwait(libpthread.so.),signal_hand(mysqld.cc:),pfs_spawn_thread(pfs.cc:),start_thread(libpthread.so.),clone(libc.so.)
sigwaitinfo(libc.so.),timer_notify_thread_func(posix_timers.c:),pfs_spawn_thread(pfs.cc:),start_thread(libpthread.so.),clone(libc.so.)
pthread_cond_wait,wait(os0event.cc:),os_event::wait_low(os0event.cc:),srv_purge_coordinator_suspend(srv0srv.cc:),srv_purge_coordinator_thread(srv0srv.cc:),start_thread(libpthread.so.),clone(libc.so.)
pthread_cond_wait,wait(os0event.cc:),os_event::wait_low(os0event.cc:),buf_resize_thread(buf0buf.cc:),start_thread(libpthread.so.),clone(libc.so.)
pthread_cond_wait,wait(os0event.cc:),os_event::wait_low(os0event.cc:),buf_dump_thread(buf0dump.cc:),start_thread(libpthread.so.),clone(libc.so.)
pthread_cond_wait,native_cond_wait(thr_cond.h:),my_cond_wait(thr_cond.h:),inline_mysql_cond_wait(thr_cond.h:),compress_gtid_table(thr_cond.h:),pfs_spawn_thread(pfs.cc:),start_thread(libpthread.so.),clone(libc.so.)
pthread_cond_timedwait,os_event::timed_wait(os0event.cc:),os_event::wait_time_low(os0event.cc:),srv_monitor_thread(srv0srv.cc:),start_thread(libpthread.so.),clone(libc.so.)
pthread_cond_timedwait,os_event::timed_wait(os0event.cc:),os_event::wait_time_low(os0event.cc:),srv_error_monitor_thread(srv0srv.cc:),start_thread(libpthread.so.),clone(libc.so.)
pthread_cond_timedwait,os_event::timed_wait(os0event.cc:),os_event::wait_time_low(os0event.cc:),pc_sleep_if_needed(buf0flu.cc:),buf_flush_page_cleaner_coordinator(buf0flu.cc:),start_thread(libpthread.so.),clone(libc.so.)
pthread_cond_timedwait,os_event::timed_wait(os0event.cc:),os_event::wait_time_low(os0event.cc:),lock_wait_timeout_thread(lock0wait.cc:),start_thread(libpthread.so.),clone(libc.so.)
pthread_cond_timedwait,os_event::timed_wait(os0event.cc:),os_event::wait_time_low(os0event.cc:),ib_wqueue_timedwait(ut0wqueue.cc:),fts_optimize_thread(fts0opt.cc:),start_thread(libpthread.so.),clone(libc.so.)
pthread_cond_timedwait,os_event::timed_wait(os0event.cc:),os_event::wait_time_low(os0event.cc:),dict_stats_thread(dict0stats_bg.cc:),start_thread(libpthread.so.),clone(libc.so.)
poll(libc.so.),vio_io_wait(viosocket.c:),vio_socket_io_wait(viosocket.c:),vio_read(viosocket.c:),net_read_raw_loop(net_serv.cc:),net_read_packet_header(net_serv.cc:),net_read_packet(net_serv.cc:),my_net_read(net_serv.cc:),Protocol_classic::read_packet(protocol_classic.cc:),Protocol_classic::get_command(protocol_classic.cc:),do_command(sql_parse.cc:),handle_connection(connection_handler_per_thread.cc:),pfs_spawn_thread(pfs.cc:),start_thread(libpthread.so.),clone(libc.so.)
poll(libc.so.),Mysqld_socket_listener::listen_for_connection_event(socket_connection.cc:),connection_event_loop(connection_acceptor.h:),mysqld_main(connection_acceptor.h:),__libc_start_main(libc.so.),_start
nanosleep(libpthread.so.),os_thread_sleep(os0thread.cc:),srv_master_sleep(srv0srv.cc:),srv_master_thread(srv0srv.cc:),start_thread(libpthread.so.),clone(libc.so.) //Above is the messages outupted on screen.All the contents is different functions relevant with linux and mysqld.
//The output sorts with rules of most-frequen first.
//The combination of function stacks lead by "__io_getevents_0_4(libaio.so.1)"(which is relevant with io) appears 10 times.
Check the content of output file.
#more pmp.log
TS 845703637.1530408066 -- ::
[New LWP ]
[New LWP ]
[New LWP ]
[New LWP ]
[New LWP ]
[New LWP ]
[New LWP ]
[New LWP ]
[New LWP ]
[New LWP ]
[New LWP ]
[New LWP ]
[New LWP ]
[New LWP ]
[New LWP ]
[New LWP ]
[New LWP ]
[New LWP ]
[New LWP ]
[New LWP ]
[New LWP ]
[New LWP ]
[New LWP ]
[New LWP ]
[New LWP ]
[New LWP ]
[New LWP ] //We got 28 new LWP from 3822 to 3981.
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
0x00007f50efe74b7d in poll () from /lib64/libc.so. Thread (Thread 0x7f50e7ec1700 (LWP )): //It's the last thread in pmp.log file here.
# 0x00007f50efdbf7da in sigwaitinfo () from /lib64/libc.so.
# 0x0000000000f5171b in timer_notify_thread_func (arg=<optimized out>) at /export/home/pb2/build/sb_0--1514433850.9/mysql-5.7./mysys/posix_timers.c:
# 0x0000000000f707b4 in pfs_spawn_thread (arg=0x30cb000) at /export/home/pb2/build/sb_0--1514433850.9/mysql-5.7./storage/perfschema/pfs.cc:
# 0x00007f50f13c1df5 in start_thread () from /lib64/libpthread.so.
# 0x00007f50efe7f1ad in clone () from /lib64/libc.so. Thread (Thread 0x7f50ded07700 (LWP )):
# 0x00007f50f11b8644 in __io_getevents_0_4 () from /lib64/libaio.so.
# 0x000000000106a514 in LinuxAIOHandler::collect (this=0x7f50ded06e10) at /export/home/pb2/build/sb_0--1514433850.9/mysql-5.7./storage/innobase/os/os0file.cc:
# 0x000000000106bc34 in LinuxAIOHandler::poll (this=0x7f50ded06e10, m1=0x7f50ded06ec8, m2=0x7f50ded06ec0, request=0x7f50ded06e90) at /export/home/pb2/build/sb_0--1514433850.9/mysql-5.7./storage/innobase/os/os0file.cc:
# 0x000000000106d65c in os_aio_linux_handler (request=0x7f50ded06e90, m2=0x7f50ded06ec0, m1=0x7f50ded06ec8, global_segment=) at /export/home/pb2/build/sb_0--1514433850.9/mysql-5.7./storage/innobase/os/os0file.cc:
# os_aio_handler (segment=, m1=0x7f50ded06ec8, m2=0x7f50ded06ec0, request=0x7f50ded06e90) at /export/home/pb2/build/sb_0--1514433850.9/mysql-5.7./storage/innobase/os/os0file.cc:
# 0x000000000120196d in fil_aio_wait (segment=) at /export/home/pb2/build/sb_0--1514433850.9/mysql-5.7./storage/innobase/fil/fil0fil.cc:
# 0x000000000110e980 in io_handler_thread (arg=<optimized out>) at /export/home/pb2/build/sb_0--1514433850.9/mysql-5.7./storage/innobase/srv/srv0start.cc:
# 0x00007f50f13c1df5 in start_thread () from /lib64/libpthread.so.
# 0x00007f50efe7f1ad in clone () from /lib64/libc.so. Thread (Thread 0x7f50de506700 (LWP )):
# 0x00007f50f11b8644 in __io_getevents_0_4 () from /lib64/libaio.so.
# 0x000000000106a514 in LinuxAIOHandler::collect (this=0x7f50de505e10) at /export/home/pb2/build/sb_0--1514433850.9/mysql-5.7./storage/innobase/os/os0file.cc:
# 0x000000000106bc34 in LinuxAIOHandler::poll (this=0x7f50de505e10, m1=0x7f50de505ec8, m2=0x7f50de505ec0, request=0x7f50de505e90) at /export/home/pb2/build/sb_0--1514433850.9/mysql-5.7./storage/innobase/os/os0file.cc:
# 0x000000000106d65c in os_aio_linux_handler (request=0x7f50de505e90, m2=0x7f50de505ec0, m1=0x7f50de505ec8, global_segment=) at /export/home/pb2/build/sb_0--1514433850.9/mysql-5.7./storage/innobase/os/os0file.cc:
# os_aio_handler (segment=, m1=0x7f50de505ec8, m2=0x7f50de505ec0, request=0x7f50de505e90) at /export/home/pb2/build/sb_0--1514433850.9/mysql-5.7./storage/innobase/os/os0file.cc:
# 0x000000000120196d in fil_aio_wait (segment=) at /export/home/pb2/build/sb_0--1514433850.9/mysql-5.7./storage/innobase/fil/fil0fil.cc:
# 0x000000000110e980 in io_handler_thread (arg=<optimized out>) at /export/home/pb2/build/sb_0--1514433850.9/mysql-5.7./storage/innobase/srv/srv0start.cc:
# 0x00007f50f13c1df5 in start_thread () from /lib64/libpthread.so.
# 0x00007f50efe7f1ad in clone () from /lib64/libc.so. //Omitted. Thread (Thread 0x7f50deeb2700 (LWP )):
# 0x00007f50f13c8ec1 in sigwait () from /lib64/libpthread.so.
# 0x00000000007c357b in signal_hand (arg=<optimized out>) at /export/home/pb2/build/sb_0--1514433850.9/mysql-5.7./sql/mysqld.cc:
# 0x0000000000f707b4 in pfs_spawn_thread (arg=0x386a740) at /export/home/pb2/build/sb_0--1514433850.9/mysql-5.7./storage/perfschema/pfs.cc:
# 0x00007f50f13c1df5 in start_thread () from /lib64/libpthread.so.
# 0x00007f50efe7f1ad in clone () from /lib64/libc.so. Thread (Thread 0x7f50be7fc700 (LWP )):
# 0x00007f50f13c5705 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.
# 0x0000000000ebe6f5 in native_cond_wait (mutex=<optimized out>, cond=<optimized out>) at /export/home/pb2/build/sb_0--1514433850.9/mysql-5.7./include/thr_cond.h:
# my_cond_wait (mp=<optimized out>, cond=<optimized out>) at /export/home/pb2/build/sb_0--1514433850.9/mysql-5.7./include/thr_cond.h:
# inline_mysql_cond_wait (src_line=, src_file=0x15d92e0 "/export/home/pb2/build/sb_0-26514852-1514433850.9/mysql-5.7.21/sql/rpl_gtid_persist.cc", mutex=<optimized out>, that=<optimized out>) at /export/home/pb2/build/sb_0--1514433850.9/mysql-5.7./include/mysql/psi/mysql_thread.h:
# compress_gtid_table (p_thd=<optimized out>) at /export/home/pb2/build/sb_0--1514433850.9/mysql-5.7./sql/rpl_gtid_persist.cc:
# 0x0000000000f707b4 in pfs_spawn_thread (arg=0x386a740) at /export/home/pb2/build/sb_0--1514433850.9/mysql-5.7./storage/perfschema/pfs.cc:
# 0x00007f50f13c1df5 in start_thread () from /lib64/libpthread.so.
# 0x00007f50efe7f1ad in clone () from /lib64/libc.so. Thread (Thread 0x7f50dee81700 (LWP )):
# 0x00007f50efe74b7d in poll () from /lib64/libc.so.
# 0x00000000012bae8f in vio_io_wait (vio=<optimized out>, event=<optimized out>, timeout=) at /export/home/pb2/build/sb_0--1514433850.9/mysql-5.7./vio/viosocket.c:
# 0x00000000012baf83 in vio_socket_io_wait (vio=<optimized out>, event=<optimized out>) at /export/home/pb2/build/sb_0--1514433850.9/mysql-5.7./vio/viosocket.c:
# 0x00000000012bb5b8 in vio_read (vio=0x7f50b0000bb0, buf=0x7f50b000a3c0 "\001", size=) at /export/home/pb2/build/sb_0--1514433850.9/mysql-5.7./vio/viosocket.c:
# 0x0000000000c6de03 in net_read_raw_loop (net=0x7f50b0002570, count=) at /export/home/pb2/build/sb_0--1514433850.9/mysql-5.7./sql/net_serv.cc:
# 0x0000000000c6e69b in net_read_packet_header (net=0x7f50b0002570) at /export/home/pb2/build/sb_0--1514433850.9/mysql-5.7./sql/net_serv.cc:
# net_read_packet (net=0x7f50b0002570, complen=0x7f50dee80d38) at /export/home/pb2/build/sb_0--1514433850.9/mysql-5.7./sql/net_serv.cc:
# 0x0000000000c6e94c in my_net_read (net=0x7f50b0002570) at /export/home/pb2/build/sb_0--1514433850.9/mysql-5.7./sql/net_serv.cc:
# 0x0000000000c7c1dc in Protocol_classic::read_packet (this=0x7f50b0001e18) at /export/home/pb2/build/sb_0--1514433850.9/mysql-5.7./sql/protocol_classic.cc:
# 0x0000000000c7af52 in Protocol_classic::get_command (this=0x7f50b0001e18, com_data=0x7f50dee80de0, cmd=0x7f50dee80e0c) at /export/home/pb2/build/sb_0--1514433850.9/mysql-5.7./sql/protocol_classic.cc:
# 0x0000000000d1cf47 in do_command (thd=0x7f50b0000dc0) at /export/home/pb2/build/sb_0--1514433850.9/mysql-5.7./sql/sql_parse.cc:
# 0x0000000000ded7ac in handle_connection (arg=<optimized out>) at /export/home/pb2/build/sb_0--1514433850.9/mysql-5.7./sql/conn_handler/connection_handler_per_thread.cc:
# 0x0000000000f707b4 in pfs_spawn_thread (arg=0x382fa60) at /export/home/pb2/build/sb_0--1514433850.9/mysql-5.7./storage/perfschema/pfs.cc:
# 0x00007f50f13c1df5 in start_thread () from /lib64/libpthread.so.
# 0x00007f50efe7f1ad in clone () from /lib64/libc.so. Thread (Thread 0x7f50f17e8740 (LWP )):
# 0x00007f50efe74b7d in poll () from /lib64/libc.so.
# 0x0000000000deeaf9 in Mysqld_socket_listener::listen_for_connection_event (this=0x30d96f0) at /export/home/pb2/build/sb_0--1514433850.9/mysql-5.7./sql/conn_handler/socket_connection.cc:
# 0x00000000007c89c4 in connection_event_loop (this=0x373e050) at /export/home/pb2/build/sb_0--1514433850.9/mysql-5.7./sql/conn_handler/connection_acceptor.h:
# mysqld_main (argc=, argv=0x2f897b8) at /export/home/pb2/build/sb_0--1514433850.9/mysql-5.7./sql/mysqld.cc:
# 0x00007f50efdaaaf5 in __libc_start_main () from /lib64/libc.so.
# 0x00000000007be479 in _start ()
TS 788084395.1530408210 -- :: [root@zlm1 :: ~]
#
Demonstrate of relevant conceptions.
 .What's gdb?
gdb is tool of linux,a debugger of GNU project.It can help you to see what's going on inside the program while it executes.For example,the usual case is the program running slowly or almost to be crashed. .What can gdb do?
It can catch details in the act belowl:
).Start the program and specify anything the might affect its behavior.
).Let the program stop on specific conditions.
).Check the details when the program stops.
).Change things in the program and try to correct effect of potential problems. .What's LWP?
LWP is abbreviation of Light Weight Process.
Process:You'll find a process in background after you've executed a linux command(which can be observed by "ps -ef").
Thread:It's nothing but a flow of execution of the linux process.
Light Weight Process:It's almost the same with "thread" but a term at kernal level. Here's some detail of it:
What are Linux Processes, Threads, Light Weight Processes, and Process State
https://www.thegeekstuff.com/2013/11/linux-process-and-threads/
Something about output file.
 .The second column in the file shows the detail of memory address with hex.
.At the very beginning of the file in Thread (LWP ),it shows the detail of how MySQL process works.
"Mysqld_socket_listener::listen_for_connection_event" is a MySQL function defined in source code file "socket_connection.cc".This is a clue which can help you to findout where to servay the details if something happened and stucked here.
.At every bottom of each thread(except thread ),you can see the same contents below:
"#. 0x... clone () from /lib64/libc.so.6" //clone() is a function to create a new thread.
"#. 0x... start_thread () from /lib64/libpthread.so.0" //start_thread() is a function to start a poxis thread.
Summary
  • pt-pmp is read-only tool and it depends on the linux gdb to collect stack traces.
  • when pt-pmp works,it will attach gdb to the program you specified,what will probably freeze the program for a while.
  • It's not recommend to run the tool on a very busy product system because of the potential freezing period and resource consumption.
  • As a matter of fact,you can also do the stack tracing stuff by pstack tool but that's not today's motif.
 

Percona-Tookit工具包之pt-pmp的更多相关文章

  1. Linux后台开发工具箱

    https://files-cdn.cnblogs.com/files/aquester/Linux后台开发工具箱.pdf 目录 目录 1 1. 前言 3 2. 脚本类工具 3 2.1. sed命令- ...

  2. Mysql: pt-table-checksum 和 pt-table-sync 检查主从一致性,实验过程

    一.安装 percona 包 1.安装仓库的包 https://www.percona.com/doc/percona-repo-config/yum-repo.html sudo yum insta ...

  3. Linux后台开发工具箱-葵花宝典

    Linux后台开发工具箱-葵花宝典 一见 2016/11/4 目录 目录 1 1. 前言 4 2. 脚本类工具 4 2.1. 双引号和单引号 4 2.2. 取脚本完整文件路径 5 2.3. 环境变量和 ...

  4. 推荐几款MySQL相关工具

    前言: 随着互联网技术的不断发展, MySQL 相关生态也越来越完善,越来越多的工具涌现出来.一些公司或个人纷纷开源出一些不错的工具,本篇文章主要介绍几款 MySQL 相关实用工具.提醒下,这里并不介 ...

  5. [知识库分享系列] 二、.NET(ASP.NET)

    最近时间又有了新的想法,当我用新的眼光在整理一些很老的知识库时,发现很多东西都已经过时,或者是很基础很零碎的知识点.如果分享出去大家不看倒好,更担心的是会误人子弟,但为了保证此系列的完整,还是选择分享 ...

  6. SQL慢查询安装过程

    SQL慢查询 基本操作 打开防火墙 firewall-cmd --zone=public --add-port=3306/tcp --permanent firewall-cmd --reload 安 ...

  7. 快速安装Percona pt工具

    yum install perl-DBI perl-DBD-MySQL perl-Time-HiRes perl-Time-HiRes perl-IO-Socket-SSLwget http://pk ...

  8. Percona 工具包 pt-online-schema-change 简介

    mysql的在线表结构修改,因为低效和阻塞读写.一直被诟病.至于ALTER TABLE 的原理,参看我上一篇文章.MySQL在线修改大表结构.看完后,发现的问题是还是会锁的,且对于在线更新的这块也是不 ...

  9. 安装percona工具包

    1.安装percona源 sudo yum install http://www.percona.com/downloads/percona-release/redhat/0.1-4/percona- ...

  10. percona pt toolkit 总结

    ##=====================================================##pt-osc之工作流程:1.检查更改表是否有主键或唯一索引,是否有触发器2.检查修改表 ...

随机推荐

  1. 配置python环境使用tushare股票数据

    最近在做一个项目,主要是基于股票市场来验证一些model,看看能否做量化交易.那么如何获取数据呢?因为客户这边前期是不想花钱买数据的,只能自己想办法了,从sina和yahoo财经频道爬到一些数据,但是 ...

  2. Spring核心-IOC-AOP-模版

    1. POM- 1.1 中央仓库 1.2 各包作用 spring-core.jar 核心工具类 spring-beans.jar 是所有应用都要用到的,它包含访问配置文件.创建和管理bean 以及进行 ...

  3. netty之==TCP粘包/拆包问题解决之道(一)

    一.TCP粘包/拆包是什么 TCP是一个“流”协议,所谓流,就是没有界限的一长串二进制数据.TCP作为传输层协议并不不了解上层业务数据的具体含义,它会根据TCP缓冲区的实际情况进行数据包的划分,所以在 ...

  4. ubuntu 更改源

    1) 备份原来的源 cp /etc/apt/source.list /etc/apt/source.list.old 2) 用下面的文件覆盖 /etc/apt/source.list # 163(非教 ...

  5. ubuntu下mysql安装(server、client、dev),开启、停止和重启,及常见错误

    转自:ubuntu下mysql安装(server.client.dev),开启.停止和重启,及常见错误 1. 在ubuntu下安装server和client很简单: (1)安装server apt-g ...

  6. genymotion安装及使用出现的问题

    此处总结genymotion出现的问题. 1)安装好genymotion后,新建一个模拟器.去下载的时候报错 Unable to create Virtual Device: Connection t ...

  7. IIS报错试图加载格式不正确的程序集解决办法 64位WinServer系统兼容32位程序集

    问题描述:     将网站/WCF发布到IIS后运行报这个错. 原因:     64位系统和32系统不匹配导致. 解决办法:     方法一.注册32位IIS(必须卸载64位IIS)         ...

  8. #include stdio.h(5)

    #include <stdio.h> int main() { //1.数组的排序-冒泡排序 /* 1.规则:相邻的两个数据进行比较 2.如果有N个数据,需要选择N-1次参照物来比较, 因 ...

  9. Struts2_HelloWorld_5

    1.设置开发模式: 更换配置文件中的 action name="hello_struts",重新访问会出错,因为配置没有立刻响应文件的即时修改. 需要加上配置 <consta ...

  10. ssh配置解释

    http://vbird.dic.ksu.edu.tw/linux_server/0310telnetssh_2.php /etc/ssh/sshd_config Port 29922 #Addres ...