您的位置:首页 > 其它

systemtap基础安装

2014-05-12 15:40 330 查看
为部署systemtap,除了systemtap安装包,还需要-devel,-debuginfo和-debuginfo-common包;如果系统有多个内核,必须为每个版本内核各安装-devel和-debuginfo包;
安装systemtap需要systemtap和systemtap-runtime安装包yum install systemtap systemtap-runtime
安装相关内核包systemtap需要内核信息以便进行probe,而这些都由kernel-debuginfokernel-debuginfo-commonkernel-devel提供uname -r查看当前内核版本,譬如为2.6.18-53.el5机器为i686,则需要如下 kernel-debuginfo-2.6.18-53.1.13.el5.i686.rpm kernel-debuginfo-common-2.6.18-53.1.13.el5.i686.rpm kernel-devel-2.6.18-53.1.13.el5.i686.rpm最简单的方式 yum install kernelname-devel-version debuginfo-install kernelname-version
运行简单脚本测试安装是否成功stap -v -e 'probe vfs.read {printf("read performed\n"); exit()}'.会看到以下输出Pass 1: parsed user script. and 45 library script(s) in 340usr/0sys/358real ms.Pass 2: analyzed script. 1 probe(s), 1 function(s), 0 embed(s), 0 global(s) in290usr/260sys/568real ms.Pass 3: translated to C into "/tmp/stapiArgLX/stap_e5886fa50499994e6a87aacdc43cd392_399.c" in490usr/430sys/938real ms.Pass 4: compiled C into "stap_e5886fa50499994e6a87aacdc43cd392_399.ko" in3310usr/430sys/3714real ms.Pass 5: starting run.read performedPass 5: run completed in 10usr/40sys/73real ms.
运行systemtap脚本时,会创建内核模块,然后加载至内核;然而该类脚本只能在安装了systemtap包的系统上执行,而有时不能在所有机器都安装;Cross-instrumentation为此提供折中方案:即在一台机器集中生成指令模块,然后复制到各个机器上使用;步骤如下:为每个target server安装systemtap-runtime,并获取其内核版本uname -r;在host安装systemtap,并安装每个target内核对应的-devel/-debuginfo/-debuginfo-common;
host构造指令模块stap -r kernel_version script. -m module_name,复制到target执行staprun module_name.ko即可譬如创建simple.ko,其target内核为2.6.18-92.1.10.el5,在host执行如下命令生成simple.kostap -r 2.6.18-92.1.10.el5 -e 'probe vfs.read {exit()}' -m simple将simple.ko复制到target,执行staprun simple.ko即可;

stap脚本可以使用root执行,此外还提供了两个用户组stapdev:该组用户使用stap运行systemtap脚本,或者staprun运行指令模块;运行stap需要将脚本编译成内核模块并加载,此类操作需要相应root权限,因此该组用户只能赋给信任的用户;stapusr:该组用户只能调用staprun,还可以运行/lib/modules/kernel_version/systemtap目录下的模块
stap命令选项-v 将输出更具体,可以执行stap -vvv script.stp-o 将标准输出写入文件-S size,count 分别限制文件大小M和数量-x pid 使用target()捕获指定的进程ID-c 'command' 将target()指向该命令-e 'script' 将脚本作为输入传输给systemtap translator,即直接执行-e后的脚本-F 使用flight recorder mode将脚本后台运行,该脚本允许stap脚本长时间运行,有两种方式存储输出:内存和文件模式,两者都是后台进程;也可从标准输入读取并运行脚本 echo "probe timer.s(1) {exit()}" | stap -
什么是flight recorderallows you to run a SystemTap script. run for long periods and just focus on recent output.内存模式:从内核内存申请缓冲区存放运行信息;缓存默认1M,-s可调大stap -F iotime.stp将看到如下信息Disconnecting from systemtap module.To reconnect, type "staprun -A stap_5dd0073edcb1f13f7565d8c343063e68_19556"只需运行staprun -A stap_5dd0073edcb1f13f7565d8c343063e68_19556便可持续获取脚本输出信息文件模式:将信息存于文件,-S决定文件大小,-o输出文件stap -F -o /tmp/pfaults.log -S 1,2 pfaults.stp

脚本运行流程:先检查已有的tapset库(/usr/share/systemtap/tapset),然后使用library已定义的tapset替代脚本将其转化为C语言,并编译成内核模块加载该模块,激活脚本脚本中的probe
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: