j_calls.d revision 1.1 1 1.1 christos #!/usr/sbin/dtrace -Zs
2 1.1 christos /*
3 1.1 christos * j_calls.d - count Java calls (method/...) using DTrace.
4 1.1 christos * Written for the Java hotspot DTrace provider.
5 1.1 christos *
6 1.1 christos * $Id: j_calls.d,v 1.1 2015/09/30 22:01:09 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 and object allocation are only
10 1.1 christos * visible when using the flag "+ExtendedDTraceProbes". eg,
11 1.1 christos * java -XX:+ExtendedDTraceProbes classfile
12 1.1 christos *
13 1.1 christos * USAGE: j_calls.d # hit Ctrl-C to end
14 1.1 christos *
15 1.1 christos * FIELDS:
16 1.1 christos * PID Process ID
17 1.1 christos * TYPE Type of call (see below)
18 1.1 christos * NAME Name of call
19 1.1 christos * COUNT Number of calls during sample
20 1.1 christos *
21 1.1 christos * TYPEs:
22 1.1 christos * cload class load
23 1.1 christos * method method call
24 1.1 christos * mcompile method compile
25 1.1 christos * mload compiled method load
26 1.1 christos * oalloc object alloc
27 1.1 christos * thread thread start
28 1.1 christos *
29 1.1 christos * COPYRIGHT: Copyright (c) 2007 Brendan Gregg.
30 1.1 christos *
31 1.1 christos * CDDL HEADER START
32 1.1 christos *
33 1.1 christos * The contents of this file are subject to the terms of the
34 1.1 christos * Common Development and Distribution License, Version 1.0 only
35 1.1 christos * (the "License"). You may not use this file except in compliance
36 1.1 christos * with the License.
37 1.1 christos *
38 1.1 christos * You can obtain a copy of the license at Docs/cddl1.txt
39 1.1 christos * or http://www.opensolaris.org/os/licensing.
40 1.1 christos * See the License for the specific language governing permissions
41 1.1 christos * and limitations under the License.
42 1.1 christos *
43 1.1 christos * CDDL HEADER END
44 1.1 christos *
45 1.1 christos * 09-Sep-2007 Brendan Gregg Created this.
46 1.1 christos */
47 1.1 christos
48 1.1 christos #pragma D option quiet
49 1.1 christos
50 1.1 christos dtrace:::BEGIN
51 1.1 christos {
52 1.1 christos printf("Tracing... Hit Ctrl-C to end.\n");
53 1.1 christos }
54 1.1 christos
55 1.1 christos hotspot*:::method-entry
56 1.1 christos {
57 1.1 christos this->class = (char *)copyin(arg1, arg2 + 1);
58 1.1 christos this->class[arg2] = '\0';
59 1.1 christos this->method = (char *)copyin(arg3, arg4 + 1);
60 1.1 christos this->method[arg4] = '\0';
61 1.1 christos this->name = strjoin(strjoin(stringof(this->class), "."),
62 1.1 christos stringof(this->method));
63 1.1 christos @calls[pid, "method", this->name] = count();
64 1.1 christos }
65 1.1 christos
66 1.1 christos hotspot*:::object-alloc
67 1.1 christos {
68 1.1 christos this->class = (char *)copyin(arg1, arg2 + 1);
69 1.1 christos this->class[arg2] = '\0';
70 1.1 christos @calls[pid, "oalloc", stringof(this->class)] = count();
71 1.1 christos }
72 1.1 christos
73 1.1 christos hotspot*:::class-loaded
74 1.1 christos {
75 1.1 christos this->class = (char *)copyin(arg0, arg1 + 1);
76 1.1 christos this->class[arg1] = '\0';
77 1.1 christos @calls[pid, "cload", stringof(this->class)] = count();
78 1.1 christos }
79 1.1 christos
80 1.1 christos hotspot*:::thread-start
81 1.1 christos {
82 1.1 christos this->thread = (char *)copyin(arg0, arg1 + 1);
83 1.1 christos this->thread[arg1] = '\0';
84 1.1 christos @calls[pid, "thread", stringof(this->thread)] = count();
85 1.1 christos }
86 1.1 christos
87 1.1 christos hotspot*:::method-compile-begin
88 1.1 christos {
89 1.1 christos this->class = (char *)copyin(arg0, arg1 + 1);
90 1.1 christos this->class[arg1] = '\0';
91 1.1 christos this->method = (char *)copyin(arg2, arg3 + 1);
92 1.1 christos this->method[arg3] = '\0';
93 1.1 christos this->name = strjoin(strjoin(stringof(this->class), "."),
94 1.1 christos stringof(this->method));
95 1.1 christos @calls[pid, "mcompile", this->name] = count();
96 1.1 christos }
97 1.1 christos
98 1.1 christos hotspot*:::compiled-method-load
99 1.1 christos {
100 1.1 christos this->class = (char *)copyin(arg0, arg1 + 1);
101 1.1 christos this->class[arg1] = '\0';
102 1.1 christos this->method = (char *)copyin(arg2, arg3 + 1);
103 1.1 christos this->method[arg3] = '\0';
104 1.1 christos this->name = strjoin(strjoin(stringof(this->class), "."),
105 1.1 christos stringof(this->method));
106 1.1 christos @calls[pid, "mload", this->name] = count();
107 1.1 christos }
108 1.1 christos
109 1.1 christos dtrace:::END
110 1.1 christos {
111 1.1 christos printf(" %6s %-8s %-52s %8s\n", "PID", "TYPE", "NAME", "COUNT");
112 1.1 christos printa(" %6d %-8s %-52s %@8d\n", @calls);
113 1.1 christos }
114