]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - cddl/contrib/dtracetoolkit/JavaScript/js_calldist.d
Copy head (r256279) to stable/10 as part of the 10.0-RELEASE cycle.
[FreeBSD/stable/10.git] / cddl / contrib / dtracetoolkit / JavaScript / js_calldist.d
1 #!/usr/sbin/dtrace -Zs
2 /*
3  * js_calldist.d - measure JavaScript elapsed times for types of operation.
4  *                 Written for the JavaScript DTrace provider.
5  *
6  * $Id: js_calldist.d 63 2007-10-04 04:34:38Z brendan $
7  *
8  * This traces JavaScript activity from all browsers running on the system with
9  * JavaScript provider support.
10  *
11  * USAGE: js_calldist.d         # hit Ctrl-C to end
12  *
13  * FIELDS:
14  *              1               Filename of the JavaScript program
15  *              2               Type of call (func/obj-new)
16  *              3               Name of call
17  *
18  * Filename and function names are printed if available.
19  *
20  * COPYRIGHT: Copyright (c) 2007 Brendan Gregg.
21  *
22  * CDDL HEADER START
23  *
24  *  The contents of this file are subject to the terms of the
25  *  Common Development and Distribution License, Version 1.0 only
26  *  (the "License").  You may not use this file except in compliance
27  *  with the License.
28  *
29  *  You can obtain a copy of the license at Docs/cddl1.txt
30  *  or http://www.opensolaris.org/os/licensing.
31  *  See the License for the specific language governing permissions
32  *  and limitations under the License.
33  *
34  * CDDL HEADER END
35  *
36  * 09-Sep-2007  Brendan Gregg   Created this.
37  */
38
39 #pragma D option quiet
40
41 dtrace:::BEGIN
42 {
43         printf("Tracing... Hit Ctrl-C to end.\n");
44 }
45
46 javascript*:::function-entry
47 {
48         self->depth++;
49         self->exclude[self->depth] = 0;
50         self->function[self->depth] = timestamp;
51 }
52
53 javascript*:::function-return
54 /self->function[self->depth]/
55 {
56         this->elapsed_incl = timestamp - self->function[self->depth];
57         this->elapsed_excl = this->elapsed_incl - self->exclude[self->depth];
58         self->function[self->depth] = 0;
59         self->exclude[self->depth] = 0;
60         this->file = basename(copyinstr(arg0));
61         this->name = copyinstr(arg2);
62
63         @types_incl[this->file, "func", this->name] =
64             quantize(this->elapsed_incl / 1000);
65         @types_excl[this->file, "func", this->name] =
66             quantize(this->elapsed_excl / 1000);
67
68         self->depth--;
69         self->exclude[self->depth] += this->elapsed_incl;
70 }
71
72 javascript*:::object-create-start
73 {
74         self->object = timestamp;
75 }
76
77 javascript*:::object-create-done
78 /self->object/
79 {
80         this->elapsed = timestamp - self->object;
81         self->object = 0;
82         this->file = basename(copyinstr(arg0));
83         this->name = copyinstr(arg1);
84
85         @types[this->file, "obj-new", this->name] =
86             quantize(this->elapsed / 1000);
87
88         self->exclude[self->depth] += this->elapsed;
89 }
90
91 dtrace:::END
92 {
93         printf("\nElapsed times (us),\n");
94         printa("   %s, %s, %s %@d\n", @types);
95
96         printf("\nExclusive function elapsed times (us),\n");
97         printa("   %s, %s, %s %@d\n", @types_excl);
98
99         printf("\nInclusive function elapsed times (us),\n");
100         printa("   %s, %s, %s %@d\n", @types_incl);
101 }