systemtap :

各种资源的使用限制由所生成的C代码中的宏来设置。这些值可在编译时由-D选项来重写。下面描述了部分挑选出来的宏:

MAXNESTING 递归函数的最大调用层数,默认值是10。

MAXSTRINGLEN 字符串的最大长度,默认值是128。

MAXTRYLOCK 在声称可以出现死锁和跳出探测点前,等待全局变量锁的最大迭代次数,默认值是1000。

MAXACTION 单个探测点内可以执行语句数的最大值,默认值是1000。

MAXMAPENTRIES 数组在声明时没有显示指定大小时,数组的最大行数(译者注:即组数的最大下标个数),默认值为2048。

MAXERRORS  在触发退出前,可以容忍软件错误个数的最大值,默认值是0。

MAXSKIPPED 在触发退出前,可忽略的重入探测点的最大值,默认值是100。

MINSTACKSPACE 运行探测处理函数所需要的内核栈的最小字节数。此数值应比探测处理函数所需内核栈的大小加上安全边界大小足够大。默认值是1024。

Stap或statrun如果在探测点已经运行之后出现问题,可以安全杀死(kill)用户空间进程,并且可以使用rmmod命令删除内核探测模块。任何未处理的跟踪消息将丢失。
变量的引用有两种风格:
$varname // 引用变量varname
$var->field // 引用结构的成员变量
$var[N] // 引用数组的元素
&$var // 变量的地址 @var("varname") // 引用变量varname
@var("var@src/file.c") // 引用src/file.c在被编译时的全局变量varname
@var("varname@file.c")->field // 引用结构的成员变量
@var("var@file.c")[N] // 引用数组的元素
&@var("var@file.c") // 变量的地址 $var$ // provide a string that includes the values of basic type values
$var$$ // provide a string that includes all values of nested data types $$vars // 一个包含所有函数参数、局部变量的字符串
$$locals // 一个包含所有局部变量的字符串
$$params // 一个包含所有函数参数的字符串
[root@localhost bin]# stap -L 'process("/usr/local/mysql56/bin/mysqld").function("MDL_context::acquire_lock")'    

 process("/usr/local/mysql56/bin/mysqld").function("MDL_context::acquire_lock@/usr/src/mysql-5.6.28/sql/mdl.cc:2184") $this:class MDL_context* const $mdl_request:class MDL_request* $lock_wait_timeout:ulong $lock:struct MDL_lock* $ticket:struct MDL_ticket* $abs_timeout:struct timespec $wait_status:enum enum_wait_status $__PRETTY_FUNCTION__:char[] const

基于源代码函数:

[root@localhost bin]# stap -v -g -d /usr/local/mysql56/bin/mysqld --ldd  -e 'probe process("/usr/local/mysql56/bin/mysqld").function("MDL_context::acquire_lock") { printf("got it\n");print_ubacktrace();mdelay(10000) }'|c++filt

打印函数参数变量

会话1:

mysql> insert into uu select ;

会话2:

