如何在 DTrace 中打印关联数组?

问题描述 投票:0回答:3

这个问题几乎概括了一切。 “dtrace '打印关联数组'” 恰好有一个谷歌搜索结果,类似的搜索同样毫无用处。

编辑:

如果我使用聚合,我不知道我仍然能够删除条目。我的申请要求我能够执行以下操作:

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...

太糟糕了。我真的很想有更好的东西。

arrays printing associative dtrace
3个回答
1
投票

这是 Google 找到的链接吗?因为这个建议看起来很合理:

我认为你正在寻找的效果应该通过使用来实现 聚合而不是数组。所以你实际上会做类似的事情:

@requests[remote_ip,request] = count();
  
...然后:

profile:::tick-10sec { /* print all of the requests */ printa(@requests); /* Nuke the requests aggregation */ trunc(@requests); }


1
投票
sum(1)

sum(-1)
而不是
count()
    


0
投票

打印操作根据 DTrace 了解的类型信息格式化输出。输出数据根据类型进行格式化。以下规则涵盖输出格式:

打印数组中的每个条目。

https://illumos.org/books/dtrace/chp-fmt.html

© www.soinside.com 2019 - 2024. All rights reserved.