1#!/usr/sbin/dtrace -s
2/*
3 * threaded.d - sample multi-threaded CPU usage.
4 *              Written using DTrace (Solaris 10 3/05).
5 *
6 * This measures thread IDs as a process runs across multiple CPUs.
7 * It is a simple script that can help determine if a multi-threaded
8 * application is effectively using it's threads, or if the threads have
9 * serialised. See the example file in Docs/Examples/threaded_example.txt
10 * for a demonstration.
11 *
12 * $Id: threaded.d 3 2007-08-01 10:50:08Z brendan $
13 *
14 * USAGE:	threaded.d
15 *
16 * FIELDS:
17 *		PID		process ID
18 *		CMD		process name
19 *		value		thread ID
20 *		count		number of samples
21 *
22 * SEE ALSO:	prstat -L
23 *
24 * COPYRIGHT: Copyright (c) 2005 Brendan Gregg.
25 *
26 * CDDL HEADER START
27 *
28 *  The contents of this file are subject to the terms of the
29 *  Common Development and Distribution License, Version 1.0 only
30 *  (the "License").  You may not use this file except in compliance
31 *  with the License.
32 *
33 *  You can obtain a copy of the license at Docs/cddl1.txt
34 *  or http://www.opensolaris.org/os/licensing.
35 *  See the License for the specific language governing permissions
36 *  and limitations under the License.
37 *
38 * CDDL HEADER END
39 *
40 * Author: Brendan Gregg  [Sydney, Australia]
41 *
42 * 25-Jul-2005	Brendan Gregg	Created this.
43 * 25-Jul-2005	   "      "	Last update.
44 */
45
46#pragma D option quiet
47
48/*
49 * Sample at 100 Hertz
50 */
51profile:::profile-100
52/pid != 0/
53{
54	@sample[pid, execname] = lquantize(tid, 0, 128, 1);
55}
56
57/*
58 * Print output every 1 second
59 */
60profile:::tick-1sec
61{
62	printf("%Y,\n", walltimestamp);
63	printa("\n     PID: %-8d CMD: %s\n%@d", @sample);
64	printf("\n");
65	trunc(@sample);
66}
67