1 #!/usr/sbin/dtrace -CZs
3 * j_calltime.d - measure Java elapsed times for different types of operation.
4 * Written for the Java hotspot DTrace provider.
6 * $Id: j_calltime.d 59 2007-10-03 08:21:58Z brendan $
8 * This traces activity from all Java processes on the system with hotspot
9 * provider support (1.6.0). Method calls are only visible when using the
10 * flag "+ExtendedDTraceProbes". eg, java -XX:+ExtendedDTraceProbes classfile
12 * USAGE: j_calltime.d [top] # hit Ctrl-C to end
14 * The "top" optional argument will truncate the output for each report
15 * section to that many lines, with a default of 10.
19 * TYPE Type of call (method/gc/total)
21 * TOTAL Total elapsed time for calls (us)
23 * COPYRIGHT: Copyright (c) 2007 Brendan Gregg.
27 * The contents of this file are subject to the terms of the
28 * Common Development and Distribution License, Version 1.0 only
29 * (the "License"). You may not use this file except in compliance
32 * You can obtain a copy of the license at Docs/cddl1.txt
33 * or http://www.opensolaris.org/os/licensing.
34 * See the License for the specific language governing permissions
35 * and limitations under the License.
39 * 09-Sep-2007 Brendan Gregg Created this.
42 #define TOP 10 /* default output truncation */
45 #pragma D option quiet
46 #pragma D option defaultargs
50 printf("Tracing... Hit Ctrl-C to end.\n");
51 top = $1 != 0 ? $1 : TOP;
54 hotspot*:::method-entry
57 self->exclude[arg0, self->depth[arg0]] = 0;
58 self->method[arg0, self->depth[arg0]] = timestamp;
61 hotspot*:::method-return
62 /self->method[arg0, self->depth[arg0]]/
64 this->elapsed_incl = timestamp - self->method[arg0, self->depth[arg0]];
65 this->elapsed_excl = this->elapsed_incl -
66 self->exclude[arg0, self->depth[arg0]];
67 self->method[arg0, self->depth[arg0]] = 0;
68 self->exclude[arg0, self->depth[arg0]] = 0;
70 this->class = (char *)copyin(arg1, arg2 + 1);
71 this->class[arg2] = '\0';
72 this->method = (char *)copyin(arg3, arg4 + 1);
73 this->method[arg4] = '\0';
74 this->name = strjoin(strjoin(stringof(this->class), "."),
75 stringof(this->method));
77 @num[pid, "method", this->name] = count();
78 @num[0, "total", "-"] = count();
79 @types_incl[pid, "method", this->name] = sum(this->elapsed_incl);
80 @types_excl[pid, "method", this->name] = sum(this->elapsed_excl);
81 @types_excl[0, "total", "-"] = sum(this->elapsed_excl);
84 self->exclude[arg0, self->depth[arg0]] += this->elapsed_incl;
90 self->full = (boolean_t)arg0;
96 this->elapsed = timestamp - self->gc;
99 @num[pid, "gc", self->full == B_FALSE ? "GC" : "Full GC"] = count();
100 @types[pid, "gc", self->full == B_FALSE ? "GC" : "Full GC"] =
108 printf("\nTop %d counts,\n", top);
109 printf(" %6s %-10s %-48s %8s\n", "PID", "TYPE", "NAME", "COUNT");
110 printa(" %6d %-10s %-48s %@8d\n", @num);
113 normalize(@types, 1000);
114 printf("\nTop %d elapsed times (us),\n", top);
115 printf(" %6s %-10s %-48s %8s\n", "PID", "TYPE", "NAME", "TOTAL");
116 printa(" %6d %-10s %-48s %@8d\n", @types);
118 trunc(@types_excl, top);
119 normalize(@types_excl, 1000);
120 printf("\nTop %d exclusive method elapsed times (us),\n", top);
121 printf(" %6s %-10s %-48s %8s\n", "PID", "TYPE", "NAME", "TOTAL");
122 printa(" %6d %-10s %-48s %@8d\n", @types_excl);
124 trunc(@types_incl, top);
125 normalize(@types_incl, 1000);
126 printf("\nTop %d inclusive method elapsed times (us),\n", top);
127 printf(" %6s %-10s %-48s %8s\n", "PID", "TYPE", "NAME", "TOTAL");
128 printa(" %6d %-10s %-48s %@8d\n", @types_incl);