SystemTap - 安装
按照SystemTap Beginners Guide的Installation and Setup部分安装了SystemTap,没想到竟然还有点曲折,在这里纪录一下。
环境
- Linux发行版本:CentOS Linux release 7.4.1708 (Core)
- 内核版本:3.10.0-693.2.2.el7.x86_64
- uname -a: Linux hostname 3.10.0-693.2.2.el7.x86_64 #1 SMP Tue Sep 12 22:26:13 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
安装
安装SystemTap
先安装如下两个RPM包:
- systemtap
- systemtap-runtime
以root运行如下命令:
# yum install systemtap systemtap-runtime
在运行SystemTap之间,还需要装必要的内核信息包。在现代系统上,可以运行如下stap-prep来安装这些包,如下:
# stap-prep
Need to install the following packages:
kernel-devel-3.10.-693.2..el7.x86_64
kernel-debuginfo-3.10.-693.2..el7.x86_64
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
No package kernel-devel-3.10.-693.2..el7.x86_64 available.
No package kernel-debuginfo-3.10.-693.2..el7.x86_64 available.
Error: Nothing to do
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Could not find debuginfo for main pkg: kernel-3.10.-693.2..el7.x86_64
No debuginfo packages available to install
package kernel-devel-3.10.-693.2..el7.x86_64 is not installed
package kernel-debuginfo-3.10.-693.2..el7.x86_64 is not installed
problem installing rpm(s) kernel-devel-3.10.-693.2..el7.x86_64 kernel-debuginfo-3.10.-693.2..el7.x86_64
运行stap-prep的时候,它探测出还要安装kernel-devel-3.10.0-693.2.2.el7.x86_64包和kernel-debuginfo-3.10.0-693.2.2.el7.x86_64包 (实际上还有kernel-debuginfo-common包),但是自动安装失败。我们可以按照如下方法手动安装。
手动安装必要的内核信息包
SystemTap需要安装内核内核符号文件来probe内核。必要的内核信息包含在如下三个包中:
- kernel-debuginfo
- kernel-debuginfo-common
- kernel-devel
一定要安装与当前内核版本一致的包。当前环境的内核版本是3.10.0-693.2.2.el7.x86_64,所以需要安装的包为:
- kernel-debuginfo-3.10.0-693.2.2.el7.x86_64
- kernel-debuginfo-common-3.10.0-693.2.2.el7.x86_64
- kernel-devel-3.10.0-693.2.2.el7.x86_64
注意:其实在上一步运行stap-prep时,已经把需要的包的名称及其内核精准地打印在屏幕上了。
接下来安装这三个包,注意不要直接yum install kernel-debuginfo kernel-debuginfo-common kernel-devel, 即使能找到相应的包,也是安装的最新版本,不会自动匹配当前版本。所以我们下载RPM包,再用rpm命令依次安装。
对于CentOS来说,内核符号文件一版在http://debuginfo.centos.org上有各个版本非常完整的包,但是一般从境内下载都比较慢,特别是kernel-debuginfo,比较大下载可能非常慢。所以在debuginfo.centos.org上下了kernel-debuginfo-common包,另外两个包在Google上搜了一把,分别找了两个镜像。下了之后才发现这个地方有坑,这个坑在后面展开讲。
wget https://ftp.sjtu.edu.cn/scientific/7/archive/debuginfo/kernel-debuginfo-3.10.0-693.2.2.el7.x86_64.rpm
wget http://debuginfo.centos.org/7/x86_64/kernel-debuginfo-common-x86_64-3.10.0-693.2.2.el7.x86_64.rpm
wget ftp://mirror.switch.ch/pool/4/mirror/scientificlinux/7.0/x86_64/updates/security/kernel-devel-3.10.0-693.2.2.el7.x86_64.rpm
下载之后,直接用rpm命令安装就好:
# rpm -ivh kernel-debuginfo-common-x86_64-3.10.-693.2..el7.x86_64.rpm
# rpm -ivh kernel-debuginfo-3.10.-693.2..el7.x86_64.rpm
# rpm -ivh kernel-devel-3.10.-693.2..el7.x86_64.rpm
至此安装步骤完毕,下面来测试SystemTap能不能正常运行。
运行SystemTap
为了测试stap是否能正常运行,用如下简单命令打印:
# stap -e 'probe begin{printf("Hello, World"); exit();}'
运行失败...结果如下:
# stap -e 'probe begin{printf("Hello, World"); exit();}'
ERROR: module version mismatch (# SMP Tue Sep :: CDT vs # SMP Tue Sep :: UTC ), release 3.10.-693.2..el7.x86_64
WARNING: /usr/bin/staprun exited with status:
Pass : run failed. [man error::pass5]
错误信息是:"ERROR: module version mismatch (#1 SMP Tue Sep 1210:10:26 CDT 2017 vs #1 SMP Tue Sep 1222:26:13 UTC 2017)"。
解决"ERROR: module version mismatch"问题
stap运行的时候加上-v参数,打印更多信息看看还有没有更多线索:
# stap -e 'probe begin{printf("Hello, World"); exit();}' -v
Pass : parsed user script and library scripts using 228224virt/41280res/3348shr/38020data kb, in 330usr/20sys/346real ms.
Pass : analyzed script: probe, function, embeds, globals using 229148virt/42332res/3536shr/38944data kb, in 0usr/0sys/6real ms.
Pass : using cached /root/.systemtap/cache/0b/stap_0bc9e27aef7a1de50ea41889a27fc524_1010.c
Pass : using cached /root/.systemtap/cache/0b/stap_0bc9e27aef7a1de50ea41889a27fc524_1010.ko
Pass : starting run.
ERROR: module version mismatch (# SMP Tue Sep :: CDT vs # SMP Tue Sep :: UTC ), release 3.10.-693.2..el7.x86_64
WARNING: /usr/bin/staprun exited with status:
Pass : run completed in 0usr/10sys/38real ms.
Pass : run failed. [man error::pass5]
查看c文件,vi /root/.systemtap/cache/0b/stap_0bc9e27aef7a1de50ea41889a27fc524_1010.c,搜错误信息"module version mismatch",能搜到报错发生在下面的第13行,至于UTS_RELEASE和UTS_VERSION是在哪里设置的,直接Google一把。
#ifndef STP_NO_VERREL_CHECK
const char* release = UTS_RELEASE;
#ifdef STAPCONF_GENERATED_COMPILE
const char* version = UTS_VERSION;
#endif
might_sleep();
if (strcmp (release, "3.10.0-693.2.2.el7.x86_64")) {
_stp_error ("module release mismatch (%s vs %s)", release, "3.10.0-693.2.2.el7.x86_64");
rc = -EINVAL;
}
#ifdef STAPCONF_GENERATED_COMPILE
if (strcmp (utsname()->version, version)) {
_stp_error ("module version mismatch (%s vs %s), release %s", version, utsname()->version, release);
rc = -EINVAL;
}
#endif
#endif
有两篇文章里面提到了同样的坑,文章连接在底部的参考中。在kernel-devel包的所以文件中搜以下变量UTS_VERSION,
# rpm -ql kernel-devel | xargs grep UTS_VERSION
/usr/src/kernels/3.10.-693.2..el7.x86_64/include/generated/compile.h:#define UTS_VERSION "#1 SMP Tue Sep 12 10:10:26 CDT 2017"
可以看到在compile.h中有#define UTS_VERSION "#1 SMP Tue Sep 12 10:10:26 CDT 2017". 这个是不是很熟悉... 对比下上面运行stap的报错信息, module mismatch的时间就是这个。文件compile.h是自动生成的,可能和当时编译时的时间相关。但是stap要求这个也和当前系统uname -a里面的时间完全一直,如果下个CentOS原生的kernel-devel应该就没这个问题。
解决问题的另一个简单方法就是直接修改这个compile.h文件,原来的文件如下:
# cat /usr/src/kernels/3.10.-693.2..el7.x86_64/include/generated/compile.h
/* This file is auto generated, version 1 */
/* SMP */
#define UTS_MACHINE "x86_64"
#define UTS_VERSION "#1 SMP Tue Sep 12 10:10:26 CDT 2017"
#define LINUX_COMPILE_BY "mockbuild"
#define LINUX_COMPILE_HOST "sl7-uefisign.fnal.gov"
#define LINUX_COMPILER "gcc version 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC) "
修改define UTS_VERSION那一行,如下:
#define UTS_VERSION "#1 SMP Tue Sep 12 10:10:26 CDT 2017" -> #define UTS_VERSION "#1 SMP Tue Sep 12 22:26:13 UTC 2017"
再次运行stap:
# stap -e 'probe begin{printf("Hello, World"); exit();}' -v
Pass : parsed user script and library scripts using 228220virt/41276res/3348shr/38016data kb, in 350usr/10sys/355real ms.
Pass : analyzed script: probe, function, embeds, globals using 229144virt/42328res/3536shr/38940data kb, in 0usr/0sys/6real ms.
Pass 3: using cached /root/.systemtap/cache/0b/stap_0bc9e27aef7a1de50ea41889a27fc524_1010.c
Pass 4: using cached /root/.systemtap/cache/0b/stap_0bc9e27aef7a1de50ea41889a27fc524_1010.ko
Pass : starting run.
ERROR: module version mismatch (# SMP Tue Sep :: CDT vs # SMP Tue Sep :: UTC ), release 3.10.-693.2..el7.x86_64
WARNING: /usr/bin/staprun exited with status:
Pass : run completed in 0usr/10sys/38real ms.
Pass : run failed. [man error::pass5]
因为中间生成的C文件和ko模块都是用的cache (蓝色标注的部分),我们把上面的cache文件删除,再重新运行,这次可以成功了。
# stap -e 'probe begin{printf("Hello, World"); exit();}'
Hello, World
参考
https://sourceware.org/systemtap/SystemTap_Beginners_Guide/using-systemtap.html#using-setup
ERROR: module version mismatch
https://groups.google.com/forum/#!topic/openresty/nlEc3qlDyOc
SystemTap - 安装的更多相关文章
- RHEL6 Systemtap 安装笔记
以 RHEL6u3 为例 1 Systemtap 安装 yum install systemtap 跟systemtap有关的有6,7个,全装上,别偷懒 就用yum安装,别傻傻的去下rpm包,吃力不 ...
- systemtap安装
一.systemtap介绍 SystemTap是一个强大的调试工具,是监控和跟踪运行中的Linux 内核的操作的动态方法,确切的说应该是一门调试语言,因为它有自己的语法,也有解析.编译.运行等过程(准 ...
- systemtap 安装试用
1. 安装 yum install -y systemtap systemtap-runtime 2. 环境准备 a. 自动安装依赖 stap-prep b. 手动安装依赖 kernel-deb ...
- systemtap 安装 总结
http://blog.soul11201.com/notes/2017/02/22/systemstap-install.html
- 【SystemTap】 Linux下安装使用SystemTap源码安装SystemTap
转自 http://blog.csdn.net/zklth/article/details/6248558 文章 http://blog.csdn.net/zklth/archive/2010/09/ ...
- CentOS 5.4 final下Systemtap的安装
CentOS 5.4 final下Systemtap的安装 时间:2015-02-11来源:linux网站 作者:zklth 一.Systemtap运行环境需求 (1)linux kernel ...
- 转 -Linux 自检和 SystemTap (强大的内核调试工具)---包含下载地址
下载: http://www.oschina.net/p/systemtap/ https://sourceware.org/systemtap/ftp/releases/ Linux 自检和 S ...
- Linux 下的一个全新的性能测量和调式诊断工具 Systemtap, 第 3 部分: Systemtap
Systemtap的原理,Systemtap与DTrace比较,以及安装要求和安装步骤本系列文章详细地介绍了一个Linux下的全新的调式.诊断和性能测量工具Systemtap和它所依赖的基础kprob ...
- Linux systemtap定位系统IO资源使用情况(ok)
一.systemtap介绍 SystemTap是一个强大的调试工具,是监控和跟踪运行中的Linux 内核的操作的动态方法,确切的说应该是一门调试语言,因为它有自己的语法,也有解析.编译.运行等过程(准 ...
随机推荐
- 列式数据库~clickhouse 数据同步使用
一 简介:进一步了解clickhouse二 数据操 1 单机建表 create TABLE aaa ( id UInt32, uid UInt32, amount Float64, ...
- android view绘制流程 面试
一.view树的绘制流程 measure--->layout--->draw measure 1.ViewGroup.LayoutParams 指定部件的长宽 2.MeasureSpec ...
- Informatic学习总结_day02_增量抽取
SELECT EMP.EMPNO, EMP.ENAME, EMP.JOB, EMP.MGR, EMP.HIREDATE, EMP.SAL, EMP.COMM, EMP.DEPTNO FROM EMP ...
- exp自动备份在bat中不执行
在命令行前加cd c:\users\...... 先定位进入可以exp的目录下,再执行exp
- expdp和impdp快速导出导入,不用创建虚拟目录
expdp 和impdp不用创建虚拟目录:在cmd直接 expdp 用户名/密码 回车 就导出了,(如果提示输入用户名和密码就输入).再将导出的文件放在oracle默认的dpdump文件夹里面,然 ...
- EntityFramework codefirst Enable-Migrations No context type was found in the assembly “MyApp.Web” error
Enable-Migrations -Force -ContextTypeName "MyApp.Repository.DataContext" -ProjectName &quo ...
- SQL中的 if 结构和循环(while)结构
- 前端工程化-webpack(打包JS)(二)
一.第一种打包方式 webpack entry<entry> output 假设目录结构如下: index.html是入口文件 打包app.js为bundle.js如下 app.js 当使 ...
- Linux 快速删除已输入的命令
从输入模式到命令模式: 按”:“到最后一行,再按ctrl+z 就好了 history 显示命令历史列表 ↑(Ctrl+p) 显示上一条命令 ↓(Ctrl+n) 显示下一条命令 !num 执行命令历史列 ...
- P2163 【[SHOI2007]园丁的烦恼】
其实是不用把一个询问拆成四个的 把询问转化为数学语言: 对于每个查询,询问满足$a<=x<=b$且$c<=y<=d$的点$x,y$的个数 ~~自然~~想到偏序问题,看到有两个式 ...