1N/A#!/usr/sbin/dtrace -Zs
1N/A/*
1N/A * j_stat.d - Java operation stats using DTrace.
1N/A * Written for the Java hotspot DTrace provider.
1N/A *
1N/A * $Id: j_stat.d 64 2007-10-04 08:35:29Z claire $
1N/A *
1N/A * This traces activity from all Java processes on the system with hotspot
1N/A * provider support (1.6.0). Method calls and object allocation are only
1N/A * visible when using the flag "+ExtendedDTraceProbes". eg,
1N/A * java -XX:+ExtendedDTraceProbes classfile
1N/A *
1N/A * USAGE: j_stat.d [interval [count]]
1N/A *
1N/A * FIELDS:
1N/A * EXEC/s Java programs executed per second, including
1N/A * those without Java provider support
1N/A * THREAD/s Threads created, per second
1N/A * METHOD/s Methods called, per second
1N/A * OBJNEW/s Objects created, per second
1N/A * CLOAD/s Class loads, per second
1N/A * EXCP/s Exceptions raised, per second
1N/A * GC/s Garbage collects, per second
1N/A *
1N/A * The numbers are per second counts for the interval specified. The default
1N/A * interval is 1 second.
1N/A *
1N/A * If you see a count in "EXECS" but not in the other columns, then your
1N/A * Java software is probably not running with the DTrace hotspot provider.
1N/A *
1N/A * If you see counts in "CLOAD" but not in "METHODS", then you Java
1N/A * software probably isn't running with "+ExtendedDTraceProbes".
1N/A *
1N/A * COPYRIGHT: Copyright (c) 2007 Brendan Gregg.
1N/A *
1N/A * CDDL HEADER START
1N/A *
1N/A * The contents of this file are subject to the terms of the
1N/A * Common Development and Distribution License, Version 1.0 only
1N/A * (the "License"). You may not use this file except in compliance
1N/A * with the License.
1N/A *
1N/A * You can obtain a copy of the license at Docs/cddl1.txt
1N/A * or http://www.opensolaris.org/os/licensing.
1N/A * See the License for the specific language governing permissions
1N/A * and limitations under the License.
1N/A *
1N/A * CDDL HEADER END
1N/A *
1N/A * 09-Sep-2007 Brendan Gregg Created this.
1N/A */
1N/A
1N/A#pragma D option quiet
1N/A#pragma D option defaultargs
1N/A
1N/Ainline int SCREEN = 21;
1N/A
1N/Adtrace:::BEGIN
1N/A{
1N/A execs = threads = methods = objnew = cload = gc = exception = 0;
1N/A lines = SCREEN + 1;
1N/A interval = $1 ? $1 : 1;
1N/A counts = $2 ? $2 : -1;
1N/A secs = interval;
1N/A first = 1;
1N/A}
1N/A
1N/Aprofile:::tick-1sec
1N/A{
1N/A secs--;
1N/A}
1N/A
1N/A/*
1N/A * Print Header
1N/A */
1N/Adtrace:::BEGIN,
1N/Aprofile:::tick-1sec
1N/A/first || (secs == 0 && lines > SCREEN)/
1N/A{
1N/A printf("%-20s %6s %8s %8s %8s %8s %6s %6s\n", "TIME", "EXEC/s",
1N/A "THREAD/s", "METHOD/s", "OBJNEW/s", "CLOAD/s", "EXCP/s", "GC/s");
1N/A lines = 0;
1N/A first = 0;
1N/A}
1N/A
1N/A/*
1N/A * Tally Data
1N/A */
1N/Aproc:::exec-success
1N/A/execname == "java"/
1N/A{
1N/A execs++;
1N/A}
1N/A
1N/Ahotspot*:::thread-start
1N/A{
1N/A threads++;
1N/A}
1N/A
1N/Ahotspot*:::method-entry
1N/A{
1N/A methods++;
1N/A}
1N/A
1N/Ahotspot*:::object-alloc
1N/A{
1N/A oalloc++;
1N/A}
1N/A
1N/Ahotspot*:::class-loaded
1N/A{
1N/A cload++;
1N/A}
1N/A
1N/Ahotspot*:::gc-begin
1N/A{
1N/A gc++;
1N/A}
1N/A
1N/Ahotspot*:::ExceptionOccurred-entry
1N/A{
1N/A exception++;
1N/A}
1N/A
1N/A/*
1N/A * Print Output
1N/A */
1N/Aprofile:::tick-1sec
1N/A/secs == 0/
1N/A{
1N/A printf("%-20Y %6d %8d %8d %8d %8d %6d %6d\n", walltimestamp,
1N/A execs / interval, threads / interval, methods / interval,
1N/A oalloc / interval, cload / interval, exception / interval,
1N/A gc / interval);
1N/A execs = threads = methods = oalloc = cload = gc = exception = 0;
1N/A secs = interval;
1N/A lines++;
1N/A counts--;
1N/A}
1N/A
1N/A/*
1N/A * End
1N/A */
1N/Aprofile:::tick-1sec
1N/A/counts == 0/
1N/A{
1N/A exit(0);
1N/A}