]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - cddl/contrib/dtracetoolkit/Mem/anonpgpid.d
Copy head (r256279) to stable/10 as part of the 10.0-RELEASE cycle.
[FreeBSD/stable/10.git] / cddl / contrib / dtracetoolkit / Mem / anonpgpid.d
1 #!/usr/sbin/dtrace -Cs
2 /*
3  * anonpgpid.d - anonymous memory paging info by process on CPU.
4  *               Written using DTrace (Solaris 10 3/05).
5  *
6  * This scripts may help identify which processes are affected by a system
7  * with low memory, which is paging to the physical swap device. A report
8  * of the process on the CPU when paging occured is printed.
9  *
10  * $Id: anonpgpid.d 8 2007-08-06 05:55:26Z brendan $
11  *
12  * USAGE:       anonpgpid.d     # hit Ctrl-C to end
13  *
14  * FIELDS:
15  *              PID             Process ID
16  *              CMD             Process name
17  *              D               Direction, Read or Write
18  *              BYTES           Total bytes during sample
19  *
20  * NOTES:
21  *
22  * This program is currently an approximation - often the process when writing
23  * pages to swap will be "pageout" the pageout scanner, or "rcapd" the
24  * resource capping daemon.
25  *
26  * THANKS: James Dickens
27  *
28  * COPYRIGHT: Copyright (c) 2006 Brendan Gregg.
29  *
30  * CDDL HEADER START
31  *
32  *  The contents of this file are subject to the terms of the
33  *  Common Development and Distribution License, Version 1.0 only
34  *  (the "License").  You may not use this file except in compliance
35  *  with the License.
36  *
37  *  You can obtain a copy of the license at Docs/cddl1.txt
38  *  or http://www.opensolaris.org/os/licensing.
39  *  See the License for the specific language governing permissions
40  *  and limitations under the License.
41  *
42  * CDDL HEADER END
43  *
44  * TODO:
45  *
46  * Track processes accurately. This is a little difficult - anonpgout
47  * occurs asynchronously to the process, and events related to this don't
48  * point back to the process.
49  *
50  * Author: Brendan Gregg  [Sydney, Australia]
51  *
52  * 25-Jul-2005  Brendan Gregg   Created this.
53  * 18-Feb-2006     "      "     Last update.
54  */
55
56 #include <sys/vnode.h>
57
58 #pragma D option quiet
59
60 dtrace:::BEGIN
61 {
62         printf("Tracing... Hit Ctrl-C to end.\n");
63 }
64
65 fbt::pageio_setup:entry
66 /((args[2]->v_flag & (VISSWAP | VSWAPLIKE)) != 0)/
67 {
68         @total[pid, execname, args[3] & B_READ ? "R" : "W"] = sum(arg1);
69 }
70
71 dtrace:::END
72 {
73         printf("%6s %-16s %1s %s\n", "PID", "CMD", "D", "BYTES");
74         printa("%6d %-16s %1s %@d\n", @total);
75 }