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

标签 arrays printing associative dtrace

这个问题几乎概括了一切。 “dtrace 'print an associative array'” 在 Google 上只有一次点击,类似的搜索同样毫无用处。

编辑:

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

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

真糟糕。我真的很想要更好的东西。

最佳答案

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

I think the effect you're looking for should be achieved by using an aggregation rather than an array. So you'd actually do something like:

@requests[remote_ip,request] = count();

... and then:

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

    /* Nuke the requests aggregation */
    trunc(@requests);
}

关于arrays - 如何在 DTrace 中打印关联数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2321375/

相关文章:

arrays - NodeJS - 使用 Q 对对象数组执行异步操作,但有所不同

java - 为什么会收到 java.io.EOFException 和 ArrayOutOfBounds 错误?帮助?

arrays - 如何在不使用引号的情况下保留字符串数组参数中的尾随零

javascript - 媒体打印 css 在 IE11 打印预览中不起作用

php - MySQL 查询帮助 : Getting content from associated table with position

java - 来自java中不同类的对象矩阵

wpf - 使用 FlowDocumentScrollViewer 打印所有页面

c - 在C中格式化字符,理由

arrays - 比较两个关联数组

c++ - 'std::string {aka std::basic_string<char>}' 分配中的类型不兼容