]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - cddl/contrib/dtracetoolkit/Tcl/tcl_cpudist.d
Copy head (r256279) to stable/10 as part of the 10.0-RELEASE cycle.
[FreeBSD/stable/10.git] / cddl / contrib / dtracetoolkit / Tcl / tcl_cpudist.d
1 #!/usr/sbin/dtrace -CZs
2 /*
3  * tcl_cpudist.d - measure Tcl on-CPU time for different types of operation.
4  *                 Written for the Tcl DTrace provider.
5  *
6  * $Id: tcl_cpudist.d 63 2007-10-04 04:34:38Z brendan $
7  *
8  * USAGE: tcl_cpudist.d [top]   # hit Ctrl-C to end
9  *    eg,
10  *        tcl_cpudist.d         # default, truncate to 10 lines
11  *        tcl_cpudist.d 25      # truncate each report section to 25 lines
12  *
13  * This traces activity from all Tcl processes on the system with DTrace
14  * provider support (tcl8.4.16).
15  *
16  * FIELDS:
17  *              1               Process ID
18  *              2               Type of call (proc/cmd/total)
19  *              3               Name of call
20  *
21  * COPYRIGHT: Copyright (c) 2007 Brendan Gregg.
22  *
23  * CDDL HEADER START
24  *
25  *  The contents of this file are subject to the terms of the
26  *  Common Development and Distribution License, Version 1.0 only
27  *  (the "License").  You may not use this file except in compliance
28  *  with the License.
29  *
30  *  You can obtain a copy of the license at Docs/cddl1.txt
31  *  or http://www.opensolaris.org/os/licensing.
32  *  See the License for the specific language governing permissions
33  *  and limitations under the License.
34  *
35  * CDDL HEADER END
36  *
37  * 09-Sep-2007  Brendan Gregg   Created this.
38  */
39
40 #define TOP     10              /* default output truncation */
41 #define B_FALSE 0
42
43 #pragma D option quiet
44 #pragma D option defaultargs
45
46 dtrace:::BEGIN
47 {
48         printf("Tracing... Hit Ctrl-C to end.\n");
49         top = $1 != 0 ? $1 : TOP;
50 }
51
52 tcl*:::proc-entry
53 {
54         self->depth++;
55         self->exclude[self->depth] = 0;
56         self->proc[self->depth] = vtimestamp;
57 }
58
59 tcl*:::proc-return
60 /self->proc[self->depth]/
61 {
62         this->oncpu_incl = vtimestamp - self->proc[self->depth];
63         this->oncpu_excl = this->oncpu_incl - self->exclude[self->depth];
64         self->proc[self->depth] = 0;
65         self->exclude[self->depth] = 0;
66         this->name = copyinstr(arg0);
67
68         @types_incl[pid, "proc", this->name] =
69             quantize(this->oncpu_incl / 1000);
70         @types_excl[pid, "proc", this->name] =
71             quantize(this->oncpu_excl / 1000);
72
73         self->depth--;
74         self->exclude[self->depth] += this->oncpu_incl;
75 }
76
77 tcl*:::cmd-entry
78 {
79         self->depth++;
80         self->exclude[self->depth] = 0;
81         self->cmd[self->depth] = vtimestamp;
82 }
83
84 tcl*:::cmd-return
85 /self->cmd[self->depth]/
86 {
87         this->oncpu_incl = vtimestamp - self->cmd[self->depth];
88         this->oncpu_excl = this->oncpu_incl - self->exclude[self->depth];
89         self->cmd[self->depth] = 0;
90         self->exclude[self->depth] = 0;
91         this->name = copyinstr(arg0);
92
93         @types_incl[pid, "cmd", this->name] =
94             quantize(this->oncpu_incl / 1000);
95         @types_excl[pid, "cmd", this->name] =
96             quantize(this->oncpu_excl / 1000);
97
98         self->depth--;
99         self->exclude[self->depth] += this->oncpu_incl;
100 }
101
102 dtrace:::END
103 {
104         trunc(@types_excl, top);
105         printf("\nTop %d exclusive on-CPU times (us),\n", top);
106         printa("   PID=%d, %s, %s %@d\n", @types_excl);
107
108         trunc(@types_incl, top);
109         printf("\nTop %d inclusive on-CPU times (us),\n", top);
110         printa("   PID=%d, %s, %s %@d\n", @types_incl);
111 }