五行号 电商 DTrace 工具

DTrace 工具

转自:以下是使用DTrace的开源工具和示例,DTrace是动态跟踪的实现,可在不同的操作系统(Solaris…

转自:以下是使用DTrace的开源工具和示例,DTrace是动态跟踪的实现,可在不同的操作系统(Solaris、MacOSX、FreeBSD等)中使用。

DTrace通过提供应用程序和系统内部的新的详细视图来帮助解决服务器上的问题,该视图达到了以前难以或无法访问的级别。

它提供了一种编写DTrace脚本的语言,该语言类似于C和awk,并且是基于事件的。

有关更长的摘要,请参阅维基百科DTrace条目。

此网站包含我的许多第一个DTrace脚本,这些脚本是在2004-5年编写的,用于预发行版的Solaris10。

这些被开发成一个名为DTraceToolkit的集合,其中包含此处找到的较新版本的脚本。

我最近的收藏发表在右图的DTrace书(PrenticeHall,2011)中,其中包含许多新脚本。

这些新脚本可以在www.dtracebook.com网站上找到。

本页:Linux,指南,DTraceToolkit,DTraceOne-Liners,Scripts,Examples,DTraceTazTool,DExplorer,Links.操作系统DTrace可用于MacOSX、FreeBSD和Solaris系列操作系统:Solaris10、OracleSolaris11、SmartOS、OmniOS以及任何其他基于illumos内核的系统。

此页上的许多DTrace脚本最初都是为Solaris10编写的。

有些可以在其他操作系统上运行而无需更改,有些则需要稍作调整才能运行。

Linux从Linux4.9开始,Linux内核终于有了与DTrace类似的原始功能。

这是多年来合并在Linux内核中的许多跟踪项目和技术的高潮,包括:分析和PMC事件(perf_events)、内核静态跟踪(跟踪点)、内核动态跟踪(kprobes)和用户动态跟踪(uprobes)。

以前的Linux跟踪器是ftrace和perf_events。

新的Linux跟踪器建立在所有这些之上,是增强的BPF,具有多个可用的前端:特别是bcc和bpftrace。

请参阅我关于它的帖子:DTraceforLinux2016(eBPF)和DTraceforLinux2018(bpftrace)。

我还有一个关于LinuxeBPF跟踪的页面。

如果您想要类似DTraceToolkit的体验(预制工具),请查看BCC。

如果你想要一个类似DTrace的体验(D编程),请查看bpftrace。

我已经为两者发布了工具。

对于eBPF之前的Linux跟踪,我编写了一组ftrace和perf_events工具,类似于DTraceToolkit,它们运行在较旧的Linux内核:perf-tools,我也在LISA,Linux性能分析:新工具和旧秘密中谈到了这一点。

附加组件呢,如SystemTap,ktap等?既然eBPF已经包含在4.9中,所有附加组件都应该考虑将eBPF用于后端功能。

这始于2017年,并将在2019年继续,因为4.9内核的推出以及对eBPF工具的需求增加。

为了看到这些附加示踪剂的一些旧材料,我确实有一个ktap页面,并在2014年做了一个演讲,从DTrace到Linux。

至于DTrace本身,有两个项目可以将其移植到Linux:dtrace4linux项目,以及OracleLinux的不同端口。

这些端口似乎没有动力,而bcc/eBPF有。

指导如何开始使用DTrace?您可以通过仅运行脚本来使用DTrace,也可以自己编写脚本。

使用DTrace脚本不是每个人都有时间坐下来从头开始编写DTrace脚本,也没有时间学习如何编写。

不用担心,网上有很多脚本可供下载和使用。

您可以:下载DTraceToolkit查看DTraceOneLiners。

请参阅DTrace手册中的DTrace脚本和单行代码。

使用/usr/demo/dtrace或DTraceGuide中的脚本。

从本网站或其他网站下载脚本。

在DTrace邮件列表中搜索有用的脚本,或在Internet上的其他位置搜索。

编写DTrace脚本有些人会编写自己的自定义DTrace脚本来排除故障或解决性能问题。

它有助于了解C了解一点内核会有所帮助天空是极限要开始编写自己的脚本,请执行以下操作:至少阅读《DTrace指南》的第1章。

查看DTraceOneLiners。

通读DTrace示例。

学习脚本。

最好的顺序是kill.d,bitesize.d,sshkeysnoop.d,shellsnoop.d。

有关脚本,请参阅其他网站。

下载DTraceToolkit阅读DTrace书籍。

参与DTrace邮件列表。

注意:此站点上的许多DTrace脚本都包含在Bourneshell或Perl中,以提供命令行选项,从而允许通过遵循其他Unix工具的现有约定和样式,为系统管理员创建直观且易于学习的工具。

DTraceToolkit请参阅DTraceToolkit网站(请更新链接以指向它)。

地址:DTraceOneLiners#Newprocesseswitharguments:dtrace-n'proc:::exec-success{trace(curpsinfo->pr_psargs);}'#Filesopenedbyprocess:dtrace-n'syscall::open*:entry{printf("%s%s",execname,copyinstr(arg0));}'#Syscallcountbyprogram:dtrace-n'syscall:::entry{@num[execname]=count();}'#Syscallcountbysyscall:dtrace-n'syscall:::entry{@num[probefunc]=count();}'#Syscallcountbyprocess:dtrace-n'syscall:::entry{@num[pid,execname]=count();}'#Readbytesbyprocess:dtrace-n'sysinfo:::readch{@bytes[execname]=sum(arg0);}'#Writebytesbyprocess:dtrace-n'sysinfo:::writech{@bytes[execname]=sum(arg0);}'#Readsizedistributionbyprocess:dtrace-n'sysinfo:::readch{@dist[execname]=quantize(arg0);}'#Writesizedistributionbyprocess:dtrace-n'sysinfo:::writech{@dist[execname]=quantize(arg0);}'#Disksizebyprocess:dtrace-n'io:::start{printf("%d%s%d",pid,execname,args[0]->b_bcount);}'#Pagespagedinbyprocess:dtrace-n'vminfo:::pgpgin{@pg[execname]=sum(arg0);}'#Minorfaultsbyprocess:dtrace-n'vminfo:::as_fault{@mem[execname]=sum(arg0);}'#Profileuser-levelstacksat99Hertz,forPID189:dtrace-n'profile-99/pid==189&&arg1/{@[ustack()]=count();}'脚本下面演示了每个程序的操作带有下载代码的链接。

(注意:要获得最新版本的一个特定的脚本,还要检查DTraceToolkit中的版本)。

IOSnoop是一个用于窥探磁盘I/O活动的程序。

在这里我们可以观看直播是什么发生在我们的磁盘上,包括负责的PID和命令。

输出包括磁盘操作的块地址和大小-这是您第一次可以实时观看磁盘的运行情况。

#iosnoop
UIDPIDDBLOCKSIZECOMMPATHNAME
10015795R38088192tar/usr/bin/eject
10015795R359046144tar/usr/bin/eject
10015795R398286144tar/usr/bin/env
10015795R38728192tar/usr/bin/expr
10015795R211207168tar/usr/bin/expr
10015795R436806144tar/usr/bin/false
10015795R441766144tar/usr/bin/fdetach
10015795R39208192tar/usr/bin/fdformat
10015795R39368192tar/usr/bin/fdformat
10015795R40808192tar/usr/bin/fdformat
10015795R96803072tar/usr/bin/fdformat
[…]
下面说明了由熟悉的Unix命令引起的磁盘活动。

iosnoop在Solaris10x86服务器上执行,并绘制了数据-磁盘磁头位置(红色)和传输大小(蓝色)。

点击查看大图:在这里,执行了一个tar命令(tarcvf/dev/null/var)来存档目录,而iosnoop捕获了磁盘活动的前2秒。

当tar读取目录时会观察到一些分散的活动,并且当tar遇到大文件时可以观察到顺序传输。

更多iosnoop示例包含更多演示和情节。

独立iosnoop.d是一个DTrace这里只有带有示例的版本,旧的pre-io提供商iosnoop.d就在这里。

psio是另一个启用了DTrace的磁盘I/O工具。

iotop按进程显示顶部磁盘I/O事件。

这将按进程跟踪磁盘I/O,并打印摘要每隔一段时间刷新一次的报告。

完整示例。

首次发布。

检查更新。

#iotop-C
Sampling…Pleasewait.
2005Jul1600:31:38,load:1.03,disk_r:5023Kb,disk_w:22Kb

UIDPIDPPIDCMDDEVICEMAJMINDBYTES
02774020320tarcmdk010216W23040
02773920320findcmdk01020R668672
02774020320tarcmdk010216R1512960
02774020320tarcmdk01023R3108864

2005Jul1600:31:43,load:1.06,disk_r:8234Kb,disk_w:0Kb

UIDPIDPPIDCMDDEVICEMAJMINDBYTES
02773920320findcmdk01020R1402880
02774020320tarcmdk01023R7069696
[…]
execsnoop是一个窥探进程活动的程序。

执行进程时在服务器上打印出他们的详细信息。

另一个用户已登录运行一些命令,如下所示。

这特别有用对原本难以发现的短期进程进行故障排除。

更多例子。

#execsnoop
UIDPIDPPIDCMD
10030082656ls
10030092656ls-l
10030102656cat/etc/passwd
10030112656vi/etc/hosts
10030122656date
10030132656ls-l
10030142656ls
10030152656finger
[…]
Execsnoop可以选择添加日期和时间(-v),或观看特定命令(-c命令)。

独立execsnoop.d是原始的仅限DTrace的版本。

C版本:execsnoop.c是为了比较libdtraceC使用者和D脚本之间的开销而编写的。

opensnoop是一个程序来窥探文件打开。

文件名和文件句柄与一些过程详细信息一起跟踪。

更多例子。

#opensnoop-g
UIDPIDPATHFDARGS
1003528/var/ld/ld.config-1cat/etc/passwd
1003528/usr/lib/libc.so.13cat/etc/passwd
1003528/etc/passwd3cat/etc/passwd
1003529/var/ld/ld.config-1cal
1003529/usr/lib/libc.so.13cal
1003529/usr/share/lib/zoneinfo/Australia/NSW3cal
1003530/var/ld/ld.config-1ls-l
1003530/usr/lib/libc.so.13ls-l
1003530/var/run/name_service_door3ls-l
1003530/usr/share/lib/zoneinfo/Australia/NSW4ls-l
1003531/var/ld/ld.config-1uname-a
1003531/usr/lib/libc.so.13uname-a
[…]
Opensnoop可以选择添加日期和时间(-v),或观看特定文件名(-f路径名)。

独立opensnoop.d是原始的DTrace唯一的版本..RWSNOOPSnoop读/写事件。

这是在应用程序级别测量读取和写入-系统调用。

完整示例。

#rwsnoop
UIDPIDCMDDBYTESFILE
02924shR128/etc/profile
02924shR128/etc/profile
02924shR128/etc/profile
02924shR84/etc/profile
02925quotaR757/etc/nsswitch.conf
02925quotaR0/etc/nsswitch.conf
02925quotaR668/etc/passwd
02926catR55/etc/motd
02926catW55/devices/pseudo/pts@0:12
10020334sshdR56/devices/pseudo/clone@0:ptm
10020334sshdW100<unknown>
02926catR0/etc/motd
02927mailR757/etc/nsswitch.conf
02927mailR0/etc/nsswitch.conf
02927mailR275/etc/group
02927mailR668/etc/passwd
02924shR0/etc/profile
[…]
rwtopdisplaytopread/writebytesbyprocess.rwtopprintsasummaryreportthatisrefreshedatintervals.Thisismeasuringreadsandwritesattheapplicationlevel-syscalls.Fullexample.#rwtop
2005Jul2405:00:13,load:1.01,app_r:38Kb,app_w:8Kb

UIDPIDPPIDCMDDBYTES
02451utmpdR4
02032020347bashR21
1002031720314sshdR26
1002031720314sshdW68
0293420320psW140
02032020347bashW216
071svc.startdR672
0293520320dfW1225
0293620320lsW1466
0293620320lsR2485
1002033420331sshdR4241
1002033420331sshdW5717
0293420320psR31567
tcpsnoopsnoopTCPnetworkpacketsbyprocess.ThisanalysesTCPnetworkpacketsandprintstheresponsiblePIDandUID,plusstandarddetailssuchasIPaddressandport.ThiscapturestrafficofnewlycreatedTCPconnectionsthatwereestablishedwhilethisprogramwasrunning.ItcanhelpidentifywhichprocessesiscausingTCPtraffic.Fullexample.newrelease.checkforupdates.#tcpsnoop.d
UIDPIDLADDRLPORTDRRADDRRPORTSIZECMD
10020892192.168.1.536398->192.168.1.17954finger
10020892192.168.1.536398->192.168.1.17954finger
10020892192.168.1.536398<-192.168.1.17954finger
0242192.168.1.523<-192.168.1.15422454inetd
0242192.168.1.523->192.168.1.15422454inetd
0242192.168.1.523<-192.168.1.15422454inetd
0242192.168.1.523<-192.168.1.15422478inetd
0242192.168.1.523->192.168.1.15422454inetd
020893192.168.1.523->192.168.1.15422457in.telnetd
020893192.168.1.523<-192.168.1.15422454in.telnetd
020893192.168.1.523->192.168.1.15422478in.telnetd
020893192.168.1.523<-192.168.1.15422457in.telnetd
020893192.168.1.523->192.168.1.15422454in.telnetd
[…]
Standalonetcpsnoop.disaDTraceonlyversion..tcptopdisplaytopTCPnetworkpacketsbyprocess.ThiscapturestrafficofnewlycreatedTCPconnectionsthatwereestablishedwhilethisprogramwasrunning.ItcanhelpidentifywhichprocessesiscausingTCPtraffic.Fullexample.firstrelease.checkforupdates.#tcptop-C30
Sampling…Pleasewait.
2005Jul505:18:56,load:1.07,TCPin:3Kb,TCPout:112Kb

UIDPIDLADDRLPORTRADDRRPORTSIZENAME
0242192.168.1.579192.168.1.154283272inetd
0242192.168.1.523192.168.1.154284294inetd
020929192.168.1.579192.168.1.154283714in.fingerd
10020926192.168.1.536409192.168.1.1791160finger
10020927192.168.1.536410192.168.1.1791160finger
10020928192.168.1.536411192.168.1.1231627telnet
020313192.168.1.522192.168.1.1542852798sshd
020931192.168.1.523192.168.1.1542844622in.telnetd
10020941192.168.1.5858192.168.1.1514115712rcp

2005Jul505:19:26,load:1.04,TCPin:0Kb,TCPout:4Kb

UIDPIDLADDRLPORTRADDRRPORTSIZENAME
10020942192.168.1.536412192.168.1.1791160finger
020931192.168.1.523192.168.1.1542847411in.telnetd
[…]
udpsnoop.dsnoopUDPnetworkI/Obyprocess.ThisanalysesUCPnetworkI/OandprintstheresponsiblePIDandUID,plusstandarddetailssuchasIPaddressandport.ThistracksUDPread/writesbypayload.Fullexample.firstrelease!checkforupdates.#udpsnoop.d
UIDPIDLADDRLPORTDRRADDRRPORTSIZECMD
027127192.168.1.535534->192.168.1.15329nslookup
027127192.168.1.535534<-192.168.1.153181nslookup
1221192.168.1.5111<-192.168.1.13752456rpcbind
1221192.168.1.5111->192.168.1.13752428rpcbind
027128192.168.1.535116<-192.168.1.13752440rpc.sprayd
027128192.168.1.535116->192.168.1.13752424rpc.sprayd
027128192.168.1.535116<-192.168.1.13752444rpc.sprayd
027128192.168.1.535116<-192.168.1.13752444rpc.sprayd
027128192.168.1.535116<-192.168.1.13752444rpc.sprayd
027128192.168.1.535116<-192.168.1.13752444rpc.sprayd
027128192.168.1.535116<-192.168.1.13752444rpc.sprayd
027128192.168.1.535116<-192.168.1.13752444rpc.sprayd
027128192.168.1.535116<-192.168.1.13752444rpc.sprayd
027128192.168.1.535116<-192.168.1.13752444rpc.sprayd
027128192.168.1.535116<-192.168.1.13752444rpc.sprayd
027128192.168.1.535116<-192.168.1.13752444rpc.sprayd
027128192.168.1.535116<-192.168.1.13752440rpc.sprayd
027128192.168.1.535116->192.168.1.13752436rpc.sprayd
^C
connectionssnoopinboundTCPconnectionsastheyareestablished,displayingtheserverprocessthatacceptedtheconnection.Fullexampleishere.#connections
UIDPIDCMDTYPEPORTIP_SOURCE
0242inetdtcp79192.168.1.1
0359sshdtcp22192.168.1.1
1001532Xorgtcp6000192.168.1.1
^C
prustatThisdisplays%CPU,%Mem,%Diskand%Netutilisationbyprocess.ToexamineallfourkeyperformanceareasbyprocessinSolariswasprohibitivlydifficultwithoutDTrace.prustatalsousesPerl,Kstatandtheprocfsstructuresfrom/proc/*/*.Itisanewtoolandstillunderdevelopment,releasedasademonstration.Fullexample.#prustat-t55
PID%CPU%Mem%Disk%NetCOMM
2230165.013.170.000.00setiathome
4408.9145.390.000.00Xsun
26180.3314.340.000.00mozilla-bin
5824.012.160.000.00gnome-terminal
5741.801.310.000.00metacity
PID%CPU%Mem%Disk%NetCOMM
226943.740.2074.470.00tar
2230166.703.170.000.00setiathome
4406.6745.390.000.00Xsun
26180.3314.340.000.00mozilla-bin
226933.811.500.000.00dtrace
PID%CPU%Mem%Disk%NetCOMM
2230163.723.170.000.00setiathome
4408.1445.390.000.00Xsun
226946.470.2036.470.00tar
226980.000.006.8822.43rcp
26180.3414.340.000.00mozilla-bin
^C
dtrussThisisaDTraceversionoftruss,designedtobelessofaburdenandsaferthantruss.Inthebelowexample,dtrussexaminesallprocessesnamed"bash"andprintsoutregulartrussoutputpluselapsedandoverheadtimes.Seethefullexample.#dtruss-eonbash
PID/LWPELAPSDOVERHDSYSCALL(args)=return
3911/1:4126write(0x2,"l0",0x1)=10
3911/1:100157943read(0x0,"s0",0x1)=10
3911/1:3826write(0x2,"s0",0x1)=10
3911/1:101912943read(0x0,"0010",0x1)=10
3911/1:3826write(0x2,"0",0x1)=10
3911/1:99853343read(0x0,"-0",0x1)=10
3911/1:3826write(0x2,"-0010",0x1)=10
3911/1:109432342read(0x0,"l0",0x1)=10
3911/1:3927write(0x2,"l0010",0x1)=10
3911/1:121049644read(0x0,"r0",0x1)=10
[…]
procsystimeThisprogramprovidesprocesssystemcalldetailssuchaselapsedtimefromentrytoreturn,overheadtimeforCPUtimeconsumed,andcounts.Intheexamplebelowweexamine"ssh"processes.Fullexample.#procsystime-a-nssh
HitCtrl-Ctostopsampling…
^C

ElapsedTimesforprocessssh,

SYSCALLTIME(ns)
read295392
write622903
pollsys1030310531

CPUTimesforprocessssh,

SYSCALLTIME(ns)
read183515
write534289
pollsys650729

SyscallCountsforprocessssh,

SYSCALLCOUNT
read12
write12
pollsys24
hotuserSampleon-CPUuser-levelfunctionsandlibraries.Thissamplesat1000Hertz,forasimpleyeteffectiveuser-levelprofilingtool.TheoutputwillidentifywhichfunctionisontheCPUthemost-whichisthehottest.Thefollowingexamplesshowhotuseranalysinggunzipandgzip.Fullexample.#./hotuser-c'gunzipcontents.gz'
Sampling…HitCtrl-Ctoend.

FUNCTIONCOUNTPCNT
libc.so.1`_free_unlocked10.1%
gunzip`unzip10.1%
ld.so.1`strcmp10.1%
gunzip`inflate_dynamic10.1%
libc.so.1`_write10.1%
gunzip`write_buf10.1%
gunzip`0x2d99020.3%
libc.so.1`write20.3%
gunzip`0x2d99420.3%
ld.so.1`rtld_db_preinit30.4%
gunzip`0x2d98c70.9%
gunzip`huft_build91.2%
libc_psr.so.1`memcpy13818.5%
gunzip`inflate_codes23331.2%
gunzip`updcrc34446.1%

#./hotuser-lc'gzipcontents'
Sampling…HitCtrl-Ctoend.

LIBRARYCOUNTPCNT
libc.so.120.0%
libc_psr.so.1370.9%
gzip411399.1%
hotkernelSampleon-CPUkernel-levelfunctionsandmodules.Thissamplesat1000Hertz,forasimpleyeteffectivemodules-levelprofilingtool.TheoutputwillidentifywhichfunctionisontheCPUthemost-whichisthehottest.Thefollowingexamplesshowhotkernelanalyseanx86kernel.Fullexample.#./hotkernel
Sampling…HitCtrl-Ctoend.
^C
FUNCTIONCOUNTPCNT
unix`swtch10.1%
pcplusmp`apic_redistribute_compute10.1%
genunix`strrput10.1%
unix`sys_call10.1%
genunix`fsflush_do_pages10.1%
TS`ts_wakeup10.1%
genunix`callout_schedule_110.1%
unix`page_create_putback10.1%
unix`mutex_enter40.3%
unix`cpu_halt157599.2%

#./hotkernel-m
Sampling…HitCtrl-Ctoend.
^C
MODULECOUNTPCNT
usbms10.0%
specfs10.0%
uhci10.0%
sockfs20.0%
genunix280.6%
unix453999.3%
dapptraceThistracesuserandlibraryfunctionusage.Thisissimilartothe"apptrace"command,howevercanfetchextradetailssuchasfunctionelapsedtimesandon-cputimes.Belowisademonstrationofrunningdapptraceonthebannercommand,theuserfunctioncallsarebeingtraced.Fullexample.#dapptrace-eoFbannerhi

###
###
#######
###
###
###

ELAPSDCPUCALL(args)=return
..->__fsr(0x2,0x8047D7C,0x8047D88)
414<-__fsr=122
..->main(0x2,0x8047D7C,0x8047D88)
..->banner(0x8047E3B,0x80614C2,0x8047D38)
..->banset(0x20,0x80614C2,0x8047DCC)
296<-banset=36
..->convert(0x68,0x8047DCC,0x2)
263<-convert=319
..->banfil(0x8061412,0x80614C2,0x8047DCC)
252<-banfil=57
..->convert(0x69,0x8047DCC,0x2)
231<-convert=319
..->banfil(0x8061419,0x80614CA,0x8047DCC)
231<-banfil=57
30928<-banner=118
..->banprt(0x80614C2,0x8047D38,0xD27FB824)
349322<-banprt=74
dappprofThisprofilesuserandlibraryfunctionusage.Thisisacompaniontodapptrace,wheresummarydataisprintedratherthanasnoopofevents.Belowisademonstrationofrunningdappprofonthebannercommand.Fullexample.#dappprof-ceoTbannerhello

##############
#######
###############
#######
#######
########################

CALLCOUNT
__fsr1
main1
banprt1
banner1
banset1
convert5
banfil5
TOTAL:15

CALLELAPSED
banset38733
banfil150280
convert152113
banner907212
__fsr1695068
banprt1887674
TOTAL:4831080

CALLCPU
banset7710
convert9566
banfil11931
__fsr15199
banner52685
banprt776429
TOTAL:873520
dvmstatThisprogramprovidesvmstatlikedataforoneparticularPID,aprocessname,orwhenrunningacommand.Itprintsstatisticseverysecond.Herewemonitora"find"processes,andcanclearlyseeitexhaustthecache(dropping"re"reclaims),andthendefertodisk(increasing"maj"majorfaultsand"fpi"filesystempageins).Fullexample.#dvmstat-nfind
remajmffrepiepoapiapofpifposy
00000000000
00000000000
63360372000000022255
16240000000005497
22920000000007715
1306400000000043998
7972168000000168038361
468636000000636013774
376588000000588010723
80636000000656011078
4877200000081209841
1610280000001056010752
017120000001740012176
41224000000123609024
topsyscallThisprogramcontinuallyprintsareportofthetopsystemcalls,andrefreshesthedisplayevery1secondorasspecified.Fullexample.2005Jun1402:26:40,loadaverage:0.16,0.18,0.21syscalls:1381

SYSCALLCOUNT
waitsys5
getuid5
xstat7
munmap7
brk8
sysconfig8
open8
getpid9
close9
resolvepath10
setcontext18
setitimer25
mmap26
lwp_sigmask32
lwp_park41
write78
read78
sigaction113
pollsys318
ioctl526
shellsnoopcapturesthetextinputandoutputlivefromshellsrunningonthesystem.Inthisexampleshellsnoopwasruninonewindow,whileinanotherseveralcommandswererun:date,calanduname-a.(thisislikeasimpleversionofttywatcher).Fullexampleishere.#shellsnoop
PIDPPIDCMDDIRTEXT
47243762kshR
47243762kshWdate

47414724dateWSunMar2823:10:06EST2004
47243762kshR
47243762kshWjupiter:/etc/init.d>
47243762kshR
47243762kshR
47243762kshWcal

47424724calWMarch2004
47424724calWSMTuWThFS
47424724calW123456
47424724calW78910111213
47424724calW14151617181920
47424724calW21222324252627
47424724calW28293031
47424724calW
47243762kshR
47243762kshWjupiter:/etc/init.d>
47243762kshR
47243762kshR
47243762kshWuname-a

47434724unameWSunOSjupiter5.10s10_51i86pci386i86pc
47243762kshR
ShellsnoophasoptionstoviewaparticularPIDonly,andtoonlyviewdataprinted-whichissomewhatspooky.Standaloneshellsnoop.distheoriginalDTraceonlyversion..kill.dThissimpleDTraceprogramwatcheswhoissendingsignalstoprocesses.Intheexamplebelow,thebashshellsuccessfullysenta"kill-2"(SIGINT)toPID3117,andfailedtosenda"kill-9"(SIGKILL)toprocess12345,#kill.d
FROMCOMMANDSIGTORESULT
2344bash231170
2344bash912345-1
^C
errinforeportsonsystemcallfailureswithfullerrnodetailstohelpexplainwhytheseerrorsoccured.Ithastwostylesofoutput:a"snoop"styletowatchevents(thedefault),anda"count"styletoprovideasummary(-c).Botharedemonstratedbelow,Fullexample.#errinfo
EXECSYSCALLERRDESC
gnome-netstatus-ioctl12Notenoughcore
mozilla-binlwp_park62timerexpired
Xorgread11Resourcetemporarilyunavailable
Xorgpollsys4interruptedsystemcall
mozilla-binlwp_park62timerexpired
mozilla-binlwp_park62timerexpired
Xorgread11Resourcetemporarilyunavailable
^C
#errinfo-c
Sampling…HitCtrl-Ctoend.
^C
EXECSYSCALLERRCOUNTDESC
gnome-netstatus-ioctl121Notenoughcore
miniserv.plwaitsys101Nochildren
gnome-settings-dread111Resourcetemporarilyunavailable
metacityread111Resourcetemporarilyunavailable
gnome-panelread111Resourcetemporarilyunavailable
nautilusread111Resourcetemporarilyunavailable
dsdmread112Resourcetemporarilyunavailable
soffice.binread112Resourcetemporarilyunavailable
java_vmlwp_cond_wait624timerexpired
svc.startdportfs625timerexpired
Xorgpollsys415interruptedsystemcall
Xorgread1126Resourcetemporarilyunavailable
mozilla-binlwp_park6258timerexpired
sshkeysnoop.d从在同一服务器上运行的SSH客户端命令捕获击键。

虽然密码清晰可见,但这不是安全问题使用Solaris10更像是DTrace的强大功能的演示。

完整示例。

#sshkeysnoop.d
UIDPIDPPIDTYPETEXT
10096518600cmdssh-lfredmars

10096518600keyf
10096518600keyr
10096518600keye
10096518600keyd
10096518600key1
10096518600key2
10096518600key3
10096518600key
[…]
短命。

这个简单的DTrace程序测量短时间消耗了多少时间生活过程。

这通常很难通过采样发现像PRSTAT这样的工具。

在下面的示例中,许多生存期较短的“expr”命令实际上消耗了大约45%的CPU。

完整示例在这里。

#shortlived.d
Sampling..HitCtrl-Ctostop.
^C
shortlivedprocesses:3.394secs
totalsampleduration:7.543secs

Totaltimebyprocessname,
ls14ms
df18ms
expr3049ms

TotaltimebyPPID,
276532ms
297523049ms
cputimes打印内核/空闲/进程消耗的CPU时间。

默认输出将CPU时间细分打印为三类,内核时间、空闲时间以及流程消耗的时间;全部在纳秒内完成。

完整示例。

#cputimes13
2005Apr2723:37:58,
KERNEL10795499
PROCESS20941091
IDLE970707443
2005Apr2723:37:59,
KERNEL8919418
PROCESS77446789
IDLE910555040
2005Apr2723:38:00,
KERNEL8615123
PROCESS78314246
IDLE810100417
cpudists按内核/空闲/进程打印CPU时间分布。

默认输出按三个类别打印CPU时间使用情况:内核时间、空闲时间和处理时间。

该值是以纳米为单位的时间和计数是出现次数。

完整示例。

#cpudists51
2005Apr2800:08:42,
KERNEL
value————-Distribution————-count
4096|0
8192|@@@@@@@@@@@@@@@@@@@@@@@@@@@@1134
16384|@@@@@@@@@344
32768|@@@104
65536|3
131072|0

PROCESS
value————-Distribution————-count
8192|0
16384|@@@@@@@@@170
32768|@@@@@@@@@@@@@@@@@@331
65536|@@@@@@@@152
131072|@17
262144|@25
524288|@13
1048576|4
2097152|0

IDLE
value————-Distribution————-count
2097152|0
4194304|@9
8388608|@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@418
16777216|@@@31
33554432|0
setuids.dsnoopsetuidcalls.这可用于监视用户登录和“su”使用情况。

完整示例在这里。

#setuids.d
UIDSUIDPPIDPIDPCMDCMD
010030373040in.telnetdlogin-p-hmars-d/dev/pts/12
100030403045bashsu-
010230453051shsu-fred
010030553059sshd/usr/lib/ssh/sshd
010030653067in.rlogindlogin-d/dev/pts/12-rmars
010030713073in.rlogindlogin-d/dev/pts/12-rmars
010230783081in.telnetdlogin-p-hmars-d/dev/pts/12
[…]
bitesize.d是一个简单的程序,用于检查进程使用磁盘-它们是否会导致大型I/O操作或许多小“咬”?在下面的示例中,我们可以看到find命令主要导致1K事件,而tar命令每次操作传输更多数据。

完整示例。

#bitesize.d
Sampling…HitCtrl-Ctoend.
^C

PIDCMD
7109find/

value————-Distribution————-count
512|0
1024|@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@1452
2048|@@91
4096|33
8192|@@97
16384|0

3fsflush

value————-Distribution————-count
4096|0
8192|@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@449
16384|0

7108tarcf/dev/null/

value————-Distribution————-count
256|0
512|70
1024|@@@@@@@@@@1306
2048|@@@@569
4096|@@@@@@@@@1286
8192|@@@@@@@@@@1403
16384|@190
32768|@@@396
65536|0
[…]
seeksize.d按进程打印磁盘磁头寻道距离。

这可以识别进程是以“随机”还是“顺序”方式访问磁盘方式。

下面的示例说明了顺序访问。

用Seeksize.d与bitesize.d结合使用。

完整示例。

#seeksize.d
Sampling…HitCtrl-Ctoend.
^C

PIDCMD
22349scp/dl/sol-10-b63-x86-v1.isomars:

value————-Distribution————-count
-1|0
0|@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@726
1|0
2|0
4|0
8|@13
16|4
32|0
[…]
zvmstat是vmstat的DTrace版本,用于打印每个区域的信息。

更多例子在这里。

#zvmstat1
ZONEremffrsrepiepoepfapiapoapffpifpofpf
global5431610000000011
workzone10000000000000
ZONEremffrsrepiepoepfapiapoapffpifpofpf
global157659101000000321
workzone1770108500480000092800
ZONEremffrsrepiepoepfapiapoapffpifpofpf
global5631700600000200
workzone114782100000000163500
[…]
zhostid是一个DTrace守护程序,用于将每个区域的主机ID更改为不同的值。

更多例子在这里。

global#./zhostid&
[1]8717
global#hostid
12345678
global#
global#zloginworkzone1
[Connectedtozone'workzone1'pts/10]
Lastlogin:TueJun2103:51:10onpts/10
SunMicrosystemsInc.SunOS5.10GenericJanuary2005
#
#hostid
90abcdef
套接字侦听此程序窥探套接字按进程划分数据传输事件,确定哪个进程负责用于在网络上读取或写入数据。

完整示例。

#socketsnoop.d
UIDPIDDIRSIZECMD
019886W64sshmars
019886R80sshmars
019915W0finger@mars
019915W2finger@mars
019915R633finger@mars
019915R0finger@mars
019886W64sshmars
019886R80sshmars
019886W48sshmars
019886R80sshmars
1004789W6vncviewermars:4
1004789R348vncviewermars:4
1004789W10vncviewermars:4
[…]
Anonprofile.d是一个窥探匿名内存使用情况的程序按流程。

这提供了进程匿名内存的配置文件随时间推移的大小。

它可以帮助解决内存问题软件开发。

更多例子在这里。

#anonprofile.d
UIDPIDTOTALARGS
0143804169728/usr/sbin/dtrace-sanonprofile.d
100143824096bash
100143828192ls-l
1001438212288ls-l
1001438220480ls-l
1001438224576ls-l
1001438228672ls-l
1001438257344ls-l
1001438265536ls-l
1001438273728ls-l
10014382106496ls-l
10014382110592ls-l
10014382118784ls-l
10014382126976ls-l
10014382131072ls-l
10014382135168ls-l
10014382143360ls-l
[…]
intrtimeTimespentbythekernelininterruptthreadswaspreviouslydifficulttomeasure.intrtimegivesabreakdownoftheinterrupttypesandtimesspentservicingeach.Fullexample.#intrtime1
InterruptTime(ns)%Time
uhci_intr237530.00
ata_intr36980890.37
i8042_intr73603990.73
gld_intr123195081.22
TOTAL(int)234017492.31
TOTAL(dur)1012546207100.00
typewriter-0.75.tar.gzThismakesyourconsolekeyboardsoundlikeamechanicalkeyboard.Thisisforentertainmentonly.#./ultra5.d&
[1]7660
typewriter.drunningfortheconsolekeyboard.
#
TroubleshootingExamplesTheseareexamplesofperformingtroubleshootingusingDTrace,andoftenbeginbyusingDTraceatthecommandlinebeforeusingDTracescriptssuchasthetoolsabove.DTracevstrussthisdemonstratestheperformaceimpactofusingDTracevstruss.DTraceisdesignedtominimisetheburdenonthesystemwhileitisrunning.DTracingSMCherewehaveaquicklookatusingDTracetoinvestigatethebehaviourofSMCwhenitisfirstexecuted.SMCisasystemadministrationGUIthattakesawhilethefirsttimeitisrunasitcompilesJavaclasses.DTracingLostCPUherewetakealookatamysteriousproblemwheretheCPUsarebusy,buttheredosen'tappeartobeanyprocessesresponsibleforthis.WherehastheCPUtimegone?prstatvstopthisanalysestheCPUoverheadofrunningprstatvsrunningtop.InthepastsomepeoplehavesuggestedthattopisaCPUhog-DTracecanmeasureit.DTraceTazToolSeveralyearsago,RichardMcDougallwrotetaztool-aGUItodisplaydiskactivityinanamazingandintuitiveway.ItusedTNFtracedata-apredecessorofDTrace.DTraceTazToolisaDTraceversionoftaztool.Itiscurrentlyindevelopment,andassuchthisisanalpharelease.Therearemanymorefeaturestocode,butitmayalreadyproveausefultool.ThecurrentversionofDTraceTazToolis:DTaz-0.51.ThefollowingimageshowsDTraceTazTooltracingtheactivityofaUFSfilesystemasitwasarchivedbythetarcommand.Forthetopplot:therequestedblocklocationisontheY-axis,timeisontheX-axis,andthecolourreflectsthenumberofrequestsforthatlocation(many==red).Thebottomplotshowsmaximumandaverageseekdistance,粗红线表示连续的磁盘活动,分散的蓝色块表示随机磁盘活动。

DTraceTazTool已经有一些可调选项,如绘制的像素和采样率,DTraceTazTool需要以root用户身份运行,或者以用户身份运行。

dtrace_kernel特权。

DExplorer探险家搜索器自动运行一组DTrace脚本进行检查系统的许多区域,并将输出放在一个有意义的目录中焦油和gzip的结构。

下面是一个示例版本0.70。

完整示例。

#dexplorer
Outputdirwillbethecurrentdir(/export/home/root/DTrace/Dexplorer).
Hitenterforyes,ortypepath:
Startingdexplorerver0.70.
Sampleintervalis5seconds.Totalrunis>100seconds.
0%InterruptsbyCPU…
5%Interruptcounts…
10%DispatcherqueuelengthbyCPU…
15%Sdtcounts…
20%Pagespagedinbyprocessname…
25%Filesopenedcount…
30%DiskI/Osizedistributionbyprocessname…
35%Minorfaultsbyprocessname…
40%Vminfodatabyprocessname…
45%Mibdatabymibstatistic…
50%TCPwritebytesbyprocess…
55%Sampleprocess@1000Hz…
60%Syscallcountbyprocessname…
65%Syscallcountbysyscall…
70%Readbytesbyprocessname…
75%Writebytesbyprocessname…
80%Sysinfocountsbyprocessname…
85%Newprocesscountswitharguments…
90%Signalcounts…
95%Syscallerrorcounts…
100%Done.
Fileisde_jupiter_200506271803.tar.gz
#
#ls-lde_jupiter_200506271803.tar.gz
-rw-r–r–1rootroot6346Jun2718:05de_jupiter_200506271803.tar.gz
输出文件可用于发送给其他人进行分析。

链接书:DTrace:DynamicTracinginOracleSolaris,MacOSXandFreeBSD-BrendanGregg,JimMauro(PrenticeHall,2011).SolarisPerformanceandTools:DTraceandMDBTechniquesforSolaris10andOpenSolaris-RichardMcDougall,JimMauro,BrendanGregg(PrenticeHall,2006).DTrace指南-DTraceTeam其他DTrace脚本:DTracebook-来自DTracebook的脚本。

SolarisInternals-RichardMcDougall的DTrace脚本。

外部DTrace链接:布伦丹的博客-我的专业博客(见dtrace标记的帖子)。

TheWall-我的个人博客,包括DTraceToolkit公告。

观景台-布莱恩·坎特里尔的博客(DTraceTeam)。

AdamLeventhal'sBlog-(DTraceTeam)。

$<blog-MikeShapiro的博客(DTraceTeam)。

上下文切换DTrace-包含我的研讨会演示幻灯片。

DTT演示文稿-StefanParvu的DTrace和DTraceToolkit演示。

DTraceCommunity-(已停用)OpenSolarisDTrace社区网站。

BigAdminDTrace-(已退休)Sun的BigAdminDTrace网站。

本文来自网络,不代表五行号立场,转载请注明出处:https://www.wuxinghao.com/news/99001.html

作者: IC信徒

IC行业自由撰稿人,专注于IC行业知识分享。
返回顶部