Académique Documents
Professionnel Documents
Culture Documents
SystemTap
S%ripting $anguage an& too$s
&ynami% tra%ing'pro(ing
) ) ) ) erne$ *un%tions system %a$$s +erne$,spa%e events User,spa%e events - newest versions .
/ass 1; parse& user s%ript < < /ass =; starting run4 #ea& per*orme& /ass =; run %omp$ete& in 10usr'>0sys'?2@ rea$ ms4
2012 IBM Corporation
event is
) ) ) ) erne$4*un%tion1 pro%ess4statement1 timer4ms1 (egin1 en& -tapset a$iases.4
/ro(e examp$e
I %at simp$e4stp
IJ'usr'(in'stap pro(e (egin 5print*-K/ro(e starte&7nK.9: pro(e timer4se%-@. 5exit-.9: pro(e en& 5print*-K/ro(e en&e&7nK.9:
Trans$ates the s%ript into C %o&e Compi$es C an& Lenerates a erne$ mo&u$e Inserts the mo&u$e9
pro(e examp$e
I %at siga$tsta% 4stp
pro(e erne$4*un%tion-KsysDsiga$tsta% K. 5
print*-KsysDsiga$tsta% %a$$e&7nK.9 :
sys%a$$4rea&
when entering rea&-. system %a$$
sys%a$$4%$ose4return
when returning *rom the %$ose-. system %a$$
mo&u$e-KC&as&CK.4*un%tion-KCK.
when entering any *un%tion in the K&as&K mo&u$e
erne$4*un%tion-KCMnet'so% et4%K.4return
returning *rom any *un%tion in *i$e net'so% et4%
erne$4statement-KCM erne$'s%he&4%;2N1>K.
when hitting $ine 2N1> o* *i$e erne$'s%he&4%
2012 IBM Corporation
timer4ms-200.
every 200 mi$$ise%on&s
pro%ess-K'(in'$sK.4*un%tion-KCK.
entering any *un%tion in '(in'$s -not its $i(raries or sys%a$$s.
pro%ess-K'$i('$i(%4so4QK.4*un%tion-KCma$$o%CK.
entering any g$i(% *un%tion with Kma$$o%K in its name
erne$4*un%tion-KCinitCK.1 erne$4*un%tion-KCexitCK.4return
entering any erne$ *un%tion whi%h has KinitK in its name or returning *rom any erne$ *un%tion with KexitK in its name
erne$4*un%tion-6may not exist8. R 5 444 : erne$4*un%tion-6this might exist8. J1 erne$4*un%tion-6i* not then this shou$&8. J1 erne$4*un%tion-6i* a$$ e$se *ai$s8. 5 444 :
Con&itiona$ pro(es
Fi$ter
3an&$er Constru%ts
Taria($es
S%ript Target
Taria($es
S%ript varia($es
L$o(a$ or $o%a$ Eutomati%a$$y type&; type in*erre& *rom assignment ) Integers -Q?,(it signe&. ) Strings ) Esso%iative arrays -g$o(a$ on$y.1 ) Statisti%s aggregates -g$o(a$ on$y. Eutomati%a$$y initia$ize& to zero'empty
Taria($es examp$e
I %at vars4stp g$o(a$ xSQ? g$o(a$ arr pro(e (egin 5 i S 10 name S KMi eK arrU0V S 1 arrU2V S @ print*-K x; O&7n i; O&7n name; Os7nK1 x1i1name. *orea%h- y in arr . 5 print*-Ky; O& arrUyV; O&7nK1 y1 arrUyV. : exit-. : I stap vars4stp x; Q? i; 10 name; Mi e y; 0 arrUyV; 1 y; 2 arrUyV; @
2012 IBM Corporation
Taria($es Cont4
Target varia($es
spe%ia$ varia($es ) e4g41 Xreturn1 XXparms1 XXvars For pointers to (ase types su%h as integers an& strings ) erne$D$ong-a&&ress.1 erne$Dstring-a&&ress. *or sa*e a%%ess to varia($e va$ues4
Taria($es Cont4
I stap ,e "pro(e mo&u$e-KC&as&CK.4*un%tion-K&as&Da$$o%D2ueueK. 5print*-KOs7nK1 XXparms.9 exit-.9 :" ($o% S0x@eee@P00
6X8 su**ix to pretty print the &ata stru%ture4 I stap ,e "pro(e mo&u$e-KC&as&CK.4*un%tion-K&as&Da$$o%D2ueueK. 5print*-KOs7nK1 XXparmsX.9 exit-.9 :" ($o% S54g&pS0x01 4re2uestD2ueueS0x01 4441 4(aseS0x@ee%@?001 4%%wD2ueueS5444:1 42ueueD$o% S5444:1 444: 6XX8 su**ix wi$$ print the va$ues within the neste& &ata stru%tures I stap ,e "pro(e mo&u$e-KC&as&CK.4*un%tion-K&as&Da$$o%D2ueueK. 5print*-KOs7nK1 XXparmsXX.9 exit-.9 :" ($o% S54g&pS0x01 4re2uestD2ueueS0x0 14441 4%%wD2ueueS54nextS0x@*1@PP?01 4prevS0x@*1@PP?0:1 42ueueD$o% S54rawD$o% S54ownerD%puS0::1444
2012 IBM Corporation
Taria($es Cont4
I stap ,L " erne$4*un%tion-KsysDsiga$tsta% K." erne$4*un%tion-KSySDsiga$tsta% Mar%h's@N0' erne$'signa$4%;10QK. Xuss;$ong int Xuoss;$ong int uss -%onst sta% Dt C. points to a signa$sta% stru%ture I %at siga$tsta% 4stp pro(e erne$4*un%tion-KsysDsiga$tsta% K. 5 print*- KOs7nK1 XXparmsX .9: I stap siga$tsta% 4stp ussS2102012Q?0 uossS0 ussS210202N02? uossS0 ussS21??01012P uossS0 ussS?@0201NQPP uossS0
S%ript an& Target varia($es g$o(a$ openFai$s1 hugeDrea&s pro(e erne$4*un%tion-KsysDopenK.4return 5 i* -Xreturn G 0. openFai$sWW9 : pro(e erne$4*un%tion-KsysDrea&K. 5 i* -X%ount H ?C102?. hugeDrea&sWW9 :
S%ript varia($es; openFai$s1 hugeDrea&s Target varia($e; X%ount ) sysDrea&-."s @r& arg Spe%ia$ %ontext varia($e; Xreturn
2012 IBM Corporation
Con&itiona$'Loop statements
Lroup %ompoun& statements with 5 : Bran%hing
i* -%on&ition. statement1 Ue$se statement2V Looping;
whi$e -%on&ition. statement *or -initia$9 %on&ition9 iteration. statement *orea%h -UTE#11 TE#2V in E##EY U$imit AUMV. statement
return TELU0
:
;string ;$ong4
0xamp$e; *un%tion
I %at *un%4stp *un%tion isDopenD%reating;$ong -*$ag;$ong.5 C#0ETDFLEL S ? '' 0x? S 00000100( i* -*$ag Z C#0ETDFLEL. return 1 e$se return 0 : pro(e erne$4*un%tion-KsysDopenK.5 %reating S isDopenD%reating-Xmo&e. i* -%reating. print*-KCreating *i$e Os7nK1 userDstring-X*i$ename.. e$se print*-K!pening *i$e Os7nK1 userDstring-X*i$ename.. : I stap *un%4stp !pening *i$e pu($i%'pi% up !pening *i$e mai$&rop !pening *i$e '$i(Q?'$i(wrap4so40 Creating *i$e 'et%'se$inux'%on*ig Creating *i$e 'pro%'mounts 444
provi&e easy to use a$iases o* %ommon pro(epoints1 provi&e va$ues o* interest *rom those pro(epoints1 &e*ine those he$per *un%tions not runna($e -pro(e a$iases1 not pro(es. insta$$e& in 'usr'share'systemtap'tapset'
Tapset examp$es
sys%a$$4C
/ro(es ea%h system %a$$1 provi&es name an& argstr Use& to pro(e memory,re$ate& events /ro(es so% et,re$ate& events
vm4C
so% et4C
pro(e sys%a$$4C 5 print*-KOs-Os.7nK1 name1 argstr. : pro(e sys%a$$4C4return 5 print*-6Os returns Os7n81 name1 retstr. :
/ro(e in s%ript;
pro(e sys%a$$4rea& 5 r&D(ytesDre2ueste& WS %ount :
2012 IBM Corporation
Tapsets
tapset;;ios%he& , systemtap I! s%he&u$er pro(e points tapset;;ir2 , Systemtap pro(es *or I#\1 wor 2ueue1 et% tapset;; pro%ess , systemtap erne$ pro%ess pro(e points tapset;;net&ev , systemtap networ &evi%e pro(e points tapset;;n*s , systemtap AFS %$ient si&e pro(e points tapset;;n*s& , systemtap AFS server si&e pro(e points tapset;;page*au$t , systemtap page*au$t pro(e points tapset;;per* , systemtap per* pro(e points tapset;;rp% , systemtap Sun#/C pro(e points tapset;;s%si , systemtap s%si pro(e points tapset;;signa$ , systemtap signa$ pro(e points tapset;;snmp , Systemtap simp$e networ management proto%o$ pro(e points tapset;;t%p , systemtap t%p pro(e points tapset;;u&p , systemtap u&p pro(e points
0m(e&&e& C %o&e
0m(e&&e& C is %opie& un%hange& *rom your s%ript to the mo&u$e 4% *i$e4 0m(e&&e& C is a$$owe& on$y in tapsets or in s%ripts %ompi$e& with stap
,g -guru mo&e.4 0m(e&&e& C %o&e is usua$$y use& insi&e a *un%tion that starts with O 5 an& en&s with O:
#e*eren%es
SystemTap &o%umentation
) Tutoria$ ) Beginner"s Lui&e ) Language #e*eren%e ) Tapset #e*eren%e http;''sour%eware4org'systemtap'&o%umentation4htm$
#e&(oo ; SystemTap; Instrumenting the Linux +erne$ *or Ena$yzing
/er*orman%e an& Fun%tiona$ /ro($ems
http;''www4re&(oo s4i(m4%om're&papers'p&*s're&p??QN4p&*
#e*eren%es Cont4
http;''pu($i(4(ou$&er4i(m4%om'in*o%enter'$nxin*o'v@r0m0'topi%'$iaai'$iaaiSys temTap4htm
http;''&o%s4re&hat4%om'&o%s'en,US'#e&D3atD0nterpriseDLinux'in&ex4htm$
#e*eren%es
There are man pages;
stap
systemtap program usage1 $anguage summary stappaths your systemtap insta$$ation paths stap*un%s *un%tions provi&e& (y tapsets stappro(es pro(es ' pro(e a$iases provi&e& (y tapsets stapex some examp$e s%ripts