DTrace: tracking user stack size in OS X? (Curthread-> t_procp-> p_stksize?)

I came across this simple DTrace script to track user stack sizes, but it does not work on OS X Mountain Lion:

dtrace -n 'sched:::on-cpu { @[execname] = max(curthread->t_procp->p_stksize);}' 

(from: http://www.solarisinternals.com/wiki/index.php/DTrace_Topics_One_Liners )

Error returned by OS X:

 dtrace: invalid probe specifier sched:::on-cpu { @[execname] = max(curthread->t_procp->p_stksize);}: in action list: t_procp is not a member of struct thread 

In fact, I find it difficult to find that the actual members of "curthread" are in OS X. Is there an equivalent way to expand the current size of the user stack for the thread? Or is "curthread" just an opaque pointer to OS X that can only be used to identify threads? Please note that I would be just as happy to do this tracing through the pid provider if this helps anyone.

Thanks!

+4
source share
1 answer

I also did not find that it is documented, but noticed that Instruments supports recording the size of the user stack. Using the dtrace export, I defined it using the ustackdepth built-in variable.

For example, this script will start recording all method calls after calling the -abortEditing method, with a depth of up to 2 calls:

 #!/usr/sbin/dtrace -s #pragma D option quiet objc$target::*abortEditing*:entry /thread == 0/ { start = ustackdepth; thread = tid; } objc$target:::entry /thread == tid && ustackdepth - start < 2/ { printf("%*s %s %s\n", ustackdepth - start + 3, "->", probemod, probefunc); } objc$target:::return /thread == tid && start == ustackdepth/ { thread = 0; } 
0
source

All Articles