6
25
2014
1

systemtap安装、运行

systemtap安装

关于systemtap安装这一部分,实验室小鱼师兄给出了具体操作,这儿我借用:

一、开启内核调试信息

首先由于Systemtap运行时需要内核的调试信息支撑,默认发行版的内核在配置时,这些调试开关是关闭的,所以为了Systemtap能够正常运行,我们首先要使内核开启运行调试信息功能。主要有两种方法:

方法一:下载并安装debuginfo安装包

由于发行版的内核默认无内核调试信息,所以我们还需要一个调试内核镜像,在http://ddebs.ubuntu.com/pool/main/l/linux/ 找到你的内核版本相对应的内核调试镜像(版本号包括后面的发布次数、硬件体系等都必须一致),

假设我的内核版本2.6.32-24,i386结构,那么我需要下载

linux-image-2.6.32-24-generic-dbgsym_2.6.32-24.42_i386.ddeb下载后安装

dpkg -i linux-image-2.6.32-24-generic-dbgsym_2.6.32-24.42_i386.ddeb

 

方法二:重新编译内核

由于http://ddebs.ubuntu.com/pool/main/l/linux/下载页面中并不包含有些版本的内核(比如我们的pcmfs基于的2.6.34.14内核),这个时候我们需要重新编译内核,执行make menuconfig后,配置以下选项(不同版本内核,选项位置可能稍有不同):

 General Setup  -- ->

[*] Kernel->user space relay support (formerly relayfs)

[*] Kprobes

kernel hacking  -- ->

[*]Kernel debugging

[*]Compile the kernel with debug info                    

[*]Debug Filesystem

配置完成后,最终效果是内核的.config文件中看到下面四个选项是设置的:

CONFIG_DEBUG_INFO =y

 CONFIG_KPROBES = y

 CONFIG_DEBUG_FS = y

 CONFIG_RELAY = y

配置完之后,按照以前的编译内核的步骤编译安装即可。

(在该内核代码路径下输入gedit .config可以看到config内容。。这里顺便说一句刚刚解压没有编译的代码中是没有.config这个文件的)

 

二、安装Systemtap和相关依赖包

该步骤很简单,只要使用apt-get安装elfutils依赖包和Systemtap即可

apt-get install elfutils

apt-get install systemtap

 

检测systemtap是否安装好

示例一:打印hello Systemtap

$stap -ve 'probe begin { log("hello Systemtap!") exit() }'

如果安装正确,会得到如下类似的输出结果:

 

测试错误总结:

错误1:

今天运行.stp脚本很怪,有时候可以正确检测,有时候就报错,报错内容如下

Error inserting module '/tmp/stapvDz3zm/stap_csf***.ko':File exists

即模块已经存在,截图

原因在于,systemtap的运行机制如下:

  1. 将.stp 脚本翻译成C源代码,并且作为一个kernel的module。
  2. 将C文件编译成module(.ko)
  3. 将module加载到kernel里
  4. Module会运行,报告script脚本里面说明的事件信息。
  5. 从kernel收集这些信息并且打印到终端。
  6. 如果给stap一个CTRL-C或者是达到脚本里面说明的结束点,会unload module。脚本运行结束。

在上一次非法中断该*.stp脚本时,systemtap无法将*.ko文件移除,这导致再次插入模块出现file exists情况。通过终端输入lsmod指令我们可以看到存在stapc***.ko这个模块,解决办法如下:先移除模块,再重新运行:

rmmod stap**.ko //移除已经存在的模块

./*.stp //重新运行脚本

 

错误2:

在*.stp 运行的过程中,若stp脚本中没有加入运行的持续时间,那么需要通过 ctrl+c 来中断。

若用ctrl+x 中断,则下次运行同样的*.stp脚本时就会出现“错误1”所描述的错误。

Category: systemtap | Tags: systemtap | Read Count: 2786
Avatar_small
Alyssa 说:
2023年1月01日 01:10

SystemTap is a free and open-source instrumentation system for Linux developed by Red Hat. It allows developers and administrators to write scripts Effect Of CBD to collect data and monitor system activity. SystemTap scripts can be used to investigate performance issues, identify bottlenecks, and track down errors. SystemTap scripts are written in the SystemTap Language which is a simple, yet powerful, programming language designed specifically for system monitoring.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter

Host by is-Programmer.com | Power by Chito 1.3.3 beta | Theme: Aeros 2.0 by TheBuckmaker.com