(7)安装Systemtap
(i)CentOS5.4默认安装了systemtap-0.9.7-5.e15
#rpm -q systemtap
systemtap-0.9.7-5.e15
最好将Centos5.4发行光盘里的Systemtap*包都装上;
Centos5.4默认安装的有如下2个:
systemtap-0.9.7-5.e15.i386
测试系统
systemtap-runtime-0.9.7-5.e15.i386
系统运行时测试设备
还未安装的有:
在图形界面的“应用程序”—>“添加/删除软件”—>“搜索”—>输入软件包名systemtap能够查询软件包的相关信息。
(ii)下载systemtap源码进行安装
从SystemTap的FTP站点下载最新的源码
ftp://sources.redhat.com/pub/SystemTap/snapshots/SystemTap-20100925.tar.bz2
或者
ftp://sources.redhat.com/pub/systemtap/releases/
或者也可以下载 systemtap 的 rpm 包进行安装: 在 上搜索systemtap.
systemtap官网在
然后安装如下:
tar -jxvf SystemTap-20100925.tar.bz2
cd src
./configure
make
make install
我在Cent OS 5.4下未安装 kernel-debuginfo和kernel-debuginfo-common,使用系统默认安装的SystemTap也能够正常工作,但建议安装上 debuginfo 包.
(8)运行简单的Systemtap测试程序;
测试脚本systemtap.stp监控Java进程的系统调用:
--------------------------------------------------------------------
global syscalllist
global mpname="java" /* attention : java process'name is lower-case "java" */
global debug=0 /*print middle info*/
global all=0
probe begin {
printf("%s process monitoring started ...\n",mpname)
}
probe syscall.read
{
if(all) printf("current process : %s \n",execname());
/* execname() can get the current process's name */
if (execname() ==mpname) {
/* variable name is syscall's name, it is defined in kernel function */
namex=name
if(debug) printf("%s\n",namex)
/* pid() can get the current process's PID */
pidx=pid()
if(debug) printf("%d\n",pidx)
syscalllist[pidx,namex]++
}
}
probe syscall.write
{
pname=execname()
syscallname=name
count(pname,syscallname)
}
probe kernel.function("sys_read"){
pname=execname()
objname="kf_sys_read"
count(pname,objname)
}
probe kernel.function("sys_write"){
pname=execname()
objname="kf_sys_write"
count(pname,objname)
}
//
//Remarks: Count process's some obj, such syscall,kernel.function
//
//Parameters:
//// pname : process'name
//// objname : syscall name
//
//Return values :
//// null
//
function count(pname,objname){
if (pname==mpname) {
if(debug) printf("%s ",objname)
/* current process' id */
pidx=pid()
if(debug) printf("%d\n",pidx)
syscalllist[pidx,objname]++
}
}
/*
probe timer.ms(5000) {
}
*/
function print_info(){
foreach ( [pidx,namex] in syscalllist ) {
printf("%d %s = %d\n", pidx,namex, syscalllist[pidx,namex] )
}
}
probe end {
print_info()
printf("java process monitoring finished\n")
}
---------------------------------------------------------------------