views:

168

answers:

1

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

...
...

print_array(file_descriptors) # should print only those entries that have not been cleared.

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.

A: 

Is this the link Google found? Because the advice seems pretty sound:

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);
}
Don
Can you clear a single entry in an aggregation?
Oh - I see now what you are doing. Aggregations aren't what you want unless you are collecting a bunch of data over the run for that key. Sorry; I misunderstood.
Don
No problem. The issue is a bit of a tough nut to crack and I could have been clearer in my post...