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. java内存区域与内存溢出

    JVM的内存区域划分: jvm的内存区域分为5部分:程序计数器,虚拟机栈,本地方法栈,堆跟方法区. 程序计数器,虚拟机栈,本地方法栈三部分是线程私有的,堆跟方法区是公共的. 1.程序计数器 是一块较小 ...

  2. php验证码处理

    //基本步骤 1,先创建一张指定宽度和高度的一张验证码图片 imagecreatetruecolor() 2,给验证码图片添加背景颜色 和文字颜色 imagecolorallocate() 3, 在指 ...

  3. linux程序分析工具介绍(二)—-ldd,nm

    本文要介绍的ldd和nm是linux下,两个用来分析程序很实用的工具.ldd是用来分析程序运行时需要依赖的动态库的工具:nm是用来查看指定程序中的符号表相关内容的工具.下面通过例子,分别来介绍一下这两 ...

  4. asp.net core 2.1 生成swagger文档

    新建asp.netcore2.1 api项目 “WebApplication1” 在nuget管理器中添加对Swashbuckle.AspNetCore 3.0.0.Microsoft.AspNetC ...

  5. Akka探索第二个例子by fsharp

    本文重度借鉴了github上akkabootcamp教程. 先上代码 open Akka open Akka.Actor open System type Message = | ContinuePr ...

  6. BZOJ3261: 最大异或和(可持久化trie树)

    题意 题目链接 Sol 设\(sum[i]\)表示\(1 - i\)的异或和 首先把每个询问的\(x \oplus sum[n]\)就变成了询问前缀最大值 可持久化Trie树维护前缀xor,建树的时候 ...

  7. MOSS2010中如何用代码给托管元数据类型的栏目赋值

    最近项目中遇到如何用代码给托管元数据类型的栏目赋值问题,经过折腾,现把我的思路和实现方法共享出来,让大家一起来学习学习.相互探讨下. /// <summary> /// 托管元数据 /// ...

  8. CentOS 7.0 各版本下载说明 新增Everything版

    CentOS-7.0-1406有很多可供选择的版本,对初学者来说,不知如何选择,下面做简单的介绍: CentOS-7.0-1406-x86_64-DVD.iso 标准安装版,一般下载这个就可以了 Ce ...

  9. Saw a tweet from Andrew Liam Trask, sounds like Oxford DeepNLP 2017 class have all videos slides practicals all up. Thanks Andrew for the tip!

    Saw a tweet from Andrew Liam Trask, sounds like Oxford DeepNLP 2017 class have all videos/slides/pra ...

  10. ui.datepicker的回显问题

    应用场景: 页面上有一些现有的输入框,需要调用日期插件,同时还要clone一份,动态添加到页面中,动态生成的输入框在调用datepicker的时候,click事件有效,但是选择的时间无法回显到对应的输 ...