- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我有一个简单的 ST 脚本,它计算每个文件的进程 io 大小:
global fds, counts
probe syscall.open.return {
if ( ( pid() == target() ) & ( $return != -1 ) ) {
printf("%s opened as %d\n", user_string($filename), $return)
fds[$return] = user_string($filename)
}
}
probe syscall.read.return, syscall.write.return {
if ( (pid() == target()) & ($return > 0) ) {
counts[fds[$fd]] += $return
}
}
probe end {
foreach (fname in counts+) {
count = counts[fname]
if ( count > 1024) {
count = count / 1024
bs = "Kb"
} else {
bs = "B"
}
printf("%s: %d %s\n", fname, count, bs)
}
}
当我运行 stap test.stp -c 'cat test.stp'
我得到:
global fds, counts
probe syscall.open.return {
if ( ( pid() == target() ) & ( $return != -1 ) ) {
printf("%s opened as %d\n", user_string($filename), $return)
fds[$return] = user_string($filename)
}
}
probe syscall.read.return, syscall.write.return {
if ( (pid() == target()) & ($return > 0) ) {
counts[fds[$fd]] += $return
}
}
probe end {
foreach (fname in counts+) {
count = counts[fname]
if ( count > 1024) {
count = count / 1024
bs = "Kb"
} else {
bs = "B"
}
printf("%s: %d %s\n", fname, count, bs)
}
}
/etc/ld.so.cache opened as 3
/lib64/libc.so.6 opened as 3
/usr/lib/locale/locale-archive opened as 3
test.stp opened as 3
test.stp: 541 B
: 541 B
/lib64/libc.so.6: 832 B
这几乎是正确的。但是当我执行 stap test.stp -c 'cat test.stp >/dev/null'
我得到一些奇怪的东西:
/etc/ld.so.cache opened as 3
/lib64/libtinfo.so.5 opened as 3
/lib64/libdl.so.2 opened as 3
/lib64/libc.so.6 opened as 3
/dev/tty opened as 3
/usr/lib/locale/locale-archive opened as 3
/proc/meminfo opened as 3
/usr/lib64/gconv/gconv-modules.cache opened as 3
/lib64/libtinfo.so.5: 832 B
/lib64/libdl.so.2: 832 B
/lib64/libc.so.6: 832 B
/proc/meminfo: 1024 B
为什么在第二种情况下我看不到 test.stp opened as 3
?
我用 strace 做了一些测试:
1) strace -e open -o trace cat test.stp
:
open("/home/al/lib/tls/x86_64/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/home/al/lib/tls/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/home/al/lib/x86_64/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/home/al/lib/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
open("/lib64/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
open("/usr/lib/locale/locale-archive", O_RDONLY|O_CLOEXEC) = 3
open("test.stp", O_RDONLY) = 3
+++ exited with 0 +++
2) strace -e open -o trace cat test.stp >/dev/null
:
open("/home/al/lib/tls/x86_64/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/home/al/lib/tls/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/home/al/lib/x86_64/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/home/al/lib/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
open("/lib64/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
open("/usr/lib/locale/locale-archive", O_RDONLY|O_CLOEXEC) = 3
open("test.stp", O_RDONLY) = 3
+++ exited with 0 +++
没有区别。
最佳答案
那是因为cat test.stp > /dev/null
需要运行 shell (bash)(注意使用 >
进行输出重定向),因此 bash 进程(不是 cat)的 PID 将被识别为 target()
.
您可以检查是否 pid()
是target()
的 child . DTrace 中有一个名为 progenyof()
的操作确定当前任务是否是具有预定义 pid()
的任务的子任务. SystemTap 中没有类似物,但您可以像这样轻松地重现它:
function progenyof(pid:long) {
parent = task_parent(task_current());
task = pid2task(pid);
while(parent && task_pid(parent) > 0) {
if(task == parent)
return 1;
parent = task_parent(parent);
}
}
关于linux - SystemTap 脚本异常行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27755952/
好吧,我正尝试在 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 读取性能事件和计数器,包括与缓存相关的事件和计
我的目标是分析内核模块中每个函数的执行时间。使用我在网上看到的示例脚本,我想出了以下脚本来满足我的需要。但偶尔我会得到计算延迟的负值。虽然,它们很少发生,但我想这表明我的脚本有问题。谁能帮我解决这个问
我是一名优秀的程序员,十分优秀!