1235368Sgnn#!/usr/sbin/dtrace -Zs 2235368Sgnn/* 3235368Sgnn * j_methodcalls.d - count Java method calls DTrace. 4235368Sgnn * Written for the Java hotspot DTrace provider. 5235368Sgnn * 6235368Sgnn * $Id: j_methodcalls.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_methodcalls.d # hit Ctrl-C to end 13235368Sgnn * 14235368Sgnn * FIELDS: 15235368Sgnn * PID Process ID 16235368Sgnn * COUNT Number of calls during sample 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*:::method-entry 46235368Sgnn{ 47235368Sgnn this->class = (char *)copyin(arg1, arg2 + 1); 48235368Sgnn this->class[arg2] = '\0'; 49235368Sgnn this->method = (char *)copyin(arg3, arg4 + 1); 50235368Sgnn this->method[arg4] = '\0'; 51235368Sgnn this->name = strjoin(strjoin(stringof(this->class), "."), 52235368Sgnn stringof(this->method)); 53235368Sgnn @calls[pid, this->name] = count(); 54235368Sgnn} 55235368Sgnn 56235368Sgnndtrace:::END 57235368Sgnn{ 58235368Sgnn printf(" %6s %8s %s\n", "PID", "COUNT", "CLASS.METHOD"); 59235368Sgnn printa(" %6d %@8d %s\n", @calls); 60235368Sgnn} 61