j_calldist.d revision 1.1 1 1.1 christos #!/usr/sbin/dtrace -CZs
2 1.1 christos /*
3 1.1 christos * j_calldist.d - measure Java elapsed times for different types of operation.
4 1.1 christos * Written for the Java hotspot DTrace provider.
5 1.1 christos *
6 1.1 christos * $Id: j_calldist.d,v 1.1 2015/09/30 22:01:06 christos Exp $
7 1.1 christos *
8 1.1 christos * This traces activity from all Java processes on the system with hotspot
9 1.1 christos * provider support (1.6.0). Method calls are only visible when using the
10 1.1 christos * flag "+ExtendedDTraceProbes". eg, java -XX:+ExtendedDTraceProbes classfile
11 1.1 christos *
12 1.1 christos * USAGE: j_calldist.d [top] # hit Ctrl-C to end
13 1.1 christos *
14 1.1 christos * The "top" optional argument will truncate the output for each report
15 1.1 christos * section to that many lines, with a default of 10.
16 1.1 christos *
17 1.1 christos * FIELDS:
18 1.1 christos * 1 Process ID
19 1.1 christos * 2 Type of call (method/gc)
20 1.1 christos * 3 Name of call
21 1.1 christos *
22 1.1 christos * COPYRIGHT: Copyright (c) 2007 Brendan Gregg.
23 1.1 christos *
24 1.1 christos * CDDL HEADER START
25 1.1 christos *
26 1.1 christos * The contents of this file are subject to the terms of the
27 1.1 christos * Common Development and Distribution License, Version 1.0 only
28 1.1 christos * (the "License"). You may not use this file except in compliance
29 1.1 christos * with the License.
30 1.1 christos *
31 1.1 christos * You can obtain a copy of the license at Docs/cddl1.txt
32 1.1 christos * or http://www.opensolaris.org/os/licensing.
33 1.1 christos * See the License for the specific language governing permissions
34 1.1 christos * and limitations under the License.
35 1.1 christos *
36 1.1 christos * CDDL HEADER END
37 1.1 christos *
38 1.1 christos * 09-Sep-2007 Brendan Gregg Created this.
39 1.1 christos */
40 1.1 christos
41 1.1 christos #define TOP 10 /* default output truncation */
42 1.1 christos #define B_FALSE 0
43 1.1 christos
44 1.1 christos #pragma D option quiet
45 1.1 christos #pragma D option defaultargs
46 1.1 christos
47 1.1 christos dtrace:::BEGIN
48 1.1 christos {
49 1.1 christos printf("Tracing... Hit Ctrl-C to end.\n");
50 1.1 christos top = $1 != 0 ? $1 : TOP;
51 1.1 christos }
52 1.1 christos
53 1.1 christos hotspot*:::method-entry
54 1.1 christos {
55 1.1 christos self->depth[arg0]++;
56 1.1 christos self->exclude[arg0, self->depth[arg0]] = 0;
57 1.1 christos self->method[arg0, self->depth[arg0]] = timestamp;
58 1.1 christos }
59 1.1 christos
60 1.1 christos hotspot*:::method-return
61 1.1 christos /self->method[arg0, self->depth[arg0]]/
62 1.1 christos {
63 1.1 christos this->elapsed_incl = timestamp - self->method[arg0, self->depth[arg0]];
64 1.1 christos this->elapsed_excl = this->elapsed_incl -
65 1.1 christos self->exclude[arg0, self->depth[arg0]];
66 1.1 christos self->method[arg0, self->depth[arg0]] = 0;
67 1.1 christos self->exclude[arg0, self->depth[arg0]] = 0;
68 1.1 christos
69 1.1 christos this->class = (char *)copyin(arg1, arg2 + 1);
70 1.1 christos this->class[arg2] = '\0';
71 1.1 christos this->method = (char *)copyin(arg3, arg4 + 1);
72 1.1 christos this->method[arg4] = '\0';
73 1.1 christos this->name = strjoin(strjoin(stringof(this->class), "."),
74 1.1 christos stringof(this->method));
75 1.1 christos
76 1.1 christos @types_incl[pid, "method", this->name] =
77 1.1 christos quantize(this->elapsed_incl / 1000);
78 1.1 christos @types_excl[pid, "method", this->name] =
79 1.1 christos quantize(this->elapsed_excl / 1000);
80 1.1 christos
81 1.1 christos self->depth[arg0]--;
82 1.1 christos self->exclude[arg0, self->depth[arg0]] += this->elapsed_incl;
83 1.1 christos }
84 1.1 christos
85 1.1 christos hotspot*:::gc-begin
86 1.1 christos {
87 1.1 christos self->gc = timestamp;
88 1.1 christos self->full = (boolean_t)arg0;
89 1.1 christos }
90 1.1 christos
91 1.1 christos hotspot*:::gc-end
92 1.1 christos /self->gc/
93 1.1 christos {
94 1.1 christos this->elapsed = timestamp - self->gc;
95 1.1 christos
96 1.1 christos @types[pid, "gc", self->full == B_FALSE ? "GC" : "Full GC"] =
97 1.1 christos quantize(this->elapsed / 1000);
98 1.1 christos
99 1.1 christos self->gc = 0;
100 1.1 christos self->full = 0;
101 1.1 christos }
102 1.1 christos
103 1.1 christos dtrace:::END
104 1.1 christos {
105 1.1 christos trunc(@types, top);
106 1.1 christos printf("\nTop %d elapsed times (us),\n", top);
107 1.1 christos printa(" PID=%d, %s, %s %@d\n", @types);
108 1.1 christos
109 1.1 christos trunc(@types_excl, top);
110 1.1 christos printf("\nTop %d exclusive method elapsed times (us),\n", top);
111 1.1 christos printa(" PID=%d, %s, %s %@d\n", @types_excl);
112 1.1 christos
113 1.1 christos trunc(@types_incl, top);
114 1.1 christos printf("\nTop %d inclusive method elapsed times (us),\n", top);
115 1.1 christos printa(" PID=%d, %s, %s %@d\n", @types_incl);
116 1.1 christos }
117