pt-ioprofile是用来观察特定进程的IO信息的。

该脚本是用shell写的,有两方面的作用:

pt-ioprofile does two things: ) get lsof+strace for -s seconds, ) aggregate the result. If you specify a FILE, then step ) is not performed.

因实际依赖的是strace命令,该命令会对进程的性能造成较大的影响。所以,在负载较重的系统中,慎用。

使用方法:

直接执行pt-ioprofile即可,默认的是mysqld进程。

# pt-ioprofile

Sun Oct  :: CST
Tracing process ID
total pread read pwrite write fsync open close lseek fcntl filename
4.591996 0.000000 0.000000 0.088374 0.000000 4.503148 0.000219 0.000070 0.000000 0.000185 /test/sbtest5.ibd
2.720128 0.000000 0.000000 0.096999 0.000000 2.622662 0.000254 0.000053 0.000000 0.000160 /test/sbtest6.ibd
0.009918 0.000193 0.000515 0.000235 0.002752 0.004530 0.000491 0.000182 0.001020 0.000000 /test/#sql-693_153.frm
0.007725 0.000917 0.000000 0.002182 0.000000 0.003766 0.000285 0.000575 0.000000 0.000000 /test/
0.004819 0.000162 0.000587 0.000097 0.001044 0.001735 0.000349 0.000157 0.000688 0.000000 /test/sbtest6.frm
0.004201 0.000104 0.000309 0.000090 0.001048 0.001900 0.000265 0.000152 0.000333 0.000000 /test/sbtest5.frm
0.000661 0.000092 0.000209 0.000000 0.000000 0.000000 0.000105 0.000091 0.000164 0.000000 /tmp/ibUARemw
0.000643 0.000075 0.000254 0.000000 0.000000 0.000000 0.000128 0.000044 0.000142 0.000000 /test/sbtest4.frm
0.000228 0.000000 0.000000 0.000000 0.000000 0.000000 0.000143 0.000085 0.000000 0.000000 /tmp/ib2bbcaJ
0.000221 0.000000 0.000000 0.000000 0.000000 0.000000 0.000170 0.000051 0.000000 0.000000 /tmp/ibp3wGXR
0.000219 0.000000 0.000000 0.000000 0.000000 0.000000 0.000168 0.000051 0.000000 0.000000 /tmp/ibEDs8K7

其中,

read:从文件中读出数据。要读取的文件用文件描述符标识,数据读入一个事先定义好的缓冲区。

write:把缓冲区的数据写入文件中。

pread:由于lseek和read调用之间,内核可能会临时挂起进程,所以对同步问题造成了问题,调用pread相当于顺序调用了lseek和read,这两个操作相当于一个捆绑的原子操作。

pwrite:由于lseek和write调用之间,内核可能会临时挂起进程,所以对同步问题造成了问题,调用pwrite相当于顺序调用了lseek 和write,这两个操作相当于一个捆绑的原子操作。

fsync:确保文件所有已修改的内容已经正确同步到硬盘上,该调用会阻塞等待直到设备报告IO完成。

open:打开一个文件,并返回这个文件的描述符。

close:close系统调用用于“关闭”一个文件,close调用终止一个文件描述符以其文件之间的关联。文件描述符被释放,并能够重新使用。

lseek:对文件描述符指定文件的读写指针进行设置,也就是说,它可以设置文件的下一个读写位置。

fcntl:针对(文件)描述符提供控制。

看看各参数的作用:

--aggregate

统计的方式,默认是sum,也可指定为avg。

个人感觉avg没太大意义。

short form: -a; type: string; default: sum

The aggregate function, either sum or avg.

If sum, then each cell will contain the sum of the values in it. If avg, then each cell will contain the average of the values in it.

--cell

显示的单位,默认是times,即IO操作的时间,也可指定为count(O操作的次数),size(IO操作的大小)

如下所示:

--cell=times

