Discussion:
Limiting dtrace depth
Darren Reed
2011-04-06 13:48:58 UTC
Permalink
If I use a simple dtrace script such as this:

fbt::somefunc:entry{self->trace=1;}
fbt::somefunc:return{self->trace=0;}
fbt:::entry{}
fbt:::return{printf("%lx", arg1);}

then it will descend to whatever depth is necessary

If I want to limit it to say 3 functions deep, how can I do that?

The quick answer I want to use is to do "self->depth++" on each entry
and then use /self->depth < 4/...
but the problem is then handling return and decrementing depth properly.

Is there something that I'm missing?

Darren
Angelo Rajadurai
2011-04-06 14:44:36 UTC
Permalink
Hey Darren,

There is a stackdepth builtin variable that holds the depth of the stack. You can use that to find how deep you are instead of using your own depth variable.

Also I'm not sure your script does what you think it does. You need predicates that use the self->trace variable. Here is my rewrite with stackdepth.

fbt::somefunc:entry
{
self->trace=1;
self->funcdepth = stackdepth;
}

fbt::somefunc:return
{
self->trace=0;
}

fbt:::return
/self->trace && (stackdepth - self->funcdepth) < 4/
{
printf("%lx",arg1);
}

I just typed this script in email and have not tested it. So please use with care :-)

BTW the stackdepth equivalent in the userland is ustackdepth.


-Angelo
Post by Darren Reed
fbt::somefunc:entry{self->trace=1;}
fbt::somefunc:return{self->trace=0;}
fbt:::entry{}
fbt:::return{printf("%lx", arg1);}
then it will descend to whatever depth is necessary
If I want to limit it to say 3 functions deep, how can I do that?
The quick answer I want to use is to do "self->depth++" on each entry and then use /self->depth < 4/...
but the problem is then handling return and decrementing depth properly.
Is there something that I'm missing?
Darren
_______________________________________________
dtrace-discuss mailing list
Darren Reed
2011-04-06 22:37:21 UTC
Permalink
Hi Angelo,

I think that this is exactly what I was looking for.

Put the lack of predicates using self->trace down to something that I
just didn't transcribe when I was writing the email.

Darren
Post by Angelo Rajadurai
Hey Darren,
There is a stackdepth builtin variable that holds the depth of the stack. You can use that to find how deep you are instead of using your own depth variable.
Also I'm not sure your script does what you think it does. You need predicates that use the self->trace variable. Here is my rewrite with stackdepth.
fbt::somefunc:entry
{
self->trace=1;
self->funcdepth = stackdepth;
}
fbt::somefunc:return
{
self->trace=0;
}
fbt:::return
/self->trace && (stackdepth - self->funcdepth) < 4/
{
printf("%lx",arg1);
}
I just typed this script in email and have not tested it. So please use with care :-)
BTW the stackdepth equivalent in the userland is ustackdepth.
-Angelo
Post by Darren Reed
fbt::somefunc:entry{self->trace=1;}
fbt::somefunc:return{self->trace=0;}
fbt:::entry{}
fbt:::return{printf("%lx", arg1);}
then it will descend to whatever depth is necessary
If I want to limit it to say 3 functions deep, how can I do that?
The quick answer I want to use is to do "self->depth++" on each entry and then use /self->depth < 4/...
but the problem is then handling return and decrementing depth properly.
Is there something that I'm missing?
Darren
_______________________________________________
dtrace-discuss mailing list
Loading...