Home | History | Annotate | Line # | Download | only in Java
      1 #!/usr/sbin/dtrace -Zs
      2 /*
      3  * j_syscalls.d - count Java methods and syscalls using DTrace.
      4  *                Written for the Java hotspot DTrace provider.
      5  *
      6  * $Id: j_syscalls.d,v 1.1.1.1 2015/09/30 22:01:09 christos Exp $
      7  *
      8  * This traces Java methods if the hotspot provider exists (1.6.0) and
      9  * the flag "+ExtendedDTraceProbes" is used. eg,
     10  * java -XX:+ExtendedDTraceProbes classfile
     11  *
     12  * USAGE: j_syscalls.d { -p PID | -c cmd }	# hit Ctrl-C to end
     13  *
     14  * FIELDS:
     15  *		PID		Process ID
     16  *		TYPE		Type of call (method/syscall)
     17  *		NAME		Name of call
     18  *		COUNT		Number of calls during sample
     19  *
     20  * COPYRIGHT: Copyright (c) 2007 Brendan Gregg.
     21  *
     22  * CDDL HEADER START
     23  *
     24  *  The contents of this file are subject to the terms of the
     25  *  Common Development and Distribution License, Version 1.0 only
     26  *  (the "License").  You may not use this file except in compliance
     27  *  with the License.
     28  *
     29  *  You can obtain a copy of the license at Docs/cddl1.txt
     30  *  or http://www.opensolaris.org/os/licensing.
     31  *  See the License for the specific language governing permissions
     32  *  and limitations under the License.
     33  *
     34  * CDDL HEADER END
     35  *
     36  * 09-Sep-2007	Brendan Gregg	Created this.
     37  */
     38 
     39 #pragma D option quiet
     40 
     41 dtrace:::BEGIN
     42 {
     43 	printf("Tracing... Hit Ctrl-C to end.\n");
     44 }
     45 
     46 hotspot$target:::method-entry
     47 {
     48 	this->class = (char *)copyin(arg1, arg2 + 1);
     49 	this->class[arg2] = '\0';
     50 	this->method = (char *)copyin(arg3, arg4 + 1);
     51 	this->method[arg4] = '\0';
     52 	this->name = strjoin(strjoin(stringof(this->class), "."),
     53 	    stringof(this->method));
     54 	@calls[pid, "method", this->name] = count();
     55 }
     56 
     57 syscall:::entry
     58 /pid == $target/
     59 {
     60 	@calls[pid, "syscall", probefunc] = count();
     61 }
     62 
     63 
     64 dtrace:::END
     65 {
     66 	printf(" %6s %-8s %-52s %8s\n", "PID", "TYPE", "NAME", "COUNT");
     67 	printa(" %6d %-8s %-52s %@8d\n", @calls);
     68 }
     69