On Fri, Aug 19, 2011 at 4:34 PM, Lida Horn <lida.h...@oracle.com> wrote:
> I'm looking for an example of how one could write a dtrace probe
> that could follow something like a NULL terminated linked list.
>

If this is a list with short-lived entries (e.g., one of the hash
buckets in the sleep queue), you can approximate the length of the
list at any given time.  Increment a variable on entry to the
list_insert() function and decrement it on entry to the list_delete()
function.  Don't let the value drop below 0, and eventually you'll
have a decent approximation to the length of the list.  (If the real
length of the list ever drops to 0 while you're observing, you'll end
up with an accurate measurement.)

The example below does this.  It's a script I used to look at the
average and max lengths of hash buckets in the sleep queue (the
self->bucket computation in the cv_block:entry clause is the old hash
function for the sleep queue):

fbt::cv_block:entry
{
       self->bucket = (((uintptr_t)(arg0) >> 2) +
              ((uintptr_t)(arg0) >> 9) & 511) + 1;
}

fbt::sleepq_insert:entry
/self->bucket/
{
       length[self->bucket]++;
       @r[self->bucket] = max(length[self->bucket]);
       @q[self->bucket] = avg(length[self->bucket]);
       bucket[arg1] = self->bucket;
       self->bucket = 0;
}

fbt::sleepq_unlink:entry
/ length[bucket[arg1]] > 0 /
{
       length[bucket[arg1]]--;
}

END
{
       trunc(@r,20);
       trunc(@q, 20);
        printf(“MAX:\n”);
        printa(@r);
        printf(“AVG:\n”);
        printa(@q);
}

Chad
_______________________________________________
dtrace-discuss mailing list
dtrace-discuss@opensolaris.org

Reply via email to