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