linux strace追踪mysql执行语句 (mysqld --debug)
转载请注明出处:使用strace追踪多个进程 http://www.ttlsa.com/html/1841.html
http://blog.itpub.net/26250550/viewspace-1339818/
strace是Linux环境下的一款程序调试工具,用来监察一个应用程序所使用的系统调用及它所接收的系统信息。追踪程序运行时的整个生命周期,输出每一个系统调用的名字,参数,返回值和执行消耗的时间等。
strace常用参数:
-p 跟踪指定的进程
-f 跟踪由fork子进程系统调用
-F 尝试跟踪vfork子进程系统调吸入,与-f同时出现时, vfork不被跟踪
-o filename 默认strace将结果输出到stdout。通过-o可以将输出写入到filename文件中
-ff 常与-o选项一起使用,不同进程(子进程)产生的系统调用输出到filename.PID文件
-r 打印每一个系统调用的相对时间
-t 在输出中的每一行前加上时间信息。
-tt 时间确定到微秒级。还可以使用-ttt打印相对时间 -v 输出所有系统调用。默认情况下,一些频繁调用的系统调用不会输出
-s 指定每一行输出字符串的长度,默认是32。文件名一直全部输出 -c 统计每种系统调用所执行的时间,调用次数,出错次数。
-e expr 输出过滤器,通过表达式,可以过滤出掉你不想要输出
1. strace追踪多个进程方法: 当有多个子进程的情况下,比如php-fpm、nginx等,用strace追踪显得很不方便。可以使用下面的方法来追踪所有的子进程。
function straceall {
strace $(pidof "${1}" | sed 's/\([0-9]*\)/-p \1/g')
}
# source /root/.bashrc
|
1
2
3
4
5
|
# vim /root/.bashrc //添加以下内容
function straceall {
strace $(pidof "${1}" | sed 's/\([0-9]*\)/-p \1/g')
}
# source /root/.bashrc
|
执行:
|
1
|
# traceall php-fpm
|
2. 追踪web服务器系统调用情况
# strace -f -F -o php-fpm-strace /usr/local/php/sbin/php-fpm -y /usr/local/php/etc/php-fpm.conf
|
1
2
|
# strace -f -F -s 1024 -o nginx-strace /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
# strace -f -F -o php-fpm-strace /usr/local/php/sbin/php-fpm -y /usr/local/php/etc/php-fpm.conf
|
3. 追踪mysql执行语句
# find ./ -name "mysqld-strace*" -type f -print |xargs grep -n "SELECT.*FROM"
|
1
2
|
# strace -f -F -ff -o mysqld-strace -s 1024 -p mysql_pid
# find ./ -name "mysqld-strace*" -type f -print |xargs grep -n "SELECT.*FROM"
|
4. whatisdong---查看程序在干啥
# This script is from http://poormansprofiler.org/
nsamples=1
sleeptime=0
pid=$(pidof $1)
for x in $(seq 1 $nsamples)
do
gdb -ex "set pagination 0" -ex "thread apply all bt" -batch -p $pid
sleep $sleeptime
done | \
awk '
BEGIN { s = ""; }
/^Thread/ { print s; s = ""; }
/^\#/ { if (s != "" ) { s = s "," $4} else { s = $4 } }
END { print s }' | \
sort | uniq -c | sort -r -n -k 1,1
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
#!/bin/bash
# This script is from http://poormansprofiler.org/
nsamples=1
sleeptime=0
pid=$(pidof $1)
for x in $(seq 1 $nsamples)
do
gdb -ex "set pagination 0" -ex "thread apply all bt" -batch -p $pid
sleep $sleeptime
done | \
awk '
BEGIN { s = ""; }
/^Thread/ { print s; s = ""; }
/^\#/ { if (s != "" ) { s = s "," $4} else { s = $4 } }
END { print s }' | \
sort | uniq -c | sort -r -n -k 1,1
|
输出:
727 pthread_cond_wait@@GLIBC_2.3.2,cache_thread,put_in_cache=true),handle_one_connection,start_thread,??
4 pthread_cond_wait@@GLIBC_2.3.2,os_event_wait_low,os_aio_simulated_handle,fil_aio_wait,io_handler_thread,start_thread,??
4 ??,??
2 read,my_real_read,my_net_read,do_command,handle_one_connection,start_thread,??
1 pthread_cond_wait@@GLIBC_2.3.2,os_event_wait_low,srv_master_thread,start_thread,??
1 pthread_cond_wait@@GLIBC_2.3.2,MYSQL_BIN_LOG::wait_for_update,mysql_binlog_send,dispatch_command,do_command,handle_one_connection,start_thread,??
1 do_sigwait,sigwait,signal_hand,start_thread,??
1
|
1
2
3
4
5
6
7
8
9
|
# profiler.sh mysqld
727 pthread_cond_wait@@GLIBC_2.3.2,cache_thread,put_in_cache=true),handle_one_connection,start_thread,??
4 pthread_cond_wait@@GLIBC_2.3.2,os_event_wait_low,os_aio_simulated_handle,fil_aio_wait,io_handler_thread,start_thread,??
4 ??,??
2 read,my_real_read,my_net_read,do_command,handle_one_connection,start_thread,??
1 pthread_cond_wait@@GLIBC_2.3.2,os_event_wait_low,srv_master_thread,start_thread,??
1 pthread_cond_wait@@GLIBC_2.3.2,MYSQL_BIN_LOG::wait_for_update,mysql_binlog_send,dispatch_command,do_command,handle_one_connection,start_thread,??
1 do_sigwait,sigwait,signal_hand,start_thread,??
1
|
linux strace追踪mysql执行语句 (mysqld --debug)的更多相关文章
- strace追踪mysql执行语句
一.strace参数 strace是Linux环境下的一款程序调试工具,用来监察一个应用程序所使用的系统调用及它所接收的系统信息.追踪程序运行时的整个生命周期,输出每一个系统调用的名字,参数,返回值和 ...
- 8.mysql执行语句的顺序
mysql执行语句的顺序 一.group by + where group by 字句和where条件语句结合在一起使用,where在前,group by 在后.即先对select xx fr ...
- MySQL执行语句的顺序
MySQL的语句一共分为11步,最先执行的总是FROM操作,最后执行的是LIMIT操作.其中每一个操作都会产生一张虚拟的表,这个虚拟的表作为一个处理的输入,只是这些虚拟的表对用户来说是透明的,但是只有 ...
- MySql 执行语句错误 Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near
关于用Power Designer 生成sql文件出现 错误 [Err] 1064 - You have an error in your SQL syntax; check the manual ...
- mysql 执行语句
连接数据库: $con = mysql_connect(服务器地址,用户名,密码): 选择数据库: $select = mysql_select_db(数据库名称); $select = mysql_ ...
- Linux中连接mysql执行sql文件
数据量小的时候可以把sql语句内容粘贴执行,但是文件很大的时候,这样执行效率很慢很慢,需要使用source执行sql文件 1.客户端连接mysql数据库 [root@iZbp1bb2egi7w0uey ...
- mysql执行语句提示Table 'performance_schema.session_variables' doesn't exist
用管理员身份cmd进入mysql安装目录bin里,执行 mysql_upgrade -u root -p 如果杀毒软件拦截,添加为信任区
- Linux strace追踪命令详解
strace介绍 strace命令是一个集诊断.调试.统计与一体的工具,我们可以使用strace对应用的系统调用和信号传递的跟踪结果来对应用进行分析,以达到解决问题或者是了解应用工作过程的目的.当然s ...
- mysql执行语句汇总
插入select的数据 INSERT INTO `test1`( order_id, goods_id, goods_name, goods_sn, product_id, goods_number, ...
随机推荐
- FM的推导原理--推荐系统
FM:解决稀疏数据下的特征组合问题 Factorization Machine(因子分解机) 美团技术团队的文章,觉得写得很好啊:https://tech.meituan.com/deep-unde ...
- group by 并且 count(1)的linq写法
SELECT [MobleNo],count(1) FROM [CustMobleNo] group by [MobleNo] GO ===作用等于=== var rst = from c in da ...
- AdvStringGrid 垂直居中 、水平居中
官网faq,解答: 结果:
- Effective STL 学习笔记 31:排序算法
Effective STL 学习笔记 31:排序算法 */--> div.org-src-container { font-size: 85%; font-family: monospace; ...
- PHP XML操作的各种方法解析
PHP提供了一整套的读取 XML文件的方法,很容易的就可以编写基于 XML的脚本程序.本章将要介绍 PHP与 XML的操作方法,并对几个常用的 XML类库做一些简要介绍. XML是一种流行的半结构化文 ...
- WepE
1. 计算机管理 第一个主:1024MB FAT32 活动,主分区 第二个主: * exFAT 主分区 都分配盘符2. WePE安装包 安装到移动硬盘 双启导 指定指一个主分区
- LoadRunner参数化取值与连接数据库
LoadRunner参数化取值与连接数据库 LoadRunner在使用参数化的时候,通常都是需要准备大数据量的,也因此LoadRunner提供两种参数化取值方式,一种是手动编辑,另一种就是通过连接 ...
- LoadRunner FAQ
LoadRunner FAQ web_concurrent_start和web_concurrent_end web_concurrent_start 语法: int web_concurrent_s ...
- hdu 5936 2016ccpc 杭州 - D
数学题好难啊!!!! 最长长度不超过十位, 折半枚举... 题解 #include<bits/stdc++.h> #define LL long long #define fi first ...
- mysql 存储过程详解
MySQL 存储过程是从 MySQL 5.0 开始增加的新功能.存储过程的优点有一箩筐.不过最主要的还是执行效率和SQL 代码封装.特别是 SQL 代码封装功能,如果没有存储过程,在外部程序访问数据库 ...