On Tue, 2008-03-25 at 14:03 +0000, Jon Haslam wrote:
> Hi Roman,
> 
> > Here's the problem I'm facing: I need to sample a particular
> > attribute of all the LWPs in a given process. Now, sampling
> > itself is no problem -- I can use profile/tick provider and
> > all is good. The problem is: I can't seem to think of a 
> > DTrace-friendly way to iterate over all the LWPs and report
> > the value of the attribute I'm interested in. 
> >
> > Any suggestions?
> 
> To be honest, I'm not completely sure what you're after

Well, I guess that makes you a mind reader, 'cause the rest
of your reply seems to be exactly what I was looking for. ;-)
Now, as far as implementation goes, I still have a few
questions:

>         self->pidp = `pidhash[$1 & (`pid_hashsz - 1)];

what is backtick doing here in front of pidhash? Is it a way
of accessing an arbitrary kernel variable?

> BEGIN
> /self->pidp->pid_id == $1/

Wow! Could you, please, elaborate on why exactly
the predicate is needed here? My reading of the first
BEGIN statement seems to suggest that the following
will always be true:
  self->pidp->pid_id == $1 

Or is it just a safety measure that prevents us from 
getting garbage from pidhash?

> {
>         this->slot = (*(uint32_t *)self->pidp) >> 8;
>         procp = `procdir[this->slot].pe_proc;
>         procname = stringof(procp->p_user.u_comm);
>         t = procp->p_tlist;

Wow! That's some powerful kernel magic, if you ask me. ;-)

> tick-50ms
> /pidp && t != NULL/
> {
>         printf("%s lwps %d/thr (%d): %d syscalls\n", procname, 
> procp->p_lwpcnt,
>             t->t_tid, t->t_lwp->lwp_ru.sysc);
>         t = t->t_forw;

Now, here comes the crucial question: AFAIK, p_tlist points to
a circular list of kernel threads. We are traversing this list
using t = t->t_forw. Now, what happens if 't' points to 
a member of the list that used to be valid but has been
deallocated in between the two ticks of tick-50ms?

Thanks,
Roman.

_______________________________________________
dtrace-discuss mailing list
[email protected]

Reply via email to