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