如何在 DTrace 中打印关联数组?
这个问题几乎概括了这一点。 “dtrace 'print an associative array'” 恰好有一个谷歌搜索结果,类似的搜索同样毫无用处。
编辑:
如果我要使用聚合,我不知道我仍然能够删除条目。我的应用程序要求我能够执行以下操作:
file_descriptors[0] = "stdin"
file_descriptors[3] = "service.log"
...
...
file_descriptors[3] = 0
...
...
# should print only those entries that have not been cleared.
print_array(file_descriptors)
我知道您可以清除整个聚合,但是单个条目怎么样?
更新:
由于我在 OS X 中执行此操作,并且我的应用程序是跟踪特定进程打开的所有文件描述符,因此我能够拥有 256 个路径名的数组,因此:
syscall::open*:entry
/execname == $1/
{
self->path = copyinstr(arg0);
}
syscall::open*:return
/execname == $1/
{
opened[arg0] = self->path;
}
syscall::close*:entry
/execname == $1/
{
opened[arg0] = 0;
}
tick-10sec
{
printf(" 0: %s\n", opened[0]);
}
The above probe repeated 255 more times...
太糟糕了。我真的很想有更好的东西。
The question pretty much sums it up. "dtrace 'print an associative array'" has exactly one google hit and the similar searches are equally useless.
EDIT:
If I were to use an aggregation, I'm not aware that I'd still be able to remove entries. My application requires that I be able to do things like:
file_descriptors[0] = "stdin"
file_descriptors[3] = "service.log"
...
...
file_descriptors[3] = 0
...
...
# should print only those entries that have not been cleared.
print_array(file_descriptors)
I know that you can clear an entire aggregation, but what about a single entry?
UPDATE:
Since I'm doing this in OS X and my application is to track all of the file descriptors that have been opened by a particular process, I was able to have an array of 256 pathnames, thusly:
syscall::open*:entry
/execname == $1/
{
self->path = copyinstr(arg0);
}
syscall::open*:return
/execname == $1/
{
opened[arg0] = self->path;
}
syscall::close*:entry
/execname == $1/
{
opened[arg0] = 0;
}
tick-10sec
{
printf(" 0: %s\n", opened[0]);
}
The above probe repeated 255 more times...
It sucks. I'd really like to have something better.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用关联数组以及
sum(1)
和sum(-1)
而不是count()
。Use an associative array and
sum(1)
andsum(-1)
instead ofcount()
.print(array) 似乎被定义为执行您想要的操作:
https://illumos.org/books/dtrace/chp-fmt.html
print(array) seems to be defined to do what you want:
https://illumos.org/books/dtrace/chp-fmt.html
此是 Google 找到的链接吗?因为这个建议看起来很合理:
Is this the link Google found? Because the advice seems pretty sound: