1*e137d3e0Schristos #!/usr/sbin/dtrace -Zs
2*e137d3e0Schristos /*
3*e137d3e0Schristos  * j_thread.d - snoop Java thread execution using DTrace.
4*e137d3e0Schristos                 Written for the Java hotspot DTrace provider.
5*e137d3e0Schristos  *
6*e137d3e0Schristos  * $Id: j_thread.d,v 1.1.1.1 2015/09/30 22:01:09 christos Exp $
7*e137d3e0Schristos  *
8*e137d3e0Schristos  * This traces activity from all Java processes on the system with hotspot
9*e137d3e0Schristos  * provider support (1.6.0).
10*e137d3e0Schristos  *
11*e137d3e0Schristos  * USAGE: j_thread.d 		# hit Ctrl-C to end
12*e137d3e0Schristos  *
13*e137d3e0Schristos  * FIELDS:
14*e137d3e0Schristos  *		TIME		Time string
15*e137d3e0Schristos  *		PID		Process ID
16*e137d3e0Schristos  *		TID		Thread ID
17*e137d3e0Schristos  *		THREAD		Thread name
18*e137d3e0Schristos  *
19*e137d3e0Schristos  * LEGEND:
20*e137d3e0Schristos  *		=>		thread start
21*e137d3e0Schristos  *		<=		thread end
22*e137d3e0Schristos  *
23*e137d3e0Schristos  * COPYRIGHT: Copyright (c) 2007 Brendan Gregg.
24*e137d3e0Schristos  *
25*e137d3e0Schristos  * CDDL HEADER START
26*e137d3e0Schristos  *
27*e137d3e0Schristos  *  The contents of this file are subject to the terms of the
28*e137d3e0Schristos  *  Common Development and Distribution License, Version 1.0 only
29*e137d3e0Schristos  *  (the "License").  You may not use this file except in compliance
30*e137d3e0Schristos  *  with the License.
31*e137d3e0Schristos  *
32*e137d3e0Schristos  *  You can obtain a copy of the license at Docs/cddl1.txt
33*e137d3e0Schristos  *  or http://www.opensolaris.org/os/licensing.
34*e137d3e0Schristos  *  See the License for the specific language governing permissions
35*e137d3e0Schristos  *  and limitations under the License.
36*e137d3e0Schristos  *
37*e137d3e0Schristos  * CDDL HEADER END
38*e137d3e0Schristos  *
39*e137d3e0Schristos  * 09-Sep-2007	Brendan Gregg	Created this.
40*e137d3e0Schristos  */
41*e137d3e0Schristos 
42*e137d3e0Schristos #pragma D option quiet
43*e137d3e0Schristos #pragma D option switchrate=10
44*e137d3e0Schristos 
45*e137d3e0Schristos dtrace:::BEGIN
46*e137d3e0Schristos {
47*e137d3e0Schristos 	printf("%-20s  %6s/%-5s -- %s\n", "TIME", "PID", "TID", "THREAD");
48*e137d3e0Schristos }
49*e137d3e0Schristos 
50*e137d3e0Schristos hotspot*:::thread-start
51*e137d3e0Schristos {
52*e137d3e0Schristos 	this->thread = (char *)copyin(arg0, arg1 + 1);
53*e137d3e0Schristos 	this->thread[arg1] = '\0';
54*e137d3e0Schristos 	printf("%-20Y  %6d/%-5d => %s\n", walltimestamp, pid, tid,
55*e137d3e0Schristos 	    stringof(this->thread));
56*e137d3e0Schristos }
57*e137d3e0Schristos 
58*e137d3e0Schristos hotspot*:::thread-stop
59*e137d3e0Schristos {
60*e137d3e0Schristos 	this->thread = (char *)copyin(arg0, arg1 + 1);
61*e137d3e0Schristos 	this->thread[arg1] = '\0';
62*e137d3e0Schristos 	printf("%-20Y  %6d/%-5d <= %s\n", walltimestamp, pid, tid,
63*e137d3e0Schristos 	    stringof(this->thread));
64*e137d3e0Schristos }
65