I''m interested in monitoring the amount of stack used by a multi-threaded program. I assume ''stackdepth'' built-in would be useful...but not sure. Been through demo''s, ToolKit, and internals..but it''s just not clicking for me yet. Not sure how to measure start/end of stack size dynamically...Anyone know how to break this down? This message posted from opensolaris.org
G''Day Mike, On Wed, 15 Feb 2006, Mike Kuhnkey wrote:> I''m interested in monitoring the amount of stack used by a > multi-threaded program. I assume ''stackdepth'' built-in would be > useful...but not sure. Been through demo''s, ToolKit, and internals..but > it''s just not clicking for me yet. > > Not sure how to measure start/end of stack size dynamically...Anyone > know how to break this down?If you just want the stack size, # dtrace -n ''on-cpu { @[execname] = max(curthread->t_procp->p_stksize); }'' dtrace: description ''on-cpu '' matched 3 probes ^C svc.startd 8192 fsflush 8192 sched 8192 nscd 8192 bash 12288 svcs 12288 svc.configd 16384 gnome-vfs-daemon 16384 dtrace 16384 miniserv.pl 24576 gnome-panel 32768 gnome-terminal 32768 sshd 57344 nautilus 73728 snmpd 348160 no worries, Brendan [Sydney, Australia]
Jonathan Adams
2006-Feb-16 21:06 UTC
[dtrace-discuss] Script for Stackdepth by Thread/LWP?
On Fri, Feb 17, 2006 at 01:16:00AM +1100, Brendan Gregg wrote:> G''Day Mike, > > On Wed, 15 Feb 2006, Mike Kuhnkey wrote: > > > I''m interested in monitoring the amount of stack used by a > > multi-threaded program. I assume ''stackdepth'' built-in would be > > useful...but not sure. Been through demo''s, ToolKit, and internals..but > > it''s just not clicking for me yet. > > > > Not sure how to measure start/end of stack size dynamically...Anyone > > know how to break this down? > > If you just want the stack size, > > # dtrace -n ''on-cpu { @[execname] = max(curthread->t_procp->p_stksize); }'' > dtrace: description ''on-cpu '' matched 3 probes > ^C > > svc.startd 8192 > fsflush 8192 > sched 8192 > nscd 8192 > bash 12288 > svcs 12288 > svc.configd 16384 > gnome-vfs-daemon 16384 > dtrace 16384 > miniserv.pl 24576 > gnome-panel 32768 > gnome-terminal 32768 > sshd 57344 > nautilus 73728 > snmpd 348160This doesn''t help with multi-threaded programs, however. You''re going to need to do something like: --- cut here --- #!/usr/sbin/dtrace -s this uintptr_t stkinfoptr; this uintptr_t stkptr; sched:::on-cpu, profile:::profile-997 { this->stkinfoptr = 0; this->stkptr = 0; } sched:::on-cpu, profile:::profile-997 /execname != "sched"/ { this->stkinfoptr = curthread->t_lwp->lwp_ustack; this->stkptr = (uintptr_t)0; } sched:::on-cpu, profile:::profile-997 /this->stkinfoptr != 0 && curpsinfo->pr_dmodel == PR_MODEL_ILP32/ { this->stkinfo32 = *(stack32_t *)copyin(this->stkinfoptr, sizeof (stack32_t)); this->stktop = (uintptr_t)this->stkinfo32.ss_sp + this->stkinfo32.ss_size; this->stkptr = (uintptr_t)uregs[R_SP]; } sched:::on-cpu, profile:::profile-997 /this->stkinfoptr != 0 && curpsinfo->pr_dmodel == PR_MODEL_LP64/ { this->stkinfo = *(stack_t *)copyin(this->stkinfoptr, sizeof (stack_t)); this->stktop = (uintptr_t)this->stkinfo.ss_sp + this->stkinfo.ss_size; this->stkptr = (uintptr_t)uregs[R_SP]; } sched:::on-cpu, profile:::profile-997 /this->stkptr != 0/ { @a[execname] = quantize(this->stktop - this->stkptr); } dtrace:::ERROR { @b[execname] = count(); } dtrace:::END { printa(@a); printf("\nErrors:\n"); printa(" %@d %s\n", @b); } --- cut here --- Cheers, - jonathan -- Jonathan Adams, Solaris Kernel Development
G''Day Jonathan, On Thu, 16 Feb 2006, Jonathan Adams wrote:> On Fri, Feb 17, 2006 at 01:16:00AM +1100, Brendan Gregg wrote: > > G''Day Mike, > > > > On Wed, 15 Feb 2006, Mike Kuhnkey wrote: > > > > > I''m interested in monitoring the amount of stack used by a > > > multi-threaded program. I assume ''stackdepth'' built-in would be > > > useful...but not sure. Been through demo''s, ToolKit, and internals..but > > > it''s just not clicking for me yet. > > > > > > Not sure how to measure start/end of stack size dynamically...Anyone > > > know how to break this down? > > > > If you just want the stack size, > > > > # dtrace -n ''on-cpu { @[execname] = max(curthread->t_procp->p_stksize); }'' > > dtrace: description ''on-cpu '' matched 3 probes > > ^C[...]> > This doesn''t help with multi-threaded programs, however.Nope, but tracing them is much harder.> You''re going to need to do something like:bah - stop making it look easy! :-) When I realised I''d have to look into the stack structures themselves, I imagined it to be much more convoluted. Very cool script! Brendan> --- cut here --- > #!/usr/sbin/dtrace -s > > this uintptr_t stkinfoptr; > this uintptr_t stkptr; > > sched:::on-cpu, profile:::profile-997 > {[...]
Jonathan Adams
2006-Feb-18 00:19 UTC
[dtrace-discuss] Script for Stackdepth by Thread/LWP?
On Sat, Feb 18, 2006 at 10:01:35AM +1100, Brendan Gregg wrote:> G''Day Jonathan, > > On Thu, 16 Feb 2006, Jonathan Adams wrote: > > > On Fri, Feb 17, 2006 at 01:16:00AM +1100, Brendan Gregg wrote: > > > G''Day Mike, > > > > > > On Wed, 15 Feb 2006, Mike Kuhnkey wrote: > > > > > > > I''m interested in monitoring the amount of stack used by a > > > > multi-threaded program. I assume ''stackdepth'' built-in would be > > > > useful...but not sure. Been through demo''s, ToolKit, and internals..but > > > > it''s just not clicking for me yet. > > > > > > > > Not sure how to measure start/end of stack size dynamically...Anyone > > > > know how to break this down? > > > > > > If you just want the stack size, > > > > > > # dtrace -n ''on-cpu { @[execname] = max(curthread->t_procp->p_stksize); }'' > > > dtrace: description ''on-cpu '' matched 3 probes > > > ^C > [...] > > > > This doesn''t help with multi-threaded programs, however. > > Nope, but tracing them is much harder. > > > You''re going to need to do something like: > > bah - stop making it look easy! :-) > > When I realised I''d have to look into the stack structures themselves, I > imagined it to be much more convoluted. Very cool script!Adam''s work in early Solaris 10 to add a "ustack" structure simplifies it significantly. Without that, it would be almost impossible. Cheers, - jonathan -- Jonathan Adams, Solaris Kernel Development