3 # xvmstat - extended vmstat demo in DTrace.
4 # Written using DTrace (Solaris 10 3/05).
6 # This has been written to demonstrate fetching similar data as vmstat
7 # from DTrace, with a few extra fields.
9 # $Id: xvmstat 3 2007-08-01 10:50:08Z brendan $
11 # USAGE: xvmstat [interval [count]]
14 # w swapped out LWPs number
15 # swap virtual memory free Mbytes
16 # free free RAM Mbytes
17 # re page reclaims pages/sec
18 # maj major faults pages/sec
19 # mf minor faults pages/sec
20 # cow copy-on-write faults pages/sec
21 # pro protection faults pages/sec
22 # sr scan rate pages/sec
23 # epi executable page ins pages/sec
24 # epo executable page outs pages/sec
25 # epf executable frees pages/sec
26 # api anonymous page ins pages/sec
27 # apo anonymous page outs pages/sec
28 # apf anonymous frees pages/sec
29 # fpi filesystem page ins pages/sec
30 # fpo filesystem page outs pages/sec
31 # fpf filesystem frees pages/sec
34 # - Most of the statistics are in units of pages, unlike the
35 # original vmstat command which sometimes uses kilobytes.
36 # - As this program does not use Kstat, there is no summary since boot line.
37 # - Free RAM is both free free + cache free.
39 # SEE ALSO: vmstat(1M)
41 # COPYRIGHT: Copyright (c) 2005 Brendan Gregg.
45 # The contents of this file are subject to the terms of the
46 # Common Development and Distribution License, Version 1.0 only
47 # (the "License"). You may not use this file except in compliance
50 # You can obtain a copy of the license at Docs/cddl1.txt
51 # or http://www.opensolaris.org/os/licensing.
52 # See the License for the specific language governing permissions
53 # and limitations under the License.
57 # 12-Jun-2005 Brendan Gregg Created this.
58 # 01-Mar-2006 " " Last update.
61 ##############################
62 # --- Process Arguments ---
69 if [ "$1" = "-h" -o "$1" = "--help" ]; then
71 USAGE: xvmstat [interval [count]]
72 xvmstat # 1 second samples, infinite
74 xvmstat 1 # print every 1 second
75 xvmstat 5 6 # print every 5 seconds, 6 times
81 if [ "$1" -gt 0 ]; then
82 interval=$1; count=-1; shift
84 if [ "$1" -gt 0 ]; then
87 if [ $interval -eq 0 ]; then
92 #################################
93 # --- Main Program, DTrace ---
96 #pragma D option quiet
99 * Command line arguments
101 inline int INTERVAL = '$interval';
102 inline int COUNTER = '$count';
103 inline int SCREEN = 21;
106 * Initialise variables
110 re = 0; sr = 0; mf = 0; maj = 0; cow = 0; pro = 0;
111 epi = 0; epo = 0; epf = 0; api = 0; apo = 0; apf = 0;
112 fpi = 0; fpo = 0; fpf = 0;
129 /first || (secs == 0 && lines > SCREEN)/
131 printf("%2s %6s %5s %5s %3s %4s %3s %3s %3s ",
132 "w", "swap", "free", "re", "maj", "mf", "cow", "pro", "sr");
133 printf("%3s %3s %3s %3s %3s %3s %3s %3s %3s\n",
134 "epi", "epo", "epf", "api", "apo", "apf", "fpi", "fpo", "fpf");
142 vminfo:::pgrec { re += arg0; }
143 vminfo:::scan { sr += arg0; }
144 vminfo:::as_fault { mf += arg0; }
145 vminfo:::execpgin { epi += arg0; }
146 vminfo:::execpgout { epo += arg0; }
147 vminfo:::execfree { epf += arg0; }
148 vminfo:::anonpgin { api += arg0; }
149 vminfo:::anonpgout { apo += arg0; }
150 vminfo:::anonfree { apf += arg0; }
151 vminfo:::fspgin { fpi += arg0; }
152 vminfo:::fspgout { fpo += arg0; }
153 vminfo:::fsfree { fpf += arg0; }
154 vminfo:::maj_fault { maj += arg0; }
155 vminfo:::cow_fault { cow += arg0; }
156 vminfo:::prot_fault { pro += arg0; }
165 this->free = `freemem;
170 * free swap is described in /usr/include/vm/anon.h as,
171 * MAX(ani_max - ani_resv, 0) + (availrmem - swapfs_minfree)
173 this->ani_max = `k_anoninfo.ani_max;
174 this->ani_resv = `k_anoninfo.ani_phys_resv + `k_anoninfo.ani_mem_resv;
175 this->swap = (this->ani_max - this->ani_resv > 0 ?
176 this->ani_max - this->ani_resv : 0) + `availrmem - `swapfs_minfree;
181 /* convert to Mbytes */
182 this->swap *= `_pagesize; this->swap /= 1048576;
183 this->free *= `_pagesize; this->free /= 1048576;
185 /* convert to per second values */
186 re /= INTERVAL; maj /= INTERVAL; mf /= INTERVAL;
187 cow /= INTERVAL; pro /= INTERVAL; sr /= INTERVAL;
188 epi /= INTERVAL; epo /= INTERVAL; epf /= INTERVAL;
189 api /= INTERVAL; apo /= INTERVAL; apf /= INTERVAL;
190 fpi /= INTERVAL; fpo /= INTERVAL; fpf /= INTERVAL;
193 printf("%2d %6d %5d %5d %3d %4d %3d %3d %3d ",
194 this->w, this->swap, this->free, re, maj, mf, cow, pro, sr);
195 printf("%3d %3d %3d %3d %3d %3d %3d %3d %3d\n",
196 epi, epo, epf, api, apo, apf, fpi, fpo, fpf);
199 re = 0; sr = 0; mf = 0; maj = 0; cow = 0; pro = 0;
200 epi = 0; epo = 0; epf = 0; api = 0; apo = 0; apf = 0;
201 fpi = 0; fpo = 0; fpf = 0;