1178825Sdfr#!/usr/sbin/dtrace -Zs 2178825Sdfr/* 3178825Sdfr * js_objgc.d - trace JavaScript Object GC using DTrace. 4178825Sdfr * Written for the JavaScript DTrace provider. 5178825Sdfr * 6178825Sdfr * $Id: js_objgc.d 63 2007-10-04 04:34:38Z brendan $ 7178825Sdfr * 8178825Sdfr * This traces JavaScript activity from all running browers on the system 9178825Sdfr * which support the JavaScript DTrace provider. 10178825Sdfr * 11178825Sdfr * USAGE: js_objgc.d # hit Ctrl-C to end 12178825Sdfr * 13178825Sdfr * FIELDS: 14178825Sdfr * FILE Filename that contained the function 15178825Sdfr * CLASS Class to which this new object belongs 16178825Sdfr * TOTAL Object entropy (positive == uncollected) 17178825Sdfr * 18178825Sdfr * This script provides information on which objects are not being garbage 19178825Sdfr * collected, an issue which causes the browser to steadily leak memory. 20178825Sdfr * We trace object creation (+1) and destruction (-1), and provide a 21178825Sdfr * summary each second of the running tally of the object class and 22178825Sdfr * originating filename. If over the period of several minutes an object 23178825Sdfr * type is still steadily increasing, then that would be of interest. 24178825Sdfr * Be patient, depending on the rate of object creation it can take over 25178825Sdfr * ten minutes for garbage collect to kick in. 26178825Sdfr * 27178825Sdfr * NOTES: 28178825Sdfr * - it is possible that you will see negative entropy. That happens 29178825Sdfr * when you begin tracing after some objects have already been created, 30178825Sdfr * and then trace their destruction. 31178825Sdfr * - there are other Things that GC handles, other than Objects; extra 32178825Sdfr * probes can be added to trace them, should the need arise. 33178825Sdfr * 34178825Sdfr * COPYRIGHT: Copyright (c) 2007 Brendan Gregg. 35178825Sdfr * 36178825Sdfr * CDDL HEADER START 37178825Sdfr * 38178825Sdfr * The contents of this file are subject to the terms of the 39178825Sdfr * Common Development and Distribution License, Version 1.0 only 40178825Sdfr * (the "License"). You may not use this file except in compliance 41178825Sdfr * with the License. 42178825Sdfr * 43178825Sdfr * You can obtain a copy of the license at Docs/cddl1.txt 44178825Sdfr * or http://www.opensolaris.org/os/licensing. 45178825Sdfr * See the License for the specific language governing permissions 46178825Sdfr * and limitations under the License. 47178825Sdfr * 48178825Sdfr * CDDL HEADER END 49178825Sdfr * 50178825Sdfr * 09-Sep-2007 Brendan Gregg Created this. 51178825Sdfr */ 52178825Sdfr 53178825Sdfr/* if you get dynvardrops, increase this, */ 54178825Sdfr#pragma D option dynvarsize=32m 55178825Sdfr#pragma D option quiet 56178825Sdfr 57178825Sdfrdtrace:::BEGIN 58178825Sdfr{ 59178825Sdfr printf("Tracing... Hit Ctrl-C to end.\n"); 60178825Sdfr} 61178825Sdfr 62178825Sdfrjavascript*:::object-create 63178825Sdfr/arg2/ 64178825Sdfr{ 65178825Sdfr this->file = basename(copyinstr(arg0)); 66178825Sdfr @objs[this->file, copyinstr(arg1)] = sum(1); 67178825Sdfr filename[arg2] = this->file; 68178825Sdfr} 69178825Sdfr 70178825Sdfrjavascript*:::object-finalize 71178825Sdfr/filename[arg2] == NULL/ 72178825Sdfr{ 73178825Sdfr @objs["<missed>", copyinstr(arg1)] = sum(-1); 74178825Sdfr} 75178825Sdfr 76178825Sdfrjavascript*:::object-finalize 77178825Sdfr/filename[arg2] != NULL/ 78178825Sdfr{ 79178825Sdfr @objs[filename[arg2], copyinstr(arg1)] = sum(-1); 80178825Sdfr filename[arg2] = 0; 81178825Sdfr} 82178825Sdfr 83178825Sdfrprofile:::tick-1sec, 84178825Sdfrdtrace:::END 85178825Sdfr{ 86178825Sdfr printf("\n %-24s %8s %-20s %23Y\n", "FILE", "TOTAL", "CLASS", 87178825Sdfr walltimestamp); 88178825Sdfr printa(" %-24.24s %@8d %s\n", @objs); 89178825Sdfr} 90178825Sdfr