# pt-ioprofile
Sun Oct :: CST
Tracing process ID
total pread read pwrite write fsync open close lseek fcntl filename
4.591996 0.000000 0.000000 0.088374 0.000000 4.503148 0.000219 0.000070 0.000000 0.000185 /test/sbtest5.ibd
2.720128 0.000000 0.000000 0.096999 0.000000 2.622662 0.000254 0.000053 0.000000 0.000160 /test/sbtest6.ibd
0.009918 0.000193 0.000515 0.000235 0.002752 0.004530 0.000491 0.000182 0.001020 0.000000 /test/#sql-693_153.frm
0.007725 0.000917 0.000000 0.002182 0.000000 0.003766 0.000285 0.000575 0.000000 0.000000 /test/
0.004819 0.000162 0.000587 0.000097 0.001044 0.001735 0.000349 0.000157 0.000688 0.000000 /test/sbtest6.frm
0.004201 0.000104 0.000309 0.000090 0.001048 0.001900 0.000265 0.000152 0.000333 0.000000 /test/sbtest5.frm
0.000661 0.000092 0.000209 0.000000 0.000000 0.000000 0.000105 0.000091 0.000164 0.000000 /tmp/ibUARemw
0.000643 0.000075 0.000254 0.000000 0.000000 0.000000 0.000128 0.000044 0.000142 0.000000 /test/sbtest4.frm
0.000228 0.000000 0.000000 0.000000 0.000000 0.000000 0.000143 0.000085 0.000000 0.000000 /tmp/ib2bbcaJ
0.000221 0.000000 0.000000 0.000000 0.000000 0.000000 0.000170 0.000051 0.000000 0.000000 /tmp/ibp3wGXR
0.000219 0.000000 0.000000 0.000000 0.000000 0.000000 0.000168 0.000051 0.000000 0.000000 /tmp/ibEDs8K7

--cell=sizes

# pt-ioprofile --cell=sizes
Sun Oct :: CST
Tracing process ID
total pread read pwrite write fsync open close lseek fcntl filename
/test1/sbtest3.ibd
/test1/sbtest2.ibd
/test1/sbtest4.ibd
/test1/
/test1/#sql-693_164.frm
/test1/sbtest3.frm
/test1/sbtest2.frm
/test1/sbtest4.frm
/test1/sbtest1.frm
/tmp/ibyD2qvV
/tmp/ibyc3Nz5
/tmp/ibJI3Ky8
/tmp/ibbLjhsI
/tmp/ib8QdnAm
/tmp/ib7oksHs

--cell=count

# pt-ioprofile --cell=count
Sun Oct :: CST
Tracing process ID
total pread read pwrite write fsync open close lseek fcntl filename
/test1/sbtest5.ibd
/test1/sbtest6.ibd
/test1/sbtest7.ibd
/test1/#sql-693_164.frm
/test1/sbtest6.frm
/test1/sbtest5.frm
/test1/sbtest7.frm
/test1/
/tmp/ibtLXAL6
/tmp/ibDei5Io
/tmp/ib2WdhKK
/tmp/ib027CfV
/test1/sbtest4.frm
short form: -c; type: string; default: times
The cell contents.
Valid values are:
VALUE CELLS CONTAIN
===== =======================
count Count of I/O operations
sizes Sizes of I/O operations
times I/O operation timing

--group-by

分组的单位,默认是filename,即对文件名进行统计,也可指定为all,即对所有操作进行统计,pid,对进程进行统计(不太确定这里的进程指的是什么?怀疑是线程,但线程不可能这么少,具体可参考下面的输出)

--group-by=filename

# pt-ioprofile
Sun Oct :: CST
Tracing process ID
total pread read pwrite write fsync open close lseek fcntl filename
4.591996 0.000000 0.000000 0.088374 0.000000 4.503148 0.000219 0.000070 0.000000 0.000185 /test/sbtest5.ibd
2.720128 0.000000 0.000000 0.096999 0.000000 2.622662 0.000254 0.000053 0.000000 0.000160 /test/sbtest6.ibd
0.009918 0.000193 0.000515 0.000235 0.002752 0.004530 0.000491 0.000182 0.001020 0.000000 /test/#sql-693_153.frm
0.007725 0.000917 0.000000 0.002182 0.000000 0.003766 0.000285 0.000575 0.000000 0.000000 /test/
0.004819 0.000162 0.000587 0.000097 0.001044 0.001735 0.000349 0.000157 0.000688 0.000000 /test/sbtest6.frm
0.004201 0.000104 0.000309 0.000090 0.001048 0.001900 0.000265 0.000152 0.000333 0.000000 /test/sbtest5.frm
0.000661 0.000092 0.000209 0.000000 0.000000 0.000000 0.000105 0.000091 0.000164 0.000000 /tmp/ibUARemw
0.000643 0.000075 0.000254 0.000000 0.000000 0.000000 0.000128 0.000044 0.000142 0.000000 /test/sbtest4.frm
0.000228 0.000000 0.000000 0.000000 0.000000 0.000000 0.000143 0.000085 0.000000 0.000000 /tmp/ib2bbcaJ
0.000221 0.000000 0.000000 0.000000 0.000000 0.000000 0.000170 0.000051 0.000000 0.000000 /tmp/ibp3wGXR
0.000219 0.000000 0.000000 0.000000 0.000000 0.000000 0.000168 0.000051 0.000000 0.000000 /tmp/ibEDs8K7

