1N/A#!/usr/sbin/dtrace -CZs
1N/A/*
1N/A * j_cputime.d - measure Java on-CPU times for different types of operation.
1N/A * Written for the Java hotspot DTrace provider.
1N/A *
1N/A * $Id: j_cputime.d 59 2007-10-03 08:21:58Z brendan $
1N/A *
1N/A * This traces activity from all Java processes on the system with hotspot
1N/A * provider support (1.6.0). Method calls are only visible when using the
1N/A * flag "+ExtendedDTraceProbes". eg, java -XX:+ExtendedDTraceProbes classfile
1N/A *
1N/A * USAGE: j_cputime.d [top] # hit Ctrl-C to end
1N/A *
1N/A * The "top" optional argument will truncate the output for each report
1N/A * section to that many lines, with a default of 10.
1N/A *
1N/A * FIELDS:
1N/A * PID Process ID
1N/A * TYPE Type of call (method/gc/total)
1N/A * NAME Name of call
1N/A * TOTAL Total on-CPU time for calls (us)
1N/A *
1N/A * COPYRIGHT: Copyright (c) 2007 Brendan Gregg.
1N/A *
1N/A * CDDL HEADER START
1N/A *
1N/A * The contents of this file are subject to the terms of the
1N/A * Common Development and Distribution License, Version 1.0 only
1N/A * (the "License"). You may not use this file except in compliance
1N/A * with the License.
1N/A *
1N/A * You can obtain a copy of the license at Docs/cddl1.txt
1N/A * or http://www.opensolaris.org/os/licensing.
1N/A * See the License for the specific language governing permissions
1N/A * and limitations under the License.
1N/A *
1N/A * CDDL HEADER END
1N/A *
1N/A * 09-Sep-2007 Brendan Gregg Created this.
1N/A */
1N/A
1N/A#define TOP 10 /* default output truncation */
1N/A#define B_FALSE 0
1N/A
1N/A#pragma D option quiet
1N/A#pragma D option defaultargs
1N/A
1N/Adtrace:::BEGIN
1N/A{
1N/A printf("Tracing... Hit Ctrl-C to end.\n");
1N/A top = $1 != 0 ? $1 : TOP;
1N/A}
1N/A
1N/Ahotspot*:::method-entry
1N/A{
1N/A self->depth[arg0]++;
1N/A self->exclude[arg0, self->depth[arg0]] = 0;
1N/A self->method[arg0, self->depth[arg0]] = vtimestamp;
1N/A}
1N/A
1N/Ahotspot*:::method-return
1N/A/self->method[arg0, self->depth[arg0]]/
1N/A{
1N/A this->oncpu_incl = vtimestamp - self->method[arg0, self->depth[arg0]];
1N/A this->oncpu_excl = this->oncpu_incl -
1N/A self->exclude[arg0, self->depth[arg0]];
1N/A self->method[arg0, self->depth[arg0]] = 0;
1N/A self->exclude[arg0, self->depth[arg0]] = 0;
1N/A
1N/A this->class = (char *)copyin(arg1, arg2 + 1);
1N/A this->class[arg2] = '\0';
1N/A this->method = (char *)copyin(arg3, arg4 + 1);
1N/A this->method[arg4] = '\0';
1N/A this->name = strjoin(strjoin(stringof(this->class), "."),
1N/A stringof(this->method));
1N/A
1N/A @num[pid, "method", this->name] = count();
1N/A @num[0, "total", "-"] = count();
1N/A @types_incl[pid, "method", this->name] = sum(this->oncpu_incl);
1N/A @types_excl[pid, "method", this->name] = sum(this->oncpu_excl);
1N/A @types_excl[0, "total", "-"] = sum(this->oncpu_excl);
1N/A
1N/A self->depth[arg0]--;
1N/A self->exclude[arg0, self->depth[arg0]] += this->oncpu_incl;
1N/A}
1N/A
1N/Ahotspot*:::gc-begin
1N/A{
1N/A self->gc = vtimestamp;
1N/A self->full = (boolean_t)arg0;
1N/A}
1N/A
1N/Ahotspot*:::gc-end
1N/A/self->gc/
1N/A{
1N/A this->oncpu = vtimestamp - self->gc;
1N/A self->gc = 0;
1N/A
1N/A @num[pid, "gc", self->full == B_FALSE ? "GC" : "Full GC"] = count();
1N/A @types[pid, "gc", self->full == B_FALSE ? "GC" : "Full GC"] =
1N/A sum(this->oncpu);
1N/A self->full = 0;
1N/A}
1N/A
1N/Adtrace:::END
1N/A{
1N/A trunc(@num, top);
1N/A printf("\nTop %d counts,\n", top);
1N/A printf(" %6s %-10s %-48s %8s\n", "PID", "TYPE", "NAME", "COUNT");
1N/A printa(" %6d %-10s %-48s %@8d\n", @num);
1N/A
1N/A trunc(@types, top);
1N/A normalize(@types, 1000);
1N/A printf("\nTop %d on-CPU times (us),\n", top);
1N/A printf(" %6s %-10s %-48s %8s\n", "PID", "TYPE", "NAME", "TOTAL");
1N/A printa(" %6d %-10s %-48s %@8d\n", @types);
1N/A
1N/A trunc(@types_excl, top);
1N/A normalize(@types_excl, 1000);
1N/A printf("\nTop %d exclusive method on-CPU times (us),\n", top);
1N/A printf(" %6s %-10s %-48s %8s\n", "PID", "TYPE", "NAME", "TOTAL");
1N/A printa(" %6d %-10s %-48s %@8d\n", @types_excl);
1N/A
1N/A trunc(@types_incl, top);
1N/A normalize(@types_incl, 1000);
1N/A printf("\nTop %d inclusive method on-CPU times (us),\n", top);
1N/A printf(" %6s %-10s %-48s %8s\n", "PID", "TYPE", "NAME", "TOTAL");
1N/A printa(" %6d %-10s %-48s %@8d\n", @types_incl);
1N/A}