[root@localhost bin]# stap -v -g -D MAXSTRINGLEN= -d /usr/local/mysql56/bin/mysqld --ldd  -e 'probe process("/usr/local/mysql56/bin/mysqld").function("MDL_context::acquire_lock") { printf("%s\n %s\n",probefunc(),$$parms$$);mdelay(1000) }'|c++filt
MDL_context::acquire_lock(MDL_request*, unsigned long)
this={.m_wait={.m_LOCK_wait_status={.m_mutex={.global={.__data={.__lock=, .__count=, .__owner=, .__nusers=, .__kind=, .__spins=, .__list={.__prev=0x0, .__next=0x0}}, .__size="", .__align=}, .mutex={.__data={.__lock=, .__count=, .__owner=, .__nusers=, .__kind=, .__spins=, .__list={.__prev=0x0, .__next=0x0}}, .__size="", .__align=}, .file="/usr/src/mysql-5.6.28/sql/mdl.cc", .line=, .count=, .thread=}, .m_psi=0x0}, .m_COND_wait_status={.m_cond={.__data={.__lock=, .__futex=, .__total_seq=, .__wakeup_seq=, .__woken_seq=, .__mutex=0x0, .__nwaiters=, ...}, ...}, ...}, ...}, ...} mdl_request={.type=, .duration=, .next_in_list=0xff2c7a, .prev_in_list=0x1e13380, .ticket=0x0,
.key={.m_length=, .m_db_name_length=, .m_ptr=""
} } lock_wait_timeout=31536000 MDL_context::acquire_lock(MDL_request*, unsigned long)
this={.m_wait={.m_LOCK_wait_status={.m_mutex={.global={.__data={.__lock=, .__count=, .__owner=, .__nusers=, .__kind=, .__spins=, .__list={.__prev=0x0, .__next=0x0}}, .__size="", .__align=}, .mutex={.__data={.__lock=, .__count=, .__owner=, .__nusers=, .__kind=, .__spins=, .__list={.__prev=0x0, .__next=0x0}}, .__size="", .__align=}, .file="/usr/src/mysql-5.6.28/sql/mdl.cc", .line=, .count=, .thread=}, .m_psi=0x0}, .m_COND_wait_status={.m_cond={.__data={.__lock=, .__futex=, .__total_seq=, .__wakeup_seq=, .__woken_seq=, .__mutex=0x0, .__nwaiters=, ...}, ...}, ...}, ...}, ...} mdl_request={.type=, .duration=, .next_in_list=0x0, .prev_in_list=0x0, .ticket=0x0, .key={.m_length=, .m_db_name_length=, .m_ptr="test"}} lock_wait_timeout=31536000 MDL_context::acquire_lock(MDL_request*, unsigned long)
this={.m_wait={.m_LOCK_wait_status={.m_mutex={.global={.__data={.__lock=, .__count=, .__owner=, .__nusers=, .__kind=, .__spins=, .__list={.__prev=0x0, .__next=0x0}}, .__size="", .__align=}, .mutex={.__data={.__lock=, .__count=, .__owner=, .__nusers=, .__kind=, .__spins=, .__list={.__prev=0x0, .__next=0x0}}, .__size="", .__align=}, .file="/usr/src/mysql-5.6.28/sql/mdl.cc", .line=, .count=, .thread=}, .m_psi=0x0}, .m_COND_wait_status={.m_cond={.__data={.__lock=, .__futex=, .__total_seq=, .__wakeup_seq=, .__woken_seq=, .__mutex=0x0, .__nwaiters=, ...}, ...}, ...}, ...}, ...} mdl_request={.type=, .duration=, .next_in_list=0x1000000ab7cbe, .prev_in_list=0xf2f3bb, .ticket=0x0, .key={.m_length=, .m_db_name_length=, .m_ptr=""}} lock_wait_timeout=

打印局部变量:

会话1:

mysql> insert into uu select ;

会话2:

