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

#pragma D option quiet
#pragma D option jstackstrsize=1024

/*
 * Tunables
 */
#define DEPTH	10		/* stack depth, frames */
#define RATE	101		/* sampling rate, Hertz */
#define TOP	25		/* number of stacks to output */

dtrace:::BEGIN
{
	printf("Sampling %d-level stacks at %d Hertz... Hit Ctrl-C to end.\n",
	    DEPTH, RATE);
}

profile-RATE
/pid == $target/
{
	@stacks[jstack(DEPTH)] = count();
}

dtrace:::END
{
	trunc(@stacks, TOP);
	printf("Top %d most frequently sampled stacks,\n", TOP);
	printa(@stacks);
}