1#!/usr/sbin/dtrace -Zs 2/* 3 * j_stat.d - Java operation stats using DTrace. 4 * Written for the Java hotspot DTrace provider. 5 * 6 * $Id: j_stat.d 64 2007-10-04 08:35:29Z claire $ 7 * 8 * This traces activity from all Java processes on the system with hotspot 9 * provider support (1.6.0). Method calls and object allocation are only 10 * visible when using the flag "+ExtendedDTraceProbes". eg, 11 * java -XX:+ExtendedDTraceProbes classfile 12 * 13 * USAGE: j_stat.d [interval [count]] 14 * 15 * FIELDS: 16 * EXEC/s Java programs executed per second, including 17 * those without Java provider support 18 * THREAD/s Threads created, per second 19 * METHOD/s Methods called, per second 20 * OBJNEW/s Objects created, per second 21 * CLOAD/s Class loads, per second 22 * EXCP/s Exceptions raised, per second 23 * GC/s Garbage collects, per second 24 * 25 * The numbers are per second counts for the interval specified. The default 26 * interval is 1 second. 27 * 28 * If you see a count in "EXECS" but not in the other columns, then your 29 * Java software is probably not running with the DTrace hotspot provider. 30 * 31 * If you see counts in "CLOAD" but not in "METHODS", then you Java 32 * software probably isn't running with "+ExtendedDTraceProbes". 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#pragma D option quiet 54#pragma D option defaultargs 55 56inline int SCREEN = 21; 57 58dtrace:::BEGIN 59{ 60 execs = threads = methods = objnew = cload = gc = exception = 0; 61 lines = SCREEN + 1; 62 interval = $1 ? $1 : 1; 63 counts = $2 ? $2 : -1; 64 secs = interval; 65 first = 1; 66} 67 68profile:::tick-1sec 69{ 70 secs--; 71} 72 73/* 74 * Print Header 75 */ 76dtrace:::BEGIN, 77profile:::tick-1sec 78/first || (secs == 0 && lines > SCREEN)/ 79{ 80 printf("%-20s %6s %8s %8s %8s %8s %6s %6s\n", "TIME", "EXEC/s", 81 "THREAD/s", "METHOD/s", "OBJNEW/s", "CLOAD/s", "EXCP/s", "GC/s"); 82 lines = 0; 83 first = 0; 84} 85 86/* 87 * Tally Data 88 */ 89proc:::exec-success 90/execname == "java"/ 91{ 92 execs++; 93} 94 95hotspot*:::thread-start 96{ 97 threads++; 98} 99 100hotspot*:::method-entry 101{ 102 methods++; 103} 104 105hotspot*:::object-alloc 106{ 107 oalloc++; 108} 109 110hotspot*:::class-loaded 111{ 112 cload++; 113} 114 115hotspot*:::gc-begin 116{ 117 gc++; 118} 119 120hotspot*:::ExceptionOccurred-entry 121{ 122 exception++; 123} 124 125/* 126 * Print Output 127 */ 128profile:::tick-1sec 129/secs == 0/ 130{ 131 printf("%-20Y %6d %8d %8d %8d %8d %6d %6d\n", walltimestamp, 132 execs / interval, threads / interval, methods / interval, 133 oalloc / interval, cload / interval, exception / interval, 134 gc / interval); 135 execs = threads = methods = oalloc = cload = gc = exception = 0; 136 secs = interval; 137 lines++; 138 counts--; 139} 140 141/* 142 * End 143 */ 144profile:::tick-1sec 145/counts == 0/ 146{ 147 exit(0); 148} 149