[root@localhost bin]# stap -v -g -D MAXSTRINGLEN= -d /usr/local/mysql56/bin/mysqld --ldd  -e 'probe process("/usr/local/mysql56/bin/mysqld").function("MDL_context::acquire_lock") { printf("%s\n %s\n",probefunc(),$$locals$$);mdelay(1000) }'|c++filt
MDL_context::acquire_lock(MDL_request*, unsigned long)
lock={.key={.m_length=, .m_db_name_length=, .m_ptr=""}, .m_rwlock={.m_prlock={.lock={.__data={.__lock=-, .__count=, .__owner=, .__nusers=, .__kind=, .__spins=, .__list={.__prev=0x76b4ad, .__next=0xf27abd}}, .__size="", .__align=}, .no_active_readers={.__data={.__lock=, .__futex=, .__total_seq=, .__wakeup_seq=, .__woken_seq=, .__mutex=0x100000000e3ed37, .__nwaiters=, .__broadcast_seq=}, .__size="7+", .__align=}, .active_readers=, .writers_waiting_readers=, .active_writer='\001', .writer_thread=}, .m_psi=0x1e13380}, .m_granted={.m_list={.m_first=0x25b3cd0, .m_last=0x0}, .m_bitmap=}, .m_waiting={.m_list={.m_first=0x14f600e3ed37, ...}, ...}, ...} ticket={.next_in_context=0x22e1ec0, .prev_in_context=0x1e13380, .next_in_lock=0xab7bcf, .prev_in_lock=0xff01ac, .m_type=, .m_duration=, .m_ctx=0x2b37140bfab0, .m_lock=0xab7cbe} abs_timeout={.tv_sec=, .tv_nsec=} wait_status= __PRETTY_FUNCTION__="bool MDL_context::acquire_lock(MDL_request*, ulong)" MDL_context::acquire_lock(MDL_request*, unsigned long)
lock=ERROR ticket={.next_in_context=0x8b48e87d894820ec, .prev_in_context=0xc08548009ff3c305, .next_in_lock=0x8948e8458b480b75, .prev_in_lock=0xfdcee8009ff3b305, .m_type=, .m_duration=, .m_ctx=0x558b480b7400f87d, .m_lock=0x28948e8458b48f8} abs_timeout={.tv_sec=, .tv_nsec=} wait_status= __PRETTY_FUNCTION__="bool MDL_context::acquire_lock(MDL_request*, ulong)" MDL_context::acquire_lock(MDL_request*, unsigned long)
lock={.key={.m_length=, .m_db_name_length=, .m_ptr=""}, .m_rwlock={.m_prlock={.lock={.__data={.__lock=, .__count=, .__owner=, .__nusers=, .__kind=, .__spins=, .__list={.__prev=0xc1, .__next=0x100000}}, .__size="", .__align=}, .no_active_readers={.__data={.__lock=, .__futex=, .__total_seq=, .__wakeup_seq=, .__woken_seq=, .__mutex=0x22d77c0, .__nwaiters=, .__broadcast_seq=}, .__size="", .__align=}, .active_readers=, .writers_waiting_readers=, .active_writer='\000', .writer_thread=}, .m_psi=0x0}, .m_granted={.m_list={.m_first=0x0, .m_last=0x384}, .m_bitmap=}, .m_waiting={.m_list={.m_first=0x1058783, ...}, ...}, ...} ticket={.next_in_context=0x10000022e1ec0, .prev_in_context=0x2b37140bfbb0, .next_in_lock=0xe3ed37, .prev_in_lock=0x22e1fe0, .m_type=, .m_duration=, .m_ctx=0x100000000000001, .m_lock=0x22e1fe0} abs_timeout={.tv_sec=, .tv_nsec=} wait_status= __PRETTY_FUNCTION__="bool MDL_context::acquire_lock(MDL_request*, ulong)"

打印局部变量+函数参数变量

