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