Thank you for your reply, however I had
realized I could do something like that, but it a
stanza per iteration of the loop and if the loop
can be large (in the case I was looking at well over
4000 entries) the number of stanzas is prohibitive.
I'm looking for a way to actually follow the chain
all the way to the end without a hard limit
and without a huge dtrace script.
Regards,
Lida Horn
requires On 8/19/2011 2:46 PM, Jonathan Adams wrote:
On Fri, Aug 19, 2011 at 01:34:36PM -0700, Lida Horn 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.
For example:
struct list {
struct list *next;
void *data;
};
struct list *list_root;
Assuming I had "list_root" available, but I wanted to know how long
the linked list is, how can I do this in a dtrace probe?
If I had looping constructs, it would be obvious:
int
count_list(struct list *list)
{
int i;
for (i = 0; list != NULL; list = list->next)
++i;
return i;
}
In the dtrace scripting language there are no loop constructs, but is
there a way to add a new provider than can loop?
Generally, you can do this using something like:
my:probe:matching:func
{
this->list = /* some way to get initial list */;
this->length = 0;
}
my:probe:matching:func / this->list != NULL / {
this->list = this->list->next; this->length++;
}
my:probe:matching:func / this->list != NULL / {
this->list = this->list->next; this->length++;
}
my:probe:matching:func / this->list != NULL / {
this->list = this->list->next; this->length++;
}
my:probe:matching:func / this->list != NULL / {
this->list = this->list->next; this->length++;
}
/* repeat N times, where N is the max list length */
my:probe:matching:func / this->list != NULL / {
/* list was longer than our maximum length */
@overflow = count();
}
my:probe:matching:func / this->list == NULL / {
/* use this->count as the length of the list */
}
(Enablings for a probe are guaranteed to execute in program order, and this->
variables are valid between enablings of the same probe.)
Cheers,
- jonathan
_______________________________________________
dtrace-discuss mailing list
dtrace-discuss@opensolaris.org