1106163Sroberto#!/usr/sbin/dtrace -Zs
254359Sroberto/*
354359Sroberto * js_objgc.d - trace JavaScript Object GC using DTrace.
454359Sroberto *              Written for the JavaScript DTrace provider.
554359Sroberto *
654359Sroberto * $Id: js_objgc.d 63 2007-10-04 04:34:38Z brendan $
754359Sroberto *
854359Sroberto * This traces JavaScript activity from all running browers on the system
954359Sroberto * which support the JavaScript DTrace provider.
1054359Sroberto *
1154359Sroberto * USAGE: js_objgc.d		# hit Ctrl-C to end
1254359Sroberto *
1354359Sroberto * FIELDS:
1454359Sroberto *		FILE		Filename that contained the function
1554359Sroberto *		CLASS		Class to which this new object belongs
1654359Sroberto *		TOTAL		Object entropy (positive == uncollected)
1754359Sroberto *
1854359Sroberto * This script provides information on which objects are not being garbage
1954359Sroberto * collected, an issue which causes the browser to steadily leak memory.
2054359Sroberto * We trace object creation (+1) and destruction (-1), and provide a
2154359Sroberto * summary each second of the running tally of the object class and
2254359Sroberto * originating filename. If over the period of several minutes an object
2354359Sroberto * type is still steadily increasing, then that would be of interest.
2454359Sroberto * Be patient, depending on the rate of object creation it can take over
2554359Sroberto * ten minutes for garbage collect to kick in.
2654359Sroberto *
2754359Sroberto * NOTES:
2854359Sroberto * - it is possible that you will see negative entropy. That happens
2954359Sroberto * when you begin tracing after some objects have already been created,
3054359Sroberto * and then trace their destruction.
3154359Sroberto * - there are other Things that GC handles, other than Objects; extra
3254359Sroberto * probes can be added to trace them, should the need arise.
3354359Sroberto *
3454359Sroberto * COPYRIGHT: Copyright (c) 2007 Brendan Gregg.
3554359Sroberto *
3654359Sroberto * CDDL HEADER START
3754359Sroberto *
3854359Sroberto *  The contents of this file are subject to the terms of the
3954359Sroberto *  Common Development and Distribution License, Version 1.0 only
4054359Sroberto *  (the "License").  You may not use this file except in compliance
4154359Sroberto *  with the License.
4254359Sroberto *
4354359Sroberto *  You can obtain a copy of the license at Docs/cddl1.txt
4454359Sroberto *  or http://www.opensolaris.org/os/licensing.
4554359Sroberto *  See the License for the specific language governing permissions
4654359Sroberto *  and limitations under the License.
4754359Sroberto *
4854359Sroberto * CDDL HEADER END
4954359Sroberto *
5054359Sroberto * 09-Sep-2007	Brendan Gregg	Created this.
5154359Sroberto */
5254359Sroberto
5354359Sroberto/* if you get dynvardrops, increase this, */
5454359Sroberto#pragma D option dynvarsize=32m
5554359Sroberto#pragma D option quiet
5654359Sroberto
5754359Srobertodtrace:::BEGIN
5854359Sroberto{
5954359Sroberto	printf("Tracing... Hit Ctrl-C to end.\n");
6054359Sroberto}
6154359Sroberto
6254359Srobertojavascript*:::object-create
6354359Sroberto/arg2/
6454359Sroberto{
6554359Sroberto	this->file = basename(copyinstr(arg0));
6654359Sroberto	@objs[this->file, copyinstr(arg1)] = sum(1);
6754359Sroberto	filename[arg2] = this->file;
6854359Sroberto}
6954359Sroberto
7054359Srobertojavascript*:::object-finalize
7154359Sroberto/filename[arg2] == NULL/
7254359Sroberto{
7354359Sroberto	@objs["<missed>", copyinstr(arg1)] = sum(-1);
7454359Sroberto}
7554359Sroberto
7654359Srobertojavascript*:::object-finalize
7754359Sroberto/filename[arg2] != NULL/
7854359Sroberto{
7954359Sroberto	@objs[filename[arg2], copyinstr(arg1)] = sum(-1);
8054359Sroberto	filename[arg2] = 0;
8154359Sroberto}
8254359Sroberto
8354359Srobertoprofile:::tick-1sec,
8454359Srobertodtrace:::END
8554359Sroberto{
8654359Sroberto	printf("\n %-24s %8s %-20s %23Y\n", "FILE", "TOTAL", "CLASS",
8754359Sroberto	    walltimestamp);
8854359Sroberto	printa(" %-24.24s %@8d %s\n", @objs);
8954359Sroberto}
9054359Sroberto