138032Speter#!/usr/sbin/dtrace -Zs 2261363Sgshapiro/* 390792Sgshapiro * j_syscalls.d - count Java methods and syscalls using DTrace. 490792Sgshapiro * Written for the Java hotspot DTrace provider. 590792Sgshapiro * 690792Sgshapiro * $Id: j_syscalls.d 19 2007-09-12 07:47:59Z brendan $ 790792Sgshapiro * 890792Sgshapiro * This traces Java methods if the hotspot provider exists (1.6.0) and 990792Sgshapiro * the flag "+ExtendedDTraceProbes" is used. eg, 1090792Sgshapiro * java -XX:+ExtendedDTraceProbes classfile 1190792Sgshapiro * 1238032Speter * USAGE: j_syscalls.d { -p PID | -c cmd } # hit Ctrl-C to end 1338032Speter * 1438032Speter * FIELDS: 1538032Speter * PID Process ID 1638032Speter * TYPE Type of call (method/syscall) 1738032Speter * NAME Name of call 1864562Sgshapiro * COUNT Number of calls during sample 1938032Speter * 2038032Speter * COPYRIGHT: Copyright (c) 2007 Brendan Gregg. 2164562Sgshapiro * 2264562Sgshapiro * CDDL HEADER START 2364562Sgshapiro * 2464562Sgshapiro * The contents of this file are subject to the terms of the 2564562Sgshapiro * Common Development and Distribution License, Version 1.0 only 2638032Speter * (the "License"). You may not use this file except in compliance 2738032Speter * with the License. 2864562Sgshapiro * 29261363Sgshapiro * You can obtain a copy of the license at Docs/cddl1.txt 3064562Sgshapiro * or http://www.opensolaris.org/os/licensing. 3164562Sgshapiro * See the License for the specific language governing permissions 3264562Sgshapiro * and limitations under the License. 3364562Sgshapiro * 3464562Sgshapiro * CDDL HEADER END 3564562Sgshapiro * 3638032Speter * 09-Sep-2007 Brendan Gregg Created this. 3738032Speter */ 3838032Speter 3938032Speter#pragma D option quiet 4038032Speter 4138032Speterdtrace:::BEGIN 4238032Speter{ 4338032Speter printf("Tracing... Hit Ctrl-C to end.\n"); 4438032Speter} 4538032Speter 4638032Speterhotspot$target:::method-entry 4738032Speter{ 4838032Speter this->class = (char *)copyin(arg1, arg2 + 1); 4938032Speter this->class[arg2] = '\0'; 5038032Speter this->method = (char *)copyin(arg3, arg4 + 1); 5138032Speter this->method[arg4] = '\0'; 5238032Speter this->name = strjoin(strjoin(stringof(this->class), "."), 5338032Speter stringof(this->method)); 5438032Speter @calls[pid, "method", this->name] = count(); 5538032Speter} 5638032Speter 5738032Spetersyscall:::entry 5838032Speter/pid == $target/ 5938032Speter{ 6038032Speter @calls[pid, "syscall", probefunc] = count(); 6138032Speter} 6238032Speter 6338032Speter 6438032Speterdtrace:::END 6538032Speter{ 6638032Speter printf(" %6s %-8s %-52s %8s\n", "PID", "TYPE", "NAME", "COUNT"); 6738032Speter printa(" %6d %-8s %-52s %@8d\n", @calls); 6838032Speter} 6938032Speter