--group-by=all

# pt-ioprofile --group-by=all
Sun Oct :: CST
Tracing process ID
8.044078 TOTAL
7.781329 fsync
0.245823 pwrite
0.004445 write
0.003389 read
0.002998 open
0.002324 lseek
0.001886 close
0.001679 pread
0.000205 fcntl

--group-by=pid

# pt-ioprofile --group-by=pid
Sun Oct :: CST
Tracing process ID
total pread read pwrite write fsync open close lseek fcntl pid
5.468350 0.002442 0.004444 0.111051 0.007580 5.320658 0.002614 0.003022 0.016232 0.000307
1.093664 0.000000 0.000000 0.000000 0.000000 1.093664 0.000000 0.000000 0.000000 0.000000
0.997042 0.000000 0.000000 0.000000 0.000000 0.997042 0.000000 0.000000 0.000000 0.000000
0.940387 0.000000 0.000000 0.000000 0.000000 0.940387 0.000000 0.000000 0.000000 0.000000
0.507274 0.000000 0.000000 0.000000 0.000000 0.507274 0.000000 0.000000 0.000000 0.000000
short form: -g; type: string; default: filename
The group-by item.
Valid values are:
VALUE GROUPING
===== ======================================
all Summarize into a single line of output
filename One line of output per filename
pid One line of output per process ID

--help

Print help and exit.

--profile-pid

指定线程的ID

short form: -p; type: int

The PID to profile, overrides --profile-process.

--profile-process

指定线程名

short form: -b; type: string; default: mysqld

The process name to profile.

--run-time

执行strace命令的时间,OPT_RUN_TIME就是--run-time指定的值。

源码如下:

 if [ "$proc_pid" ]; then
echo "Tracing process ID $proc_pid" _lsof "$proc_pid" > "$samples" >&
if [ "$?" -ne "" ]; then
echo "Error: could not execute lsof, error code $?"
EXIT_STATUS=
return
fi strace -T -s -f -p $proc_pid >> "$samples" >& &
if [ "$?" -ne "" ]; then
echo "Error: could not execute strace, error code $?"
EXIT_STATUS=
return
fi
strace_pid=$!
# sleep one second then check to make sure the strace is
# actually running
sleep
ps -p $strace_pid > /dev/null >&
if [ "$?" -ne "" ]; then
echo "Cannot find strace process" >&
tail "$samples" >&
EXIT_STATUS=
return
fi
# sleep for interval -, since we did a one second sleep
# before checking for the PID of strace
if [ $((${OPT_RUN_TIME}-)) -gt ]; then
sleep $((${OPT_RUN_TIME}-))
fi kill -s $strace_pid sleep
kill -s $strace_pid >/dev/null # Sometimes strace leaves threads/processes in T status.
kill -s $proc_pid # Summarize the output we just generated.
tabulate_strace "$samples" > $PT_TMPDIR/tabulated_samples
type: int; default: 

How long to profile.

--save-samples

将strace和lsof获取的结果保存到指定的文件中

type: string

Filename to save samples in; these can be used for later analysis.

--version

Print the tool’s version and exit.

参考

1. http://blog.csdn.net/zongcai249/article/details/17598411

2. http://www.cnblogs.com/yanlingyin/archive/2012/08/04/2617209.html

3. http://blog.csdn.net/cywosp/article/details/8767327

