1N/A#!/usr/sbin/dtrace -CZs
1N/A/*
1N/A * j_profile.d - sample stack traces with Java translations using DTrace.
1N/A *
1N/A * USAGE: j_profile.d { -p PID | -c cmd } # hit Ctrl-C to end
1N/A * $Id: j_profile.d 19 2007-09-12 07:47:59Z brendan $
1N/A *
1N/A *
1N/A * This samples stack traces for the process specified. This stack trace
1N/A * will cross the JVM and system libraries, and insert translations for Java
1N/A * stack frames where appropriate. This is best explained with an example
1N/A * stack frame output,
1N/A *
1N/A * Func_loop.func_c()V
1N/A * Func_loop.func_b()V
1N/A * Func_loop.func_a()V
1N/A * Func_loop.main([Ljava/lang/String;)V
1N/A * StubRoutines (1)
1N/A * libjvm.so`__1cJJavaCallsLcall_helper6FpnJJavaValue_pnMmethodHan
1N/A * libjvm.so`__1cCosUos_exception_wrapper6FpFpnJJavaValue_pnMmetho
1N/A * libjvm.so`__1cJJavaCallsEcall6FpnJJavaValue_nMmethodHandle_pnRJ
1N/A * libjvm.so`__1cRjni_invoke_static6FpnHJNIEnv__pnJJavaValue_pnI_j
1N/A * libjvm.so`jni_CallStaticVoidMethod+0x15d
1N/A * java`JavaMain+0xd30
1N/A * libc.so.1`_thr_setup+0x52
1N/A * libc.so.1`_lwp_start
1N/A * 101
1N/A *
1N/A * The lines at the top are Java frames, followed by the JVM (libjvm.so).
1N/A * The JVM symbols may be translated by passing the output through c++filt.
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 jstackstrsize=1024
1N/A
1N/A/*
1N/A * Tunables
1N/A */
1N/A#define DEPTH 10 /* stack depth, frames */
1N/A#define RATE 101 /* sampling rate, Hertz */
1N/A#define TOP 25 /* number of stacks to output */
1N/A
1N/Adtrace:::BEGIN
1N/A{
1N/A printf("Sampling %d-level stacks at %d Hertz... Hit Ctrl-C to end.\n",
1N/A DEPTH, RATE);
1N/A}
1N/A
1N/Aprofile-RATE
1N/A/pid == $target/
1N/A{
1N/A @stacks[jstack(DEPTH)] = count();
1N/A}
1N/A
1N/Adtrace:::END
1N/A{
1N/A trunc(@stacks, TOP);
1N/A printf("Top %d most frequently sampled stacks,\n", TOP);
1N/A printa(@stacks);
1N/A}