1#!/usr/sbin/dtrace -s
2/*
3 * cpuwalk.d - Measure which CPUs a process runs on.
4 *             Written using DTrace (Solaris 10 3/05)
5 *
6 * This program is for multi-CPU servers, and can help identify if a process
7 * is running on multiple CPUs concurrently or not.
8 *
9 * 14-Feb-2006, ver 1.00
10 *
11 * USAGE:	cpuwalk.d [duration]
12 *	   eg,
13 *		cpuwalk.d 10		# sample for 10 seconds
14 *		cpuwalk.d		# sample until Ctrl-C is hit
15 *
16 * FIELDS:
17 *		value		CPU id
18 *		count		Number of 1000 hz samples on this CPU
19 *
20 * COPYRIGHT: Copyright (c) 2005 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 * 22-Sep-2005  Brendan Gregg   Created this.
37 */
38
39#pragma D option quiet
40#pragma D option defaultargs
41
42inline int MAXCPUID = 1024;
43
44dtrace:::BEGIN
45{
46	$1 ? printf("Sampling...\n") :
47	    printf("Sampling... Hit Ctrl-C to end.\n");
48	seconds = 0;
49}
50
51profile:::profile-1000hz
52/pid/
53{
54	@sample[pid, execname] = lquantize(cpu, 0, MAXCPUID, 1);
55}
56
57profile:::tick-1sec
58{
59	seconds++;
60}
61
62profile:::tick-1sec
63/seconds == $1/
64{
65	exit(0);
66}
67
68dtrace:::END
69{
70	printa("\n     PID: %-8d CMD: %s\n%@d", @sample);
71}
72