1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
|
#!/usr/bin/sh
#
# xvmstat - extended vmstat demo in DTrace.
# Written using DTrace (Solaris 10 3/05).
#
# This has been written to demonstrate fetching similar data as vmstat
# from DTrace, with a few extra fields.
#
# $Id: xvmstat,v 1.1.1.1 2015/09/30 22:01:09 christos Exp $
#
# USAGE: xvmstat [interval [count]]
#
# FIELDS:
# w swapped out LWPs number
# swap virtual memory free Mbytes
# free free RAM Mbytes
# re page reclaims pages/sec
# maj major faults pages/sec
# mf minor faults pages/sec
# cow copy-on-write faults pages/sec
# pro protection faults pages/sec
# sr scan rate pages/sec
# epi executable page ins pages/sec
# epo executable page outs pages/sec
# epf executable frees pages/sec
# api anonymous page ins pages/sec
# apo anonymous page outs pages/sec
# apf anonymous frees pages/sec
# fpi filesystem page ins pages/sec
# fpo filesystem page outs pages/sec
# fpf filesystem frees pages/sec
#
# NOTES:
# - Most of the statistics are in units of pages, unlike the
# original vmstat command which sometimes uses kilobytes.
# - As this program does not use Kstat, there is no summary since boot line.
# - Free RAM is both free free + cache free.
#
# SEE ALSO: vmstat(1M)
#
# COPYRIGHT: Copyright (c) 2005 Brendan Gregg.
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License, Version 1.0 only
# (the "License"). You may not use this file except in compliance
# with the License.
#
# You can obtain a copy of the license at Docs/cddl1.txt
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# CDDL HEADER END
#
# 12-Jun-2005 Brendan Gregg Created this.
# 01-Mar-2006 " " Last update.
#
##############################
# --- Process Arguments ---
#
### default values
interval=1; count=-1
### check arguments
if [ "$1" = "-h" -o "$1" = "--help" ]; then
cat <<-END >&2
USAGE: xvmstat [interval [count]]
xvmstat # 1 second samples, infinite
eg,
xvmstat 1 # print every 1 second
xvmstat 5 6 # print every 5 seconds, 6 times
END
exit 1
fi
### argument logic
if [ "$1" -gt 0 ]; then
interval=$1; count=-1; shift
fi
if [ "$1" -gt 0 ]; then
count=$1; shift
fi
if [ $interval -eq 0 ]; then
interval=1
fi
#################################
# --- Main Program, DTrace ---
#
/usr/sbin/dtrace -n '
#pragma D option quiet
/*
* Command line arguments
*/
inline int INTERVAL = '$interval';
inline int COUNTER = '$count';
inline int SCREEN = 21;
/*
* Initialise variables
*/
dtrace:::BEGIN
{
re = 0; sr = 0; mf = 0; maj = 0; cow = 0; pro = 0;
epi = 0; epo = 0; epf = 0; api = 0; apo = 0; apf = 0;
fpi = 0; fpo = 0; fpf = 0;
lines = SCREEN + 1;
counts = COUNTER;
secs = INTERVAL;
first = 1;
}
profile:::tick-1sec
{
secs--;
}
/*
* Print header
*/
dtrace:::BEGIN,
profile:::tick-1sec
/first || (secs == 0 && lines > SCREEN)/
{
printf("%2s %6s %5s %5s %3s %4s %3s %3s %3s ",
"w", "swap", "free", "re", "maj", "mf", "cow", "pro", "sr");
printf("%3s %3s %3s %3s %3s %3s %3s %3s %3s\n",
"epi", "epo", "epf", "api", "apo", "apf", "fpi", "fpo", "fpf");
lines = 0;
first = 0;
}
/*
* Probe events
*/
vminfo:::pgrec { re += arg0; }
vminfo:::scan { sr += arg0; }
vminfo:::as_fault { mf += arg0; }
vminfo:::execpgin { epi += arg0; }
vminfo:::execpgout { epo += arg0; }
vminfo:::execfree { epf += arg0; }
vminfo:::anonpgin { api += arg0; }
vminfo:::anonpgout { apo += arg0; }
vminfo:::anonfree { apf += arg0; }
vminfo:::fspgin { fpi += arg0; }
vminfo:::fspgout { fpo += arg0; }
vminfo:::fsfree { fpf += arg0; }
vminfo:::maj_fault { maj += arg0; }
vminfo:::cow_fault { cow += arg0; }
vminfo:::prot_fault { pro += arg0; }
/*
* Print output line
*/
profile:::tick-1sec
/secs == 0/
{
/* fetch free mem */
this->free = `freemem;
/*
* fetch free swap
*
* free swap is described in /usr/include/vm/anon.h as,
* MAX(ani_max - ani_resv, 0) + (availrmem - swapfs_minfree)
*/
this->ani_max = `k_anoninfo.ani_max;
this->ani_resv = `k_anoninfo.ani_phys_resv + `k_anoninfo.ani_mem_resv;
this->swap = (this->ani_max - this->ani_resv > 0 ?
this->ani_max - this->ani_resv : 0) + `availrmem - `swapfs_minfree;
/* fetch w */
this->w = `nswapped;
/* convert to Mbytes */
this->swap *= `_pagesize; this->swap /= 1048576;
this->free *= `_pagesize; this->free /= 1048576;
/* convert to per second values */
re /= INTERVAL; maj /= INTERVAL; mf /= INTERVAL;
cow /= INTERVAL; pro /= INTERVAL; sr /= INTERVAL;
epi /= INTERVAL; epo /= INTERVAL; epf /= INTERVAL;
api /= INTERVAL; apo /= INTERVAL; apf /= INTERVAL;
fpi /= INTERVAL; fpo /= INTERVAL; fpf /= INTERVAL;
/* print line */
printf("%2d %6d %5d %5d %3d %4d %3d %3d %3d ",
this->w, this->swap, this->free, re, maj, mf, cow, pro, sr);
printf("%3d %3d %3d %3d %3d %3d %3d %3d %3d\n",
epi, epo, epf, api, apo, apf, fpi, fpo, fpf);
/* clear counters */
re = 0; sr = 0; mf = 0; maj = 0; cow = 0; pro = 0;
epi = 0; epo = 0; epf = 0; api = 0; apo = 0; apf = 0;
fpi = 0; fpo = 0; fpf = 0;
/* process counts */
secs = INTERVAL;
counts--;
lines++;
}
/*
* End
*/
profile:::tick-1sec
/counts == 0/
{
exit(0);
}
'
|