1 #!/usr/sbin/dtrace -Zs 2 /* 3 * js_stat.d - JavaScript operation stats using DTrace. 4 * Written for the JavaScript DTrace provider. 5 * 6 * $Id: js_stat.d,v 1.1.1.1 2015/09/30 22:01:09 christos Exp $ 7 * 8 * This traces activity from all browsers on the system that are 9 * running with JavaScript provider support. 10 * 11 * USAGE: js_stat.d [interval [count]] 12 * 13 * FIELDS: 14 * EXEC/s JavaScript programs executed per second 15 * FUNCS/s Functions called, per second 16 * OBJNEW/s Objects created, per second 17 * OBJFRE/s Objects freed (finalize), per second 18 * 19 * The numbers are counts for the interval specified. The default interval 20 * is 1 second. 21 * 22 * Filename and function names are printed if available. 23 * 24 * COPYRIGHT: Copyright (c) 2007 Brendan Gregg. 25 * 26 * CDDL HEADER START 27 * 28 * The contents of this file are subject to the terms of the 29 * Common Development and Distribution License, Version 1.0 only 30 * (the "License"). You may not use this file except in compliance 31 * with the License. 32 * 33 * You can obtain a copy of the license at Docs/cddl1.txt 34 * or http://www.opensolaris.org/os/licensing. 35 * See the License for the specific language governing permissions 36 * and limitations under the License. 37 * 38 * CDDL HEADER END 39 * 40 * 09-Sep-2007 Brendan Gregg Created this. 41 */ 42 43 #pragma D option quiet 44 #pragma D option defaultargs 45 46 inline int SCREEN = 21; 47 48 dtrace:::BEGIN 49 { 50 execs = funcs = objnew = objfree = 0; 51 lines = SCREEN + 1; 52 interval = $1 ? $1 : 1; 53 counts = $2 ? $2 : -1; 54 secs = interval; 55 first = 1; 56 } 57 58 profile:::tick-1sec 59 { 60 secs--; 61 } 62 63 /* 64 * Print Header 65 */ 66 dtrace:::BEGIN, 67 profile:::tick-1sec 68 /first || (secs == 0 && lines > SCREEN)/ 69 { 70 printf("%-20s %8s %8s %8s %8s\n", "TIME", "EXEC/s", "FUNC/s", 71 "OBJNEW/s", "OBJFRE/s"); 72 lines = 0; 73 first = 0; 74 } 75 76 /* 77 * Tally Data 78 */ 79 javascript*:::execute-start 80 { 81 execs++; 82 } 83 84 javascript*:::function-entry 85 { 86 funcs++; 87 } 88 89 javascript*:::object-create-start 90 { 91 objnew++; 92 } 93 94 javascript*:::object-finalize 95 { 96 objfree++; 97 } 98 99 /* 100 * Print Output 101 */ 102 profile:::tick-1sec 103 /secs == 0/ 104 { 105 printf("%-20Y %8d %8d %8d %8d\n", walltimestamp, execs / interval, 106 funcs / interval, objnew / interval, objfree / interval); 107 execs = funcs = objnew = objfree = 0; 108 secs = interval; 109 lines++; 110 counts--; 111 } 112 113 /* 114 * End 115 */ 116 profile:::tick-1sec 117 /counts == 0/ 118 { 119 exit(0); 120 } 121