]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - cddl/contrib/dtracetoolkit/Tcl/tcl_stat.d
Copy head (r256279) to stable/10 as part of the 10.0-RELEASE cycle.
[FreeBSD/stable/10.git] / cddl / contrib / dtracetoolkit / Tcl / tcl_stat.d
1 #!/usr/sbin/dtrace -Zs
2 /*
3  * tcl_stat.d - Tcl operation stats using DTrace.
4  *            Written for the Tcl DTrace provider.
5  *
6  * $Id: tcl_stat.d 63 2007-10-04 04:34:38Z brendan $
7  *
8  * This traces activity from all Tcl processes on the system with DTrace
9  * provider support (tcl8.4.16).
10  *
11  * USAGE: tcl_stat.d [interval [count]]
12  *
13  * FIELDS:
14  *              EXEC/s          Tcl programs executed per second, including
15  *                              those without Tcl provider support
16  *              PROC/s          Procedures called, per second
17  *              CMD/s           Commands created, per second
18  *              OBJNEW/s        Objects created, per second
19  *              OBJFRE/s        Objects freed, per second
20  *              OP/s            Bytecode operations, per second
21  *
22  * The numbers are counts for the interval specified. The default interval
23  * is 1 second.
24  *
25  * If you see a count in "EXECS" but not in the other columns, then you
26  * may have older Tcl software that does not have the integrated DTrace
27  * provider (or newer software where the provider has changed).
28  *
29  * COPYRIGHT: Copyright (c) 2007 Brendan Gregg.
30  *
31  * CDDL HEADER START
32  *
33  *  The contents of this file are subject to the terms of the
34  *  Common Development and Distribution License, Version 1.0 only
35  *  (the "License").  You may not use this file except in compliance
36  *  with the License.
37  *
38  *  You can obtain a copy of the license at Docs/cddl1.txt
39  *  or http://www.opensolaris.org/os/licensing.
40  *  See the License for the specific language governing permissions
41  *  and limitations under the License.
42  *
43  * CDDL HEADER END
44  *
45  * 09-Sep-2007  Brendan Gregg   Created this.
46  */
47
48 #pragma D option quiet
49 #pragma D option defaultargs
50
51 inline int SCREEN = 21;
52
53 dtrace:::BEGIN
54 {
55         execs = procs = cmds = objnew = objfree = ops = 0;
56         lines = SCREEN + 1;
57         interval = $1 ? $1 : 1;
58         counts = $2 ? $2 : -1;
59         secs = interval;
60         first = 1;
61 }
62
63 profile:::tick-1sec
64 {
65         secs--;
66 }
67
68 /*
69  * Print Header
70  */
71 dtrace:::BEGIN,
72 profile:::tick-1sec
73 /first || (secs == 0 && lines > SCREEN)/
74 {
75         printf("%-20s %6s %8s %8s %8s %8s %8s\n", "TIME", "EXEC/s",
76             "PROC/s", "CMD/s", "OBJNEW/s", "OBJFRE/s", "OP/s");
77         lines = 0;
78         first = 0;
79 }
80
81 /*
82  * Tally Data
83  */
84 proc:::exec-success
85 /execname == "tcl" || execname == "tclsh"/
86 {
87         execs++;
88 }
89
90 tcl*:::proc-entry
91 {
92         procs++;
93 }
94
95 tcl*:::cmd-entry
96 {
97         cmds++;
98 }
99
100 tcl*:::obj-create
101 {
102         objnew++;
103 }
104
105 tcl*:::obj-free
106 {
107         objfree++;
108 }
109
110 tcl*:::inst-start
111 {
112         ops++;
113 }
114
115 /*
116  * Print Output
117  */
118 profile:::tick-1sec
119 /secs == 0/
120 {
121         printf("%-20Y %6d %8d %8d %8d %8d %8d\n", walltimestamp,
122             execs / interval, procs / interval, cmds / interval,
123             objnew / interval, objfree / interval, ops / interval);
124         execs = procs = cmds = objnew = objfree = ops = 0;
125         secs = interval;
126         lines++;
127         counts--;
128 }
129
130 /*
131  * End
132  */
133 profile:::tick-1sec
134 /counts == 0/
135 {
136         exit(0);
137 }