1235368Sgnn#!/usr/sbin/dtrace -Zs 2235368Sgnn/* 3235368Sgnn * j_objnew.d - report Java object allocation using DTrace. 4235368Sgnn * Written for the Java hotspot DTrace provider. 5235368Sgnn * 6235368Sgnn * $Id: j_objnew.d 19 2007-09-12 07:47:59Z brendan $ 7235368Sgnn * 8235368Sgnn * This traces activity from all Java processes on the system with hotspot 9235368Sgnn * provider support (1.6.0) and the flag "+ExtendedDTraceProbes". eg, 10235368Sgnn * java -XX:+ExtendedDTraceProbes classfile 11235368Sgnn * 12235368Sgnn * USAGE: j_objnew.d # hit Ctrl-C to end 13235368Sgnn * 14235368Sgnn * FIELDS: 15235368Sgnn * PID Process ID 16235368Sgnn * OBJS Number of objects created 17235368Sgnn * CLASS.METHOD Java class and method name 18235368Sgnn * 19235368Sgnn * COPYRIGHT: Copyright (c) 2007 Brendan Gregg. 20235368Sgnn * 21235368Sgnn * CDDL HEADER START 22235368Sgnn * 23235368Sgnn * The contents of this file are subject to the terms of the 24235368Sgnn * Common Development and Distribution License, Version 1.0 only 25235368Sgnn * (the "License"). You may not use this file except in compliance 26235368Sgnn * with the License. 27235368Sgnn * 28235368Sgnn * You can obtain a copy of the license at Docs/cddl1.txt 29235368Sgnn * or http://www.opensolaris.org/os/licensing. 30235368Sgnn * See the License for the specific language governing permissions 31235368Sgnn * and limitations under the License. 32235368Sgnn * 33235368Sgnn * CDDL HEADER END 34235368Sgnn * 35235368Sgnn * 09-Sep-2007 Brendan Gregg Created this. 36235368Sgnn */ 37235368Sgnn 38235368Sgnn#pragma D option quiet 39235368Sgnn 40235368Sgnndtrace:::BEGIN 41235368Sgnn{ 42235368Sgnn printf("Tracing... Hit Ctrl-C to end.\n"); 43235368Sgnn} 44235368Sgnn 45235368Sgnnhotspot*:::object-alloc 46235368Sgnn{ 47235368Sgnn this->class = (char *)copyin(arg1, arg2 + 1); 48235368Sgnn this->class[arg2] = '\0'; 49235368Sgnn @objs[pid, stringof(this->class)] = count(); 50235368Sgnn @dist[pid, stringof(this->class)] = quantize(arg3); 51235368Sgnn} 52235368Sgnn 53235368Sgnndtrace:::END 54235368Sgnn{ 55235368Sgnn printf("Java object allocation byte distributions by pid and class,\n"); 56235368Sgnn printa(@dist); 57235368Sgnn 58235368Sgnn printf("Java object allocation count by pid and class,\n\n"); 59235368Sgnn printf(" %6s %8s %s\n", "PID", "OBJS", "CLASS"); 60235368Sgnn printa(" %6d %8@d %s\n", @objs); 61235368Sgnn} 62