3 * j_syscolors.d - trace Java method flow plus syscalls, in color.
4 * Written for the Java hotspot DTrace provider.
6 * $Id: j_syscolors.d 58 2007-10-01 13:36:29Z brendan $
8 * This traces Java methods if the hotspot provider exists (1.6.0) and
9 * the flag "+ExtendedDTraceProbes" is used. eg,
10 * java -XX:+ExtendedDTraceProbes classfile
12 * USAGE: j_syscolors.d { -p PID | -c cmd } # hit Ctrl-C to end
14 * This watches Java method entries and returns, and indents child
21 * DELTA(us) Elapsed time from previous line to this line
22 * TYPE Type of call (func/syscall)
23 * NAME Java method or syscall name
25 * If the flow appears to jump, check the TID column - the JVM may have
26 * switched to another thread.
28 * WARNING: Watch the first column carefully, it prints the CPU-id. If it
29 * changes, then it is very likely that the output has been shuffled.
30 * Changes in TID will appear to shuffle output, as we change from one thread
31 * depth to the next. See Docs/Notes/ALLjavaflow.txt for additional notes.
33 * COPYRIGHT: Copyright (c) 2007 Brendan Gregg.
37 * The contents of this file are subject to the terms of the
38 * Common Development and Distribution License, Version 1.0 only
39 * (the "License"). You may not use this file except in compliance
42 * You can obtain a copy of the license at Docs/cddl1.txt
43 * or http://www.opensolaris.org/os/licensing.
44 * See the License for the specific language governing permissions
45 * and limitations under the License.
49 * 09-Sep-2007 Brendan Gregg Created this.
52 /* increasing bufsize can reduce drops */
53 #pragma D option bufsize=32m
54 #pragma D option quiet
55 #pragma D option switchrate=10
61 color_java = "\033[2;35m"; /* violet, faint */
62 color_line = "\033[1;35m"; /* violet, bold */
63 color_syscall = "\033[2;32m"; /* green, faint */
64 color_off = "\033[0m"; /* default */
66 printf("%3s %6s/%-5s %9s %-8s -- %s\n", "C", "PID", "TID", "DELTA(us)",
70 hotspot$target:::method-entry,
71 hotspot$target:::method-return,
74 /self->last == 0 && pid == $target/
76 self->last = timestamp;
79 hotspot$target:::method-entry
81 this->delta = (timestamp - self->last) / 1000;
82 this->class = (char *)copyin(arg1, arg2 + 1);
83 this->class[arg2] = '\0';
84 this->method = (char *)copyin(arg3, arg4 + 1);
85 this->method[arg4] = '\0';
87 printf("%s%3d %6d/%-5d %9d %-8s %*s-> %s.%s%s\n", color_java, cpu,
88 pid, tid, this->delta, "method", self->depth[arg0] * 2, "",
89 stringof(this->class), stringof(this->method), color_off);
91 self->depthlast = self->depth[arg0];
92 self->last = timestamp;
95 hotspot$target:::method-return
97 this->delta = (timestamp - self->last) / 1000;
98 this->class = (char *)copyin(arg1, arg2 + 1);
99 this->class[arg2] = '\0';
100 this->method = (char *)copyin(arg3, arg4 + 1);
101 this->method[arg4] = '\0';
103 self->depth[arg0] -= self->depth[arg0] > 0 ? 1 : 0;
104 printf("%s%3d %6d/%-5d %9d %-8s %*s<- %s.%s%s\n", color_java, cpu,
105 pid, tid, this->delta, "method", self->depth[arg0] * 2, "",
106 stringof(this->class), stringof(this->method), color_off);
107 self->depthlast = self->depth[arg0];
108 self->last = timestamp;
114 this->delta = (timestamp - self->last) / 1000;
115 printf("%s%3d %6d/%-5d %9d %-8s %*s-> %s%s\n", color_syscall,
116 cpu, pid, tid, this->delta, "syscall", self->depthlast * 2, "",
117 probefunc, color_off);
118 self->last = timestamp;
124 this->delta = (timestamp - self->last) / 1000;
125 printf("%s%3d %6d/%-5d %9d %-8s %*s<- %s%s\n", color_syscall,
126 cpu, pid, tid, this->delta, "syscall", self->depthlast * 2, "",
127 probefunc, color_off);
128 self->last = timestamp;