SystemTap是一個系統(tǒng)的跟蹤探測工具。它能讓用戶來跟蹤和研究計算機系統(tǒng)在底層的實現(xiàn)。
安裝SystemTap需要為你的系統(tǒng)內(nèi)核安裝-devel,-debuginfo,-debuginfo-common包
使用下面的repo可以進行debuginfo的安裝
[debuggery]
name=CentOS-$releasever - DebugInfo
baseurl=http://debuginfo.centos.org/$releasever/$basearch/
priority=1
需要理解下面幾個名詞:
instrumentation module -- 由SystemTap腳本編譯的內(nèi)核模塊
host system -- 你編譯instrumentation 模塊的機器
target system -- 你運行instrumentation 模塊的機器
target kernel -- target system的內(nèi)核模塊
你可以在一臺機器上為其他機器編譯trap模塊,在目標(biāo)機上只要安裝systemtap-runtime,在宿主機上使用:
stap -r kernel_version script -m module_name
就能生成module_name.ko模塊
然后在目標(biāo)機上運行staprun module_name.ko就可以執(zhí)行這個trap
stap命令參數(shù):
-v
提供腳本運行的詳細輸出,可以使用多個的,比如stap -vv script.stp 輸出的信息比stap -v script.stp多
-o filename
將輸出存到文件filename中
-S size,count
限制輸出的文件大。ㄕ譩yte算)和文件數(shù)目,多個文件會有后綴
-x process ID
這個processID能從腳本中的target()獲取
-c 'command'
將target()函數(shù)做重命名
-e 'script'
使用script而不是文件作為輸入
-F
使用Flight recorder mode(飛行記錄模式),讓腳本在后臺運行。
我們也可以使用 - 來將標(biāo)準(zhǔn)輸入作為stap的輸入
echo "probe timer.s(1) {exit()}" | stap -
SystemTap的飛行模式
飛行模式使用-F參數(shù)控制的,它并不保存所有的輸出,而是只保存最近一段時間的輸出,保存的文件大小和文件數(shù)量是根據(jù)-S來控制的。
飛行模式的監(jiān)控是運行在后臺的。
安裝出現(xiàn)問題:
missing x86_64 kernel/module debuginfo
根據(jù)這篇文章解決:http://dikar.iteye.com/blog/1477619
SystemTap是如何工作的
每個SystemTap腳本都會創(chuàng)建一個sesssion,這個session按照下面的執(zhí)行順序做操作:
1 SystemTap使用tapset庫檢查這個腳本
2 SystemTap將腳本翻譯成C,然后在根據(jù)這個C程序生成一個內(nèi)核模塊。(在/tmp/xxxx/xxxx.ko)
3 SystemTap加載這個模塊,然后將代碼掛載到探針probes(events 和handlers)中
4 當(dāng)事件發(fā)生的時候,相關(guān)的代碼就執(zhí)行了
5 當(dāng)session結(jié)束的時候,探針就被銷毀
SystemTap的事件可以被歸類為兩種類型:同步和異步
同步事件包括:
syscall.system_call
vfs.file_operation
kernel.function("function")
kernel.trace("tracepoint")
module("module").function("function")
異步事件包括:
begin
end
timer events
printf