]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - cddl/contrib/dtracetoolkit/JavaScript/js_objgc.d
MFC r368207,368607:
[FreeBSD/stable/10.git] / cddl / contrib / dtracetoolkit / JavaScript / js_objgc.d
1 #!/usr/sbin/dtrace -Zs
2 /*
3  * js_objgc.d - trace JavaScript Object GC using DTrace.
4  *              Written for the JavaScript DTrace provider.
5  *
6  * $Id: js_objgc.d 63 2007-10-04 04:34:38Z brendan $
7  *
8  * This traces JavaScript activity from all running browers on the system
9  * which support the JavaScript DTrace provider.
10  *
11  * USAGE: js_objgc.d            # hit Ctrl-C to end
12  *
13  * FIELDS:
14  *              FILE            Filename that contained the function
15  *              CLASS           Class to which this new object belongs
16  *              TOTAL           Object entropy (positive == uncollected)
17  *
18  * This script provides information on which objects are not being garbage
19  * collected, an issue which causes the browser to steadily leak memory.
20  * We trace object creation (+1) and destruction (-1), and provide a
21  * summary each second of the running tally of the object class and
22  * originating filename. If over the period of several minutes an object
23  * type is still steadily increasing, then that would be of interest.
24  * Be patient, depending on the rate of object creation it can take over
25  * ten minutes for garbage collect to kick in.
26  *
27  * NOTES:
28  * - it is possible that you will see negative entropy. That happens
29  * when you begin tracing after some objects have already been created,
30  * and then trace their destruction.
31  * - there are other Things that GC handles, other than Objects; extra
32  * probes can be added to trace them, should the need arise.
33  *
34  * COPYRIGHT: Copyright (c) 2007 Brendan Gregg.
35  *
36  * CDDL HEADER START
37  *
38  *  The contents of this file are subject to the terms of the
39  *  Common Development and Distribution License, Version 1.0 only
40  *  (the "License").  You may not use this file except in compliance
41  *  with the License.
42  *
43  *  You can obtain a copy of the license at Docs/cddl1.txt
44  *  or http://www.opensolaris.org/os/licensing.
45  *  See the License for the specific language governing permissions
46  *  and limitations under the License.
47  *
48  * CDDL HEADER END
49  *
50  * 09-Sep-2007  Brendan Gregg   Created this.
51  */
52
53 /* if you get dynvardrops, increase this, */
54 #pragma D option dynvarsize=32m
55 #pragma D option quiet
56
57 dtrace:::BEGIN
58 {
59         printf("Tracing... Hit Ctrl-C to end.\n");
60 }
61
62 javascript*:::object-create
63 /arg2/
64 {
65         this->file = basename(copyinstr(arg0));
66         @objs[this->file, copyinstr(arg1)] = sum(1);
67         filename[arg2] = this->file;
68 }
69
70 javascript*:::object-finalize
71 /filename[arg2] == NULL/
72 {
73         @objs["<missed>", copyinstr(arg1)] = sum(-1);
74 }
75
76 javascript*:::object-finalize
77 /filename[arg2] != NULL/
78 {
79         @objs[filename[arg2], copyinstr(arg1)] = sum(-1);
80         filename[arg2] = 0;
81 }
82
83 profile:::tick-1sec,
84 dtrace:::END
85 {
86         printf("\n %-24s %8s %-20s %23Y\n", "FILE", "TOTAL", "CLASS",
87             walltimestamp);
88         printa(" %-24.24s %@8d %s\n", @objs);
89 }