1235368Sgnn#!/usr/sbin/dtrace -s
2/*
3 * stacksize.d - measure stack size for running threads.
4 *               Written using DTrace (Solaris 10 3/05).
5 *
6 * $Id: stacksize.d 3 2007-08-01 10:50:08Z brendan $
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 * 16-Feb-2006     "      "	Last update.
34 */
35
36#pragma D option quiet
37
38this uintptr_t stkinfoptr;
39this uintptr_t stkptr;
40
41dtrace:::BEGIN
42{
43	trace("Sampling... Hit Ctrl-C to end\n");
44}
45
46sched:::on-cpu, profile:::profile-997
47{
48	this->stkinfoptr = 0;
49	this->stkptr = 0;
50}
51
52sched:::on-cpu, profile:::profile-997
53/execname != "sched"/
54{
55	this->stkinfoptr = curthread->t_lwp->lwp_ustack;
56	this->stkptr = (uintptr_t)0;
57}
58
59sched:::on-cpu, profile:::profile-997
60/this->stkinfoptr != 0 && curpsinfo->pr_dmodel == PR_MODEL_ILP32/
61{
62	this->stkinfo32 = (stack32_t *)copyin(this->stkinfoptr,
63	    sizeof (stack32_t));
64	this->stktop = (uintptr_t)this->stkinfo32->ss_sp +
65	    this->stkinfo32->ss_size;
66	this->stkptr = (uintptr_t)uregs[R_SP];
67}
68
69sched:::on-cpu, profile:::profile-997
70/this->stkinfoptr != 0 && curpsinfo->pr_dmodel == PR_MODEL_LP64/
71{
72	this->stkinfo = (stack_t *)copyin(this->stkinfoptr,
73	    sizeof (stack_t));
74	this->stktop = (uintptr_t)this->stkinfo->ss_sp +
75	    this->stkinfo->ss_size;
76	this->stkptr = (uintptr_t)uregs[R_SP];
77}
78
79sched:::on-cpu, profile:::profile-997
80/this->stkptr != 0/
81{
82	@sizes[execname] = quantize(this->stktop - this->stkptr);
83}
84
85dtrace:::ERROR
86{
87	@errors[execname] = count();
88}
89
90dtrace:::END
91{
92	printa(@sizes);
93	printf("\nErrors:\n");
94	printa("    %@d %s\n", @errors);
95}
96