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