2
|
1 |
#!/usr/sbin/dtrace -Zs
|
|
2 |
/*
|
5506
|
3 |
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
|
2
|
4 |
*
|
|
5 |
* Redistribution and use in source and binary forms, with or without
|
|
6 |
* modification, are permitted provided that the following conditions
|
|
7 |
* are met:
|
|
8 |
*
|
|
9 |
* - Redistributions of source code must retain the above copyright
|
|
10 |
* notice, this list of conditions and the following disclaimer.
|
|
11 |
*
|
|
12 |
* - Redistributions in binary form must reproduce the above copyright
|
|
13 |
* notice, this list of conditions and the following disclaimer in the
|
|
14 |
* documentation and/or other materials provided with the distribution.
|
|
15 |
*
|
5506
|
16 |
* - Neither the name of Oracle nor the names of its
|
2
|
17 |
* contributors may be used to endorse or promote products derived
|
|
18 |
* from this software without specific prior written permission.
|
|
19 |
*
|
|
20 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
|
21 |
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
|
22 |
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
23 |
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
|
24 |
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
25 |
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
26 |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
27 |
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
28 |
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
29 |
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
30 |
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
31 |
*/
|
|
32 |
|
|
33 |
/*
|
|
34 |
*/
|
|
35 |
|
|
36 |
/*
|
|
37 |
* Usage:
|
|
38 |
* 1. hotspot_calls_tree.d -c "java ..."
|
|
39 |
* 2. hotspot_calls_tree.d -p JAVA_PID
|
|
40 |
*
|
|
41 |
* This script prints calls tree of fired 'hotspot' probes.
|
|
42 |
*
|
|
43 |
* Notes:
|
|
44 |
* The script uses 'monitors' probes which are disabled by default since
|
|
45 |
* it incurs performance overhead to the application. To enable them, you
|
|
46 |
* need to turn on the ExtendedDTraceProbes VM option. You can either
|
|
47 |
* start the application with -XX:+ExtendedDTraceProbes option or use the
|
|
48 |
* jinfo command to enable it at runtime as follows:
|
|
49 |
*
|
|
50 |
* jinfo -flag +ExtendedDTraceProbes <java_pid>
|
|
51 |
*
|
|
52 |
*/
|
|
53 |
|
|
54 |
#pragma D option quiet
|
|
55 |
#pragma D option destructive
|
|
56 |
#pragma D option defaultargs
|
|
57 |
#pragma D option aggrate=100ms
|
|
58 |
|
|
59 |
self int indent;
|
|
60 |
string PAUSE_AT_STARTUP_FILE;
|
|
61 |
|
|
62 |
:::BEGIN
|
|
63 |
{
|
|
64 |
SAMPLE_NAME = "hotspot probes tracing";
|
|
65 |
|
|
66 |
printf("BEGIN %s\n\n", SAMPLE_NAME);
|
|
67 |
|
|
68 |
self->indent = 10;
|
|
69 |
}
|
|
70 |
|
|
71 |
hotspot$target:::class-loaded,
|
|
72 |
hotspot$target:::class-unloaded,
|
|
73 |
hotspot$target:::compiled-method-load,
|
|
74 |
hotspot$target:::compiled-method-unload,
|
|
75 |
hotspot$target:::monitor-notify,
|
|
76 |
hotspot$target:::monitor-notifyAll
|
|
77 |
{
|
|
78 |
printf("%d %*s <-> %s\n", curcpu->cpu_id, self->indent, "", probename);
|
|
79 |
}
|
|
80 |
|
|
81 |
hotspot$target:::vm-init-begin,
|
|
82 |
hotspot$target:::gc-begin,
|
|
83 |
hotspot$target:::mem-pool-gc-begin,
|
|
84 |
hotspot$target:::thread-start,
|
|
85 |
hotspot$target:::method-compile-begin,
|
|
86 |
hotspot$target:::monitor-contended-enter,
|
|
87 |
hotspot$target:::monitor-wait
|
|
88 |
{
|
|
89 |
self->indent ++;
|
|
90 |
printf("%d %*s -> %s\n", curcpu->cpu_id, self->indent, "", probename);
|
|
91 |
}
|
|
92 |
|
|
93 |
hotspot$target:::vm-init-end,
|
|
94 |
hotspot$target:::vm-shutdown,
|
|
95 |
hotspot$target:::gc-end,
|
|
96 |
hotspot$target:::mem-pool-gc-end,
|
|
97 |
hotspot$target:::thread-stop,
|
|
98 |
hotspot$target:::method-compile-end,
|
|
99 |
hotspot$target:::monitor-contended-entered,
|
|
100 |
hotspot$target:::monitor-contended-exit,
|
|
101 |
hotspot$target:::monitor-waited
|
|
102 |
{
|
|
103 |
printf("%d %*s <- %s\n", curcpu->cpu_id, self->indent, "", probename);
|
|
104 |
self->indent --;
|
|
105 |
}
|
|
106 |
|
|
107 |
:::END
|
|
108 |
{
|
|
109 |
printf("\nEND of %s\n", SAMPLE_NAME);
|
|
110 |
}
|
|
111 |
|
|
112 |
syscall::rexit:entry,
|
|
113 |
syscall::exit:entry
|
|
114 |
/pid == $target/
|
|
115 |
{
|
|
116 |
exit(0);
|
|
117 |
}
|