1 #!/usr/sbin/dtrace -Zs
2 /*
3  * js_cpudist.d - measure JavaScript on-CPU times for types of operation.
4  *                 Written for the JavaScript DTrace provider.
5  *
6  * $Id: js_cpudist.d,v 1.1.1.1 2015/09/30 22:01:07 christos Exp $
7  *
8  * This traces JavaScript activity from all browsers running on the system with
9  * JavaScript provider support.
10  *
11  * USAGE: js_cpudist.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] = vtimestamp;
51 }
52 
53 javascript*:::function-return
54 /self->function[self->depth]/
55 {
56 	this->oncpu_incl = vtimestamp - self->function[self->depth];
57 	this->oncpu_excl = this->oncpu_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->oncpu_incl / 1000);
65 	@types_excl[this->file, "func", this->name] =
66 	    quantize(this->oncpu_excl / 1000);
67 
68 	self->depth--;
69 	self->exclude[self->depth] += this->oncpu_incl;
70 }
71 
72 javascript*:::object-create-start
73 {
74 	self->object = vtimestamp;
75 }
76 
77 javascript*:::object-create-done
78 /self->object/
79 {
80 	this->oncpu = vtimestamp - 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->oncpu / 1000);
87 
88 	self->exclude[self->depth] += this->oncpu;
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 on-CPU times (us),\n");
97 	printa("   %s, %s, %s %@d\n", @types_excl);
98 
99 	printf("\nInclusive function on-CPU times (us),\n");
100 	printa("   %s, %s, %s %@d\n", @types_incl);
101 }
102