]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - cddl/contrib/dtracetoolkit/Cpu/cpuwalk.d
MFC r368207,368607:
[FreeBSD/stable/10.git] / cddl / contrib / dtracetoolkit / Cpu / cpuwalk.d
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  * $Id: cpuwalk.d 3 2007-08-01 10:50:08Z brendan $
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  * 14-Feb-2006     "      "     Last update.
38  */
39
40 #pragma D option quiet
41 #pragma D option defaultargs
42
43 inline int MAXCPUID = 1024;
44
45 dtrace:::BEGIN
46 {
47         $1 ? printf("Sampling...\n") :
48             printf("Sampling... Hit Ctrl-C to end.\n");
49         seconds = 0;
50 }
51
52 profile:::profile-1000hz
53 /pid/
54 {
55         @sample[pid, execname] = lquantize(cpu, 0, MAXCPUID, 1);
56 }
57
58 profile:::tick-1sec
59 {
60         seconds++;
61 }
62
63 profile:::tick-1sec
64 /seconds == $1/
65 {
66         exit(0);
67 }
68
69 dtrace:::END
70 {
71         printa("\n     PID: %-8d CMD: %s\n%@d", @sample);
72 }