3 * j_flowtime.d - snoop Java execution with method flow and delta times.
4 * Written for the Java hotspot DTrace provider.
6 * $Id: j_flowtime.d 41 2007-09-17 02:20:10Z brendan $
8 * This traces activity from all Java processes on the system with hotspot
9 * provider support (1.6.0) and the flag "+ExtendedDTraceProbes". eg,
10 * java -XX:+ExtendedDTraceProbes classfile
12 * USAGE: j_flowtime.d # hit Ctrl-C to end
14 * This watches Java method entries and returns, and indents child
21 * TIME(us) Time since boot (us)
22 * DELTA(us) Elapsed time from previous line to this line
23 * CLASS.METHOD Java class and method name
29 * WARNING: Watch the first column carefully, it prints the CPU-id. If it
30 * changes, then it is very likely that the output has been shuffled.
31 * Changes in TID will appear to shuffle output, as we change from one thread
32 * depth to the next. See Docs/Notes/ALLjavaflow.txt for additional notes.
34 * COPYRIGHT: Copyright (c) 2007 Brendan Gregg.
38 * The contents of this file are subject to the terms of the
39 * Common Development and Distribution License, Version 1.0 only
40 * (the "License"). You may not use this file except in compliance
43 * You can obtain a copy of the license at Docs/cddl1.txt
44 * or http://www.opensolaris.org/os/licensing.
45 * See the License for the specific language governing permissions
46 * and limitations under the License.
50 * 09-Sep-2007 Brendan Gregg Created this.
53 /* increasing bufsize can reduce drops */
54 #pragma D option bufsize=16m
55 #pragma D option quiet
56 #pragma D option switchrate=10
62 printf("%3s %6s/%-5s %-16s %9s -- %s\n", "C", "PID", "TID", "TIME(us)",
63 "DELTA(us)", "CLASS.METHOD");
66 hotspot*:::method-entry,
67 hotspot*:::method-return
70 self->last = timestamp;
73 hotspot*:::method-entry
75 this->delta = (timestamp - self->last) / 1000;
76 this->class = (char *)copyin(arg1, arg2 + 1);
77 this->class[arg2] = '\0';
78 this->method = (char *)copyin(arg3, arg4 + 1);
79 this->method[arg4] = '\0';
81 printf("%3d %6d/%-5d %-16d %9d %*s-> %s.%s\n", cpu, pid, tid,
82 timestamp / 1000, this->delta, self->depth[arg0] * 2, "",
83 stringof(this->class), stringof(this->method));
85 self->last = timestamp;
88 hotspot*:::method-return
90 this->delta = (timestamp - self->last) / 1000;
91 this->class = (char *)copyin(arg1, arg2 + 1);
92 this->class[arg2] = '\0';
93 this->method = (char *)copyin(arg3, arg4 + 1);
94 this->method[arg4] = '\0';
96 self->depth[arg0] -= self->depth[arg0] > 0 ? 1 : 0;
97 printf("%3d %6d/%-5d %-16d %9d %*s<- %s.%s\n", cpu, pid, tid,
98 timestamp / 1000, this->delta, self->depth[arg0] * 2, "",
99 stringof(this->class), stringof(this->method));
100 self->last = timestamp;