pt-ioprofile的更多相关文章

  1. PX 和PT的区别

    字体大小的设置单位,常用的有2种:px.pt.这两个有什么区别呢? 先搞清基本概念:px就是表示pixel,像素,是屏幕上显示数据的最基本的点: pt就是point,是印刷行业常用单位,等于1/72英 ...

  2. css中单位px、pt、em和rem的区别

    国内的设计师大都喜欢用px,而国外的网站大都喜欢用em和rem,那么三者有什么区别,又各自有什么优劣呢? px :像素(Pixel).相对长度单位.像素px是相对于显示器屏幕分辨率而言的.(引自CSS ...

  3. 快速安装Percona pt工具

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

  4. ((uchar*)(Img1->imageData + Img1->widthStep*pt.y))[pt.x] 的 具体含义

    widthstep是指图像每行所占的字节数. 主要要和width区别: width是表示图像的每行像素数,widthStep指表示存储一行像素需要的字节数. 在OpenCV里边,widthStep必须 ...

  5. Android中的dp, px, pt

    定义: px是像素,表示屏幕显示的最小元素单位 pt是磅数,一磅等于1/72英寸,一般用来作为字体的单位使用 问题: px和pt不使用于手机,因为同样的px在高低分辨率的手机上显示的比例不同 解决办法 ...

  6. css中font-size的单位总结:px、em、pt

    px:基于像素的单位.像素是一种有用的单位,因为在任何媒体上都可以保证一个像素的差别确实是可见的.em :一般用来测量长度的通用单位(例如元素周转的页边空白和填充),当用于指定字体大小时,em单位是指 ...

  7. UI设计中px、pt、ppi、dpi、dp、sp之间的关系

    UI设计中px.pt.ppi.dpi.dp.sp之间的关系 武汉AAA数字艺术教育 2015-07-24 14:19:50 职业教育 pi px 阅读(3398) 评论(0) 声明:本文由入驻搜狐公众 ...

  8. 关于pt与px

    pt:point,点,是印刷业一个标准的长度单位,1pt=1/72英寸:  在Windows里,默认的显示设置中,把文字定义为96dpi.这说明了:1px=1/96英寸:而1pt=1/72英寸,可以得 ...

  9. Android中dip、dp、sp、pt和px的区别

    1.概述 过去,程序员通常以像素为单位设计计算机用户界面.例如:图片大小为80×32像素.这样处理的问题在于,如果在一个每英寸点数(dpi)更高的新显示器上运行该程序,则用户界面会显得很小.在有些情况 ...

  10. 必备:常用px,pt,em换算表(转)

    常用px,pt,em换算表 pt (point,磅):是一个物理长度单位,指的是72分之一英寸. px (pixel,像素):是一个虚拟长度单位,是计算机系统的数字化图像长度单位,如果px要换算成物理 ...

随机推荐

  1. Vagrant 基础全面解析

    这篇 Vagrant 入门文章将带你创建一个 Vagrant 项目,这个过程将会用到 Vagrant 所提供的主要基本特性.如果想了解 Vagrant 能为你带来哪些好处,可以阅读 Vagrant 官 ...

  2. 使用Python保存屏幕截图(不使用PIL)

    起因 在极客学院讲授<使用Python编写远程控制程序>的课程中,涉及到查看被控制电脑屏幕截图的功能. 如果使用PIL,这个需求只需要三行代码: from PIL import Image ...

  3. 【知识必备】内存泄漏全解析,从此拒绝ANR,让OOM远离你的身边,跟内存泄漏say byebye

    一.写在前面 对于C++来说,内存泄漏就是new出来的对象没有delete,俗称野指针:而对于java来说,就是new出来的Object放在Heap上无法被GC回收:而这里就把我之前的一篇内存泄漏的总 ...

  4. 搞个这样的APP要多久?

    这是一个“如有雷同,纯属巧合”的故事,外加一些废话,大家请勿对号入座.开始了…… 我有些尴尬地拿着水杯,正对面坐着来访的王总,他是在别处打拼的人,这几年据说收获颇丰,见移动互联网如火如荼,自然也想着要 ...

  5. .net 分布式架构之业务消息队列

    开源QQ群: .net 开源基础服务  238543768 开源地址: http://git.oschina.net/chejiangyi/Dyd.BusinessMQ ## 业务消息队列 ##业务消 ...

  6. 在vim中使用查找命令查找指定字符串

    要自当前光标位置向上搜索,请使用以下命令:         /pattern   Enter           其中,pattern   表示要搜索的特定字符序列.         要自当前光标位置 ...

  7. ASP.NET Core 中文文档 第四章 MVC(4.3)过滤器

    原文:Filters 作者:Steve Smith 翻译:刘怡(AlexLEWIS) 校对:何镇汐 ASP.NET MVC 过滤器 可在执行管道的前后特定阶段执行代码.过滤器可以配置为全局有效.仅对控 ...

  8. margin折叠-从子元素margin-top影响父元素引出的问题

    正在做一个手机端电商项目,顶部导航栈的布局是一个div包含一个子div,如果给在正常文档流中的子div一个垂直margin-top,神奇的现象出现了,两父子元素的边距没变,但父div跟着一起往下走了! ...

  9. 自制Azure中国版“加血包”

    Micrsoft Azure中国版的国际出口最近升级为电话线拨号模式,目测为10个用户共享一条56kb的电话线拨号链路.有图有真相: 中国的IT从业者,有三分之一的职业生涯时间是在跟网络斗智斗勇.这点 ...

  10. ABP源码分析二:ABP中配置的注册和初始化

    一般来说,ASP.NET Web应用程序的第一个执行的方法是Global.asax下定义的Start方法.执行这个方法前HttpApplication 实例必须存在,也就是说其构造函数的执行必然是完成 ...