MDL_context::acquire_lock(MDL_request*, unsigned long)
this={.m_wait={.m_LOCK_wait_status={.m_mutex={.global={.__data={.__lock=, .__count=, .__owner=, .__nusers=, .__kind=, .__spins=, .__list={.__prev=0x0, .__next=0x0}}, .__size="", .__align=}, .mutex={.__data={.__lock=, .__count=, .__owner=, .__nusers=, .__kind=, .__spins=, .__list={.__prev=0x0, .__next=0x0}}, .__size="", .__align=}, .file="/usr/src/mysql-5.6.28/sql/mdl.cc", .line=, .count=, .thread=}, .m_psi=0x0}, .m_COND_wait_status={.m_cond={.__data={.__lock=, .__futex=, .__total_seq=, .__wakeup_seq=, .__woken_seq=, .__mutex=0x0, .__nwaiters=, ...}, ...}, ...}, ...}, ...} mdl_request={.type=, .duration=, .next_in_list=0xff2c7a, .prev_in_list=0x1e13380, .ticket=0x0, .key={.m_length=, .m_db_name_length=, .m_ptr=""}} lock_wait_timeout= lock={.key={.m_length=, .m_db_name_length=, .m_ptr=""}, .m_rwlock={.m_prlock={.lock={.__data={.__lock=-, .__count=, .__owner=, .__nusers=, .__kind=, .__spins=, .__list={.__prev=0x76b4ad, .__next=0xf27abd}}, .__size="", .__align=}, .no_active_readers={.__data={.__lock=, .__futex=, .__total_seq=, .__wakeup_seq=, .__woken_seq=, .__mutex=0x100000000e3ed37, .__nwaiters=, .__broadcast_seq=}, .__size="7+", .__align=}, .active_readers=, .writers_waiting_readers=, .active_writer='\001', .writer_thread=}, .m_psi=0x1e13380}, .m_granted={.m_list={.m_first=0x25b3cd0, .m_last=0x0}, .m_bitmap=}, .m_waiting={.m_list={.m_first=0x14f600e3ed37, ...}, ...}, ...} ticket={.next_in_context=0x22e1ec0, .prev_in_context=0x1e13380, .next_in_lock=0xab7bcf, .prev_in_lock=0xff01ac, .m_type=, .m_duration=, .m_ctx=0x2b37140bfab0, .m_lock=0xab7cbe} abs_timeout={.tv_sec=, .tv_nsec=} wait_status= __PRETTY_FUNCTION__="bool MDL_context::acquire_lock(MDL_request*, ulong)" MDL_context::acquire_lock(MDL_request*, unsigned long)
this={.m_wait={.m_LOCK_wait_status={.m_mutex={.global={.__data={.__lock=, .__count=, .__owner=, .__nusers=, .__kind=, .__spins=, .__list={.__prev=0x0, .__next=0x0}}, .__size="", .__align=}, .mutex={.__data={.__lock=, .__count=, .__owner=, .__nusers=, .__kind=, .__spins=, .__list={.__prev=0x0, .__next=0x0}}, .__size="", .__align=}, .file="/usr/src/mysql-5.6.28/sql/mdl.cc", .line=, .count=, .thread=}, .m_psi=0x0}, .m_COND_wait_status={.m_cond={.__data={.__lock=, .__futex=, .__total_seq=, .__wakeup_seq=, .__woken_seq=, .__mutex=0x0, .__nwaiters=, ...}, ...}, ...}, ...}, ...} mdl_request={.type=, .duration=, .next_in_list=0x0, .prev_in_list=0x0, .ticket=0x0, .key={.m_length=, .m_db_name_length=, .m_ptr="test"}} lock_wait_timeout= lock=ERROR ticket={.next_in_context=0x8b48e87d894820ec, .prev_in_context=0xc08548009ff3c305, .next_in_lock=0x8948e8458b480b75, .prev_in_lock=0xfdcee8009ff3b305, .m_type=, .m_duration=, .m_ctx=0x558b480b7400f87d, .m_lock=0x28948e8458b48f8} abs_timeout={.tv_sec=, .tv_nsec=} wait_status= __PRETTY_FUNCTION__="bool MDL_context::acquire_lock(MDL_request*, ulong)"

MDL_context::acquire_lock(MDL_request*, unsigned long)
this={.m_wait={.m_LOCK_wait_status={.m_mutex={.global={.__data={.__lock=, .__count=, .__owner=, .__nusers=, .__kind=, .__spins=, .__list={.__prev=0x0, .__next=0x0}}, .__size="", .__align=}, .mutex={.__data={.__lock=, .__count=, .__owner=, .__nusers=, .__kind=, .__spins=, .__list={.__prev=0x0, .__next=0x0}}, .__size="", .__align=}, .file="/usr/src/mysql-5.6.28/sql/mdl.cc", .line=, .count=, .thread=}, .m_psi=0x0}, .m_COND_wait_status={.m_cond={.__data={.__lock=, .__futex=, .__total_seq=, .__wakeup_seq=, .__woken_seq=, .__mutex=0x0, .__nwaiters=, ...}, ...}, ...}, ...}, ...} mdl_request={.type=, .duration=, .next_in_list=0x1000000ab7cbe, .prev_in_list=0xf2f3bb, .ticket=0x0, .key={.m_length=, .m_db_name_length=, .m_ptr=""}} lock_wait_timeout= lock={.key={.m_length=, .m_db_name_length=, .m_ptr=""}, .m_rwlock={.m_prlock={.lock={.__data={.__lock=, .__count=, .__owner=, .__nusers=, .__kind=, .__spins=, .__list={.__prev=0xc1, .__next=0x100000}}, .__size="", .__align=}, .no_active_readers={.__data={.__lock=, .__futex=, .__total_seq=, .__wakeup_seq=, .__woken_seq=, .__mutex=0x22d77c0, .__nwaiters=, .__broadcast_seq=}, .__size="", .__align=}, .active_readers=, .writers_waiting_readers=, .active_writer='\000', .writer_thread=}, .m_psi=0x0}, .m_granted={.m_list={.m_first=0x0, .m_last=0x384}, .m_bitmap=}, .m_waiting={.m_list={.m_first=0x1058783, ...}, ...}, ...} ticket={.next_in_context=0x10000022e1ec0, .prev_in_context=0x2b37140bfbb0, .next_in_lock=0xe3ed37, .prev_in_lock=0x22e1fe0, .m_type=, .m_duration=, .m_ctx=0x100000000000001, .m_lock=0x22e1fe0} abs_timeout={.tv_sec=, .tv_nsec=} wait_status= __PRETTY_FUNCTION__="bool MDL_context::acquire_lock(MDL_request*, ulong)"

