1235368Sgnn#!/usr/sbin/dtrace -Zs
2235368Sgnn/*
3235368Sgnn * j_thread.d - snoop Java thread execution using DTrace.
4235368Sgnn                Written for the Java hotspot DTrace provider.
5235368Sgnn *
6235368Sgnn * $Id: j_thread.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).
10235368Sgnn *
11235368Sgnn * USAGE: j_thread.d 		# hit Ctrl-C to end
12235368Sgnn *
13235368Sgnn * FIELDS:
14235368Sgnn *		TIME		Time string
15235368Sgnn *		PID		Process ID
16235368Sgnn *		TID		Thread ID
17235368Sgnn *		THREAD		Thread name
18235368Sgnn *
19235368Sgnn * LEGEND:
20235368Sgnn *		=>		thread start
21235368Sgnn *		<=		thread end
22235368Sgnn *
23235368Sgnn * COPYRIGHT: Copyright (c) 2007 Brendan Gregg.
24235368Sgnn *
25235368Sgnn * CDDL HEADER START
26235368Sgnn *
27235368Sgnn *  The contents of this file are subject to the terms of the
28235368Sgnn *  Common Development and Distribution License, Version 1.0 only
29235368Sgnn *  (the "License").  You may not use this file except in compliance
30235368Sgnn *  with the License.
31235368Sgnn *
32235368Sgnn *  You can obtain a copy of the license at Docs/cddl1.txt
33235368Sgnn *  or http://www.opensolaris.org/os/licensing.
34235368Sgnn *  See the License for the specific language governing permissions
35235368Sgnn *  and limitations under the License.
36235368Sgnn *
37235368Sgnn * CDDL HEADER END
38235368Sgnn *
39235368Sgnn * 09-Sep-2007	Brendan Gregg	Created this.
40235368Sgnn */
41235368Sgnn
42235368Sgnn#pragma D option quiet
43235368Sgnn#pragma D option switchrate=10
44235368Sgnn
45235368Sgnndtrace:::BEGIN
46235368Sgnn{
47235368Sgnn	printf("%-20s  %6s/%-5s -- %s\n", "TIME", "PID", "TID", "THREAD");
48235368Sgnn}
49235368Sgnn
50235368Sgnnhotspot*:::thread-start
51235368Sgnn{
52235368Sgnn	this->thread = (char *)copyin(arg0, arg1 + 1);
53235368Sgnn	this->thread[arg1] = '\0';
54235368Sgnn	printf("%-20Y  %6d/%-5d => %s\n", walltimestamp, pid, tid,
55235368Sgnn	    stringof(this->thread));
56235368Sgnn}
57235368Sgnn
58235368Sgnnhotspot*:::thread-stop
59235368Sgnn{
60235368Sgnn	this->thread = (char *)copyin(arg0, arg1 + 1);
61235368Sgnn	this->thread[arg1] = '\0';
62235368Sgnn	printf("%-20Y  %6d/%-5d <= %s\n", walltimestamp, pid, tid,
63235368Sgnn	    stringof(this->thread));
64235368Sgnn}
65