3 * vmstat.d - vmstat demo in DTrace.
4 * Written using DTrace (Solaris 10 3/05).
6 * This has been written to demonstrate fetching the same data as vmstat
7 * from DTrace. This program is intended as a starting point for other
8 * DTrace scripts, by beginning with familiar statistics.
10 * $Id: vmstat.d 8 2007-08-06 05:55:26Z brendan $
15 * w swapped out LWPs number
16 * swap virtual memory free Kbytes
17 * free free RAM Kbytes
18 * re page reclaims Kbytes
19 * mf minor faults Kbytes
22 * fr pages freed Kbytes
24 * in interrupts number
25 * sy system calls number
26 * cs context switches number
29 * Most of the statistics are in units of kilobytes, unlike the
30 * original vmstat command which sometimes uses page counts.
31 * As this program does not use Kstat, there is no summary since boot line.
32 * Free RAM is both free free + cache free.
34 * SEE ALSO: vmstat(1M)
36 * COPYRIGHT: Copyright (c) 2005 Brendan Gregg.
40 * The contents of this file are subject to the terms of the
41 * Common Development and Distribution License, Version 1.0 only
42 * (the "License"). You may not use this file except in compliance
45 * You can obtain a copy of the license at Docs/cddl1.txt
46 * or http://www.opensolaris.org/os/licensing.
47 * See the License for the specific language governing permissions
48 * and limitations under the License.
52 * 11-Jun-2005 Brendan Gregg Created this.
53 * 08-Jan-2006 " " Last update.
56 #pragma D option quiet
58 inline int SCREEN = 21;
61 * Initialise variables
65 pi = 0; po = 0; re = 0; sr = 0; mf = 0; fr = 0;
66 sy = 0; in = 0; cs = 0;
77 printf(" %1s %10s %8s %5s %5s %4s %4s %4s %4s %5s %6s %4s\n",
78 "w", "swap", "free", "re", "mf", "pi", "po", "fr", "sr",
86 vminfo:::pgpgin { pi += arg0; }
87 vminfo:::pgpgout { po += arg0; }
88 vminfo:::pgrec { re += arg0; }
89 vminfo:::scan { sr += arg0; }
90 vminfo:::as_fault { mf += arg0; }
91 vminfo:::dfree { fr += arg0; }
93 syscall:::entry { sy++; }
94 sdt:::interrupt-start { in++; }
95 sched::resume:on-cpu { cs++; }
103 this->free = `freemem;
108 * free swap is described in /usr/include/vm/anon.h as,
109 * MAX(ani_max - ani_resv, 0) + (availrmem - swapfs_minfree)
111 this->ani_max = `k_anoninfo.ani_max;
112 this->ani_resv = `k_anoninfo.ani_phys_resv + `k_anoninfo.ani_mem_resv;
113 this->swap = (this->ani_max - this->ani_resv > 0 ?
114 this->ani_max - this->ani_resv : 0) + `availrmem - `swapfs_minfree;
119 /* convert to Kbytes */
120 pi *= `_pagesize / 1024;
121 po *= `_pagesize / 1024;
122 re *= `_pagesize / 1024;
123 sr *= `_pagesize / 1024;
124 mf *= `_pagesize / 1024;
125 fr *= `_pagesize / 1024;
126 this->swap *= `_pagesize / 1024;
127 this->free *= `_pagesize / 1024;
130 printf(" %1d %10d %8d %5d %5d %4d %4d %4d %4d %5d %6d %4d\n",
131 this->w, this->swap, this->free, re, mf, pi, po, fr, sr,
135 pi = 0; po = 0; re = 0; sr = 0; mf = 0; fr = 0;
136 sy = 0; in = 0; cs = 0;