打印其中的某个变量值的内部某个成员

会话1:

mysql> insert into uu select 1;

会话2:

[root@localhost bin]# stap -v -g -D MAXSTRINGLEN= -d /usr/local/mysql56/bin/mysqld --ldd  -e 'probe process("/usr/local/mysql56/bin/mysqld").function("MDL_context::acquire_lock") { printf("%s\n %d\n",probefunc(),$mdl_request->type);mdelay(1000) }'|c++filt
MDL_context::acquire_lock(MDL_request*, unsigned long)

MDL_context::acquire_lock(MDL_request*, unsigned long)

MDL_context::acquire_lock(MDL_request*, unsigned long)
 

打印其中的某个变量值的全部成员:

会话1:

mysql> insert into uu select ;

会话2:

[root@localhost bin]# stap -v -g -D MAXSTRINGLEN= -d /usr/local/mysql56/bin/mysqld --ldd  -e 'probe process("/usr/local/mysql56/bin/mysqld").function("MDL_context::acquire_lock") { printf("%s\n %s\n",probefunc(),$mdl_request$$);mdelay(1000) }'|c++filt
MDL_context::acquire_lock(MDL_request*, unsigned long)
{.type=, .duration=, .next_in_list=0xff2c7a, .prev_in_list=0x1e13380, .ticket=0x0, .key={.m_length=, .m_db_name_length=, .m_ptr=""}}
MDL_context::acquire_lock(MDL_request*, unsigned long)
{.type=, .duration=, .next_in_list=0x0, .prev_in_list=0x0, .ticket=0x0, .key={.m_length=, .m_db_name_length=, .m_ptr="test"}}
MDL_context::acquire_lock(MDL_request*, unsigned long)
{.type=, .duration=, .next_in_list=0x1000000ab7cbe, .prev_in_list=0xf2f3bb, .ticket=0x0, .key={.m_length=, .m_db_name_length=, .m_ptr=""}}
^CPass : run completed in 10usr/80sys/23132real ms.
[root@localhost bin]# stap -v -g -D MAXSTRINGLEN= -d /usr/local/mysql56/bin/mysqld --ldd  -e 'probe process("/usr/local/mysql56/bin/mysqld").function("MDL_request::MDL_request") { printf("%s\n %s\n",probefunc(),$$parms$$);mdelay(10000) }'|c++filt

MDL_request::MDL_request()
this={.type=, .duration=, .next_in_list=0x0, .prev_in_list=0x14edc50, .ticket=0x25a7f70, .key={.m_length=, .m_db_name_length=, .m_ptr=""}}
MDL_request::MDL_request()
this={.type=, .duration=, .next_in_list=0x0, .prev_in_list=0x0, .ticket=0x0, .key={.m_length=, .m_db_name_length=, .m_ptr=""}}
MDL_request::MDL_request()
this=ERROR
MDL_request::MDL_request()
this={.type=, .duration=, .next_in_list=0x8b48e87d894820ec, .prev_in_list=0xc08548009ff3c305, .ticket=0x8948e8458b480b75, .key={.m_length=, .m_db_name_length=, .m_ptr=""}}
MDL_request::MDL_request()
this={.type=, .duration=, .next_in_list=0xeeb551, .prev_in_list=0xee97d0, .ticket=0x2b37140bfd40, .key={.m_length=, .m_db_name_length=, .m_ptr=""}}
MDL_request::MDL_request()
this={.type=, .duration=, .next_in_list=0x8b48e87d894820ec, .prev_in_list=0xc08548009ff3c305, .ticket=0x8948e8458b480b75, .key={.m_length=, .m_db_name_length=, .m_ptr=""}}

