j_profile.d revision 1.1 1 #!/usr/sbin/dtrace -CZs
2 /*
3 * j_profile.d - sample stack traces with Java translations using DTrace.
4 *
5 * USAGE: j_profile.d { -p PID | -c cmd } # hit Ctrl-C to end
6 * $Id: j_profile.d,v 1.1 2015/09/30 22:01:09 christos Exp $
7 *
8 *
9 * This samples stack traces for the process specified. This stack trace
10 * will cross the JVM and system libraries, and insert translations for Java
11 * stack frames where appropriate. This is best explained with an example
12 * stack frame output,
13 *
14 * Func_loop.func_c()V
15 * Func_loop.func_b()V
16 * Func_loop.func_a()V
17 * Func_loop.main([Ljava/lang/String;)V
18 * StubRoutines (1)
19 * libjvm.so`__1cJJavaCallsLcall_helper6FpnJJavaValue_pnMmethodHan
20 * libjvm.so`__1cCosUos_exception_wrapper6FpFpnJJavaValue_pnMmetho
21 * libjvm.so`__1cJJavaCallsEcall6FpnJJavaValue_nMmethodHandle_pnRJ
22 * libjvm.so`__1cRjni_invoke_static6FpnHJNIEnv__pnJJavaValue_pnI_j
23 * libjvm.so`jni_CallStaticVoidMethod+0x15d
24 * java`JavaMain+0xd30
25 * libc.so.1`_thr_setup+0x52
26 * libc.so.1`_lwp_start
27 * 101
28 *
29 * The lines at the top are Java frames, followed by the JVM (libjvm.so).
30 * The JVM symbols may be translated by passing the output through c++filt.
31 *
32 * COPYRIGHT: Copyright (c) 2007 Brendan Gregg.
33 *
34 * CDDL HEADER START
35 *
36 * The contents of this file are subject to the terms of the
37 * Common Development and Distribution License, Version 1.0 only
38 * (the "License"). You may not use this file except in compliance
39 * with the License.
40 *
41 * You can obtain a copy of the license at Docs/cddl1.txt
42 * or http://www.opensolaris.org/os/licensing.
43 * See the License for the specific language governing permissions
44 * and limitations under the License.
45 *
46 * CDDL HEADER END
47 *
48 * 09-Sep-2007 Brendan Gregg Created this.
49 */
50
51 #pragma D option quiet
52 #pragma D option jstackstrsize=1024
53
54 /*
55 * Tunables
56 */
57 #define DEPTH 10 /* stack depth, frames */
58 #define RATE 101 /* sampling rate, Hertz */
59 #define TOP 25 /* number of stacks to output */
60
61 dtrace:::BEGIN
62 {
63 printf("Sampling %d-level stacks at %d Hertz... Hit Ctrl-C to end.\n",
64 DEPTH, RATE);
65 }
66
67 profile-RATE
68 /pid == $target/
69 {
70 @stacks[jstack(DEPTH)] = count();
71 }
72
73 dtrace:::END
74 {
75 trunc(@stacks, TOP);
76 printf("Top %d most frequently sampled stacks,\n", TOP);
77 printa(@stacks);
78 }
79