Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you print an associative array in DTrace?

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.

like image 653
Sniggerfardimungus Avatar asked Feb 23 '10 20:02

Sniggerfardimungus


People also ask

What is associative array with example?

Associative arrays are used to store key value pairs. For example, to store the marks of different subject of a student in an array, a numerically indexed array would not be the best choice.

What is associative array in PHP?

Associative Array - It refers to an array with strings as an index. Rather than storing element values in a strict linear index order, this stores them in combination with key values. Multiple indices are used to access values in a multidimensional array, which contains one or more arrays.

What is associative arrays in PPL?

An associative array is an unordered collection of data elements that are indexed by an equal number of values called keys. In the case of non-associative arrays, the indices never need to be stored (because of their regularity).


1 Answers

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);
}
like image 152
Don Avatar answered Oct 26 '22 08:10

Don