mdl 锁 SYSTEMTAP跟踪的更多相关文章

  1. MySQL锁系列3 MDL锁

    http://www.cnblogs.com/xpchild/p/3790139.html   MySQL为了保护数据字典元数据,使用了metadata lock,即MDL锁,保证在并发的情况下,结构 ...

  2. mysql 原理 ~ DDL之mdl锁

    一 简介: MDL锁 二 具体 1 MDL锁   1 增删查改 申请MDL读锁   2 ddl语句       1. 拿MDL写锁      2. 降级成MDL读锁      3. 真正做DDL    ...

  3. 用systemtap跟踪打印动态链接库的所有c++函数调用过程

    http://gmd20.blog.163.com/blog/static/168439232015475525227/             用systemtap跟踪打印动态链接库的所有c++函数 ...

  4. 有了MDL锁视图,业务死锁从此一目了然

    摘要:MDL锁视图让一线运维人员清晰地查看数据库各session持有和等待的元数据锁信息,从而找出数据库MDL锁等待的根因,准确地进行下一步决策. 当多用户共同存取数据时,数据库中就会产生多个事务同时 ...

  5. MDL锁

    mdl锁的主要作用是用来维护表元数据的一致性.在表上有活动事务的时候,不可以对表元数据进行修改操作. 如果没有MDL锁的保护,那么session2可以直接执行,并导致session1出错. MDL锁是 ...

  6. sync fsync fdatasync ---systemtap跟踪

    aa.stp: probe kernel .function ( "sys_sync" ) { printf ( "probfunc:%s fun:%s\n", ...

  7. systemtap跟踪C

    1.[root@localhost ~]# rpm -qi  glibcName        : glibc                        Relocations: (not rel ...

  8. 深入理解MYSQL的MDL元数据锁

    1 前言 2 MDL锁与实现 3 MDL锁的性能与并发改进 4 MDL锁的诊断 前言 好久没更新,主要是因为Inside君最近沉迷于一部动画片——<新葫芦娃兄弟>.终于抽得闲,完成了本篇关 ...

  9. 深入理解MDL元数据锁

    前言:  当你在MySQL中执行一条SQL时,语句并没有在你预期的时间内执行完成,这时候我们通常会登陆到MySQL数据库上查看是不是出了什么问题,通常会使用的一个命令就是 show processli ...

随机推荐

  1. 洛谷 P1081 开车旅行 —— 倍增

    题目:https://www.luogu.org/problemnew/show/P1081 真是倍增好题! 预处理:f[i][j] 表示从 i 点开始走 2^j 次 AB (A,B各走一次)到达的点 ...

  2. 比较两个map里的数据

    template <class DataType>void ProcessMap(std::map<std::string, std::vector<DataType> ...

  3. 数据结构C++,线性表的实现

    #include <iostream>#include <sstream>#include <fstream>#include <cmath>#incl ...

  4. 使用命名方式使用django的url模式

    有如下一个url配置: urlpatterns = patterns('', (r'^archive/(\d{4})/$', archive), (r'^archive-summary/(\d{4}) ...

  5. 判断ascii码是什么的函数

    function CharMode(iN){ if (iN>=48 && iN <=57) //数字 return 1; if (iN>=65 && ...

  6. curl强制下载文件

    <?phpfunction download_remote_file_with_curl($file_url, $save_to) { $ch = curl_init(); curl_setop ...

  7. 【转】Postman接口测试之POST、GET请求方法

    转自竹小冉: https://www.cnblogs.com/zhuxr/p/9009708.html 一.基础知识 1.HTTP的五种请求方法:GET, POST ,HEAD,OPTIONS, PU ...

  8. CSS制作简单loading动画

    曾经以为,loading的制作需要一些比较高深的web动画技术,后来发现大多数loading都可以用“障眼法”做出来.比如一个旋转的圆圈,并不都是将gif图放进去,有些就是画个静止图像,然后让它旋转就 ...

  9. 【java并发】(1)深入理解volatile关键字

    volatile这个关键字可能很多朋友都听说过,或许也都用过.在Java 5之前,它是一个备受争议的关键字,因为在程序中使用它往往会导致出人意料的结果.在Java 5之后,volatile关键字才得以 ...

  10. buf.readInt16LE函数详解

    offset {Number} 0 noAssert {Boolean} 默认:false 返回:{Number} 从该 Buffer 指定的带有特定尾数格式(readInt16BE() 返回一个较大 ...