1#!/usr/sbin/dtrace -s
2/*
3 * stacksize.d - measure stack size for running threads.
4 *               Written using DTrace (Solaris 10 3/05).
5 *
6 * 16-Feb-2006, ver 0.70
7 *
8 * USAGE:       stacksize.d              # hit Ctrl-C to end sample
9 *
10 * FIELDS:
11 *		value		size of the user stack
12 *		count		number of samples at this size
13 *
14 * SEE ALSO:    pmap(1)
15 *
16 * COPYRIGHT: Copyright (c) 2006 Jonathan Adams
17 *
18 * CDDL HEADER START
19 *
20 *  The contents of this file are subject to the terms of the
21 *  Common Development and Distribution License, Version 1.0 only
22 *  (the "License").  You may not use this file except in compliance
23 *  with the License.
24 *
25 *  You can obtain a copy of the license at Docs/cddl1.txt
26 *  or http://www.opensolaris.org/os/licensing.
27 *  See the License for the specific language governing permissions
28 *  and limitations under the License.
29 *
30 * CDDL HEADER END
31 *
32 * 16-Feb-2006  Jonathan Adams	Created this.
33 */
34
35#pragma D option quiet
36
37this uintptr_t stkinfoptr;
38this uintptr_t stkptr;
39
40dtrace:::BEGIN
41{
42	trace("Sampling... Hit Ctrl-C to end\n");
43}
44
45sched:::on-cpu, profile:::profile-997
46{
47	this->stkinfoptr = 0;
48	this->stkptr = 0;
49}
50
51sched:::on-cpu, profile:::profile-997
52/execname != "sched"/
53{
54	this->stkinfoptr = curthread->t_lwp->lwp_ustack;
55	this->stkptr = (uintptr_t)0;
56}
57
58sched:::on-cpu, profile:::profile-997
59/this->stkinfoptr != 0 && curpsinfo->pr_dmodel == PR_MODEL_ILP32/
60{
61	this->stkinfo32 = (stack32_t *)copyin(this->stkinfoptr,
62	    sizeof (stack32_t));
63	this->stktop = (uintptr_t)this->stkinfo32->ss_sp +
64	    this->stkinfo32->ss_size;
65	this->stkptr = (uintptr_t)uregs[R_SP];
66}
67
68sched:::on-cpu, profile:::profile-997
69/this->stkinfoptr != 0 && curpsinfo->pr_dmodel == PR_MODEL_LP64/
70{
71	this->stkinfo = (stack_t *)copyin(this->stkinfoptr,
72	    sizeof (stack_t));
73	this->stktop = (uintptr_t)this->stkinfo->ss_sp +
74	    this->stkinfo->ss_size;
75	this->stkptr = (uintptr_t)uregs[R_SP];
76}
77
78sched:::on-cpu, profile:::profile-997
79/this->stkptr != 0/
80{
81	@sizes[execname] = quantize(this->stktop - this->stkptr);
82}
83
84dtrace:::ERROR
85{
86	@errors[execname] = count();
87}
88
89dtrace:::END
90{
91	printa(@sizes);
92	printf("\nErrors:\n");
93	printa("    %@d %s\n", @errors);
94}
95