325N/A# xvmstat - extended vmstat demo in DTrace. 325N/A# Written using DTrace (Solaris 10 3/05). 325N/A# This has been written to demonstrate fetching similar data as vmstat 325N/A# from DTrace, with a few extra fields. 325N/A# $Id: xvmstat 3 2007-08-01 10:50:08Z brendan $ 325N/A# USAGE: xvmstat [interval [count]] 325N/A# w swapped out LWPs number 325N/A# swap virtual memory free Mbytes 325N/A# - Most of the statistics are in units of pages, unlike the 325N/A# original vmstat command which sometimes uses kilobytes. 325N/A# - As this program does not use Kstat, there is no summary since boot line. 325N/A# - Free RAM is both free free + cache free. 325N/A# COPYRIGHT: Copyright (c) 2005 Brendan Gregg. 325N/A# The contents of this file are subject to the terms of the 325N/A# Common Development and Distribution License, Version 1.0 only 325N/A# (the "License"). You may not use this file except in compliance 325N/A# See the License for the specific language governing permissions 325N/A# and limitations under the License. 325N/A# 12-Jun-2005 Brendan Gregg Created this. 325N/A# 01-Mar-2006 " " Last update. 325N/A############################## 325N/A# --- Process Arguments --- if [
"$1" =
"-h" -o
"$1" =
"--help" ];
then USAGE: xvmstat [interval [count]] xvmstat # 1 second samples, infinite xvmstat 1 # print every 1 second xvmstat 5 6 # print every 5 seconds, 6 times interval=$1; count=-1; shift if [ $interval -eq 0 ]; then ################################# # --- Main Program, DTrace --- inline int INTERVAL = '$interval'; inline int COUNTER = '$count'; 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; /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"); 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; } * 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; 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; 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); 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;