- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我想用 SystemTap 分析内核模块的缓存行为(#cache 引用、#cache 未命中等)。有一个在线示例脚本,展示了如何使用 SystemTap 读取性能事件和计数器,包括与缓存相关的事件和计数器: https://sourceware.org/systemtap/examples/profiling/perf.stp
此示例脚本默认适用于进程:
probe perf.hw.cache_references.process("/usr/bin/find").counter("find_insns") {}
我用 module
替换了 process
关键字,用我的内核模块的名称替换了可执行文件的路径:
probe perf.hw.cache_references.module(MODULE_NAME).counter("find_insns") {}
我很确定我的模块有调试信息,但是运行我得到的脚本:
semantic error: while resolving probe point: identifier 'perf' at perf.stp:14:7 source: probe perf.hw.instructions.module(MODULE_NAME).counter("find_insns") {}
任何想法可能是错误的?
编辑:
好吧,我意识到性能计数器只能绑定(bind)到进程而不是模块(此处解释:https://sourceware.org/systemtap/man/stapprobes.3stap.html)。因此,我将其改回:
probe perf.hw.cache_references.process(PATH_TO_BINARY).counter("find_insns") {}
现在,如示例脚本所示,我有:
probe module(MODULE_NAME).function(FUNC_NAME) {
#save counter values on entrance
...
}
但现在运行它,我得到:
semantic error: perf counter 'find_insns' not defined semantic error: while resolving probe point: identifier 'module' at perf.stp:26:7 source: probe module(MODULE_NAME).function(FUNC_NAME)
编辑2:
所以这是我的完整脚本:
#! /usr/bin/env stap
# Usage: stap perf.stp <path-to-binary> <module-name> <function-name>
global cycles_per_insn
global branch_per_insn
global cacheref_per_insn
global insns
global cycles
global branches
global cacherefs
global insn
global cachemisses
global miss_per_insn
probe perf.hw.instructions.process(@1).counter("find_insns") {}
probe perf.hw.cpu_cycles.process(@1).counter("find_cycles") {}
probe perf.hw.branch_instructions.process(@1).counter("find_branches") {}
probe perf.hw.cache_references.process(@1).counter("find_cache_refs") {}
probe perf.hw.cache_misses.process(@1).counter("find_cache_misses") {}
probe module(@2).function(@3)
{
insn["find_insns"] = @perf("find_insns")
insns <<< (insn["find_insns"])
insn["find_cycles"] = @perf("find_cycles")
cycles <<< insn["find_cycles"]
insn["find_branches"] = @perf("find_branches")
branches <<< insn["find_branches"]
insn["find_cache_refs"] = @perf("find_cache_refs")
cacherefs <<< insn["find_cache_refs"]
insn["find_cache_misses"] = @perf("find_cache_misses")
cachemisses <<< insn["find_cache_misses"]
}
probe module(@2).function(@3).return
{
dividend = (@perf("find_cycles") - insn["find_cycles"])
divisor = (@perf("find_insns") - insn["find_insns"])
q = dividend / divisor
if (q > 0)
cycles_per_insn <<< q
dividend = (@perf("find_branches") - insn["find_branches"])
q = dividend / divisor
if (q > 0)
branch_per_insn <<< q
dividend = (@perf("find_cycles") - insn["find_cycles"])
q = dividend / divisor
if (q > 0)
cacheref_per_insn <<< q
dividend = (@perf("find_cache_misses") - insn["find_cache_misses"])
q = dividend / divisor
if (q > 0)
miss_per_insn <<< q
}
probe end
{
if (@count(cycles_per_insn)) {
printf ("Cycles per Insn\n\n")
print (@hist_log(cycles_per_insn))
}
if (@count(branch_per_insn)) {
printf ("\nBranches per Insn\n\n")
print (@hist_log(branch_per_insn))
}
if (@count(cacheref_per_insn)) {
printf ("Cache Refs per Insn\n\n")
print (@hist_log(cacheref_per_insn))
}
if (@count(miss_per_insn)) {
printf ("Cache Misses per Insn\n\n")
print (@hist_log(miss_per_insn))
}
}
最佳答案
Systemtap 无法读取内核探测的硬件 perfctr 值,因为 linux 没有提供合适的(例如,原子的)内部 API 来安全地从所有上下文中读取这些值。 perf...process 探测器之所以起作用,是因为该上下文不是原子的:systemtap 探测器处理程序可以安全地阻塞。
我无法回答您关于您上次试验的两个(?)脚本的详细问题,因为它们不完整。
关于linux - 用于分析函数缓存行为的 SystemTap 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31549671/
好吧,我正尝试在 SDT 标记上探索我自己的应用程序。我写了一个 systemtap 脚本来探测它,但是 systemtap 在第 5 次之前没有显示任何错误,然后在第 5 次(开始运行)之后,它就什
我想访问从 glibc 的“打开”函数返回的数据,例如文件名或文件描述符 我试试 probe process("/lib*/libc.so.*").function("open") { fd =
我想访问从 glibc 的“打开”函数返回的数据,例如文件名或文件描述符 我试试 probe process("/lib*/libc.so.*").function("open") { fd =
以下 systemtap 脚本无法编译: probe process("myexe").function("myFun").return { print("hi mom\n") } 它说: seman
我正在尝试在我的 GT-i9300 上加载一个简单的 Systemtap 模块 我得到了错误 Error inserting module '/sdcard/systemtap/modules/mon
我想知道如何在 systemtap 中添加对用户空间应用程序的支持。当我尝试跟踪任何用户空间程序时,它显示 CONFIG_UTRACE 未设置。 最佳答案 也许您的内核中没有设置 utrace 工具。
我正在尝试执行一个 systemtap 脚本。但是在执行过程中我遇到了以下语义错误。 stap -v -g netfilter.stp Pass 1: parsed user script and 9
我正在尝试找出这些写入我的闪存驱动器的原因。 deathstar> while true > do > dmesg|grep sdc|grep WRITE > sleep 3 > done [1796
我正在考虑使用 SystemTap 来监控生产服务器上的文件系统事件。 如何将数据从 SystemTap 生成的内核模块传输到另一个应用程序?我只看到 printf 作为从 SystemTap 脚本输
我有一个简单的 ST 脚本,它计算每个文件的进程 io 大小: global fds, counts probe syscall.open.return { if ( ( pid()
我想使用 systemtap 来提取我的 linux 生产服务器的详细信息。我的 systemtap 脚本是 global bt; global quit = 0 probe begin {
我想编写一个 SystemTap 脚本,它可以确定探测调用中当前 PID 的实际线程数。此时该数字应与/proc/4711/status 输出中显示的数字相同。 我的第一个方法是计算 kprocess
我正在尝试使用 systemtap 调试内核中的一些代码。我需要在该函数中打印局部变量的值,但看起来 systemtap 只能看到函数参数,而看不到该函数中定义的局部变量。这是我的探测脚本。 prob
我正在尝试创建硬链接(hard link),直接从 Systemtap 嵌入式 C 代码调用 sys_link。基本上,代码如下所示: function sys_link:long(oldname,
我正在寻找一些关于 systemtap 对性能影响的真实信息。我知道静态内核探测记录在他们网站的某处(带有统计信息),但是用户空间探测呢? 我在他们的邮件列表 (http://sourceware.o
我的系统是 Ubuntu,uname -r = 4.15.0-23-generic。我已经为内核安装了调试符号。 我的问题是: I am trying to use socket(AF_PACKET,
我想使用 systemtap 从远程访问中提取我的 linux 生产服务器的详细信息。对此,我有一些疑问: linux生产服务器和linux开发服务器是否有必要使用相同的内核。如果没有,那么如何添加对
我正在尝试运行此脚本,但它显示没有 tcp 连接有什么想法吗?操作系统:centos 6.3 #! /usr/bin/env stap probe begin { printf("%6s %16s
我想用 SystemTap 分析内核模块的缓存行为(#cache 引用、#cache 未命中等)。有一个在线示例脚本,展示了如何使用 SystemTap 读取性能事件和计数器,包括与缓存相关的事件和计
我的目标是分析内核模块中每个函数的执行时间。使用我在网上看到的示例脚本,我想出了以下脚本来满足我的需要。但偶尔我会得到计算延迟的负值。虽然,它们很少发生,但我想这表明我的脚本有问题。谁能帮我解决这个问
我是一名优秀的程序员,十分优秀!