8

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.

Mateusz Piotrowski
  • 8,029
  • 10
  • 53
  • 79
Sniggerfardimungus
  • 11,583
  • 10
  • 52
  • 97

2 Answers2

1

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);
}
alanc
  • 4,102
  • 21
  • 24
Don
  • 3,654
  • 1
  • 26
  • 47
  • 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 Feb 24 '10 at 04:44
  • No problem. The issue is a bit of a tough nut to crack and I could have been clearer in my post... – Sniggerfardimungus Feb 24 '10 at 19:00
1

Use an associative array and sum(1) and sum(-1) instead of count().

Pol
  • 3,848
  • 1
  • 38
  • 55