1N/A# xvmstat - extended vmstat demo in DTrace. 1N/A# Written using DTrace (Solaris 10 3/05). 1N/A# This has been written to demonstrate fetching similar data as vmstat 1N/A# from DTrace, with a few extra fields. 1N/A# $Id: xvmstat 3 2007-08-01 10:50:08Z brendan $ 1N/A# USAGE: xvmstat [interval [count]] 1N/A# w swapped out LWPs number 1N/A# swap virtual memory free Mbytes 1N/A# free free RAM Mbytes 1N/A# - Most of the statistics are in units of pages, unlike the 1N/A# original vmstat command which sometimes uses kilobytes. 1N/A# - As this program does not use Kstat, there is no summary since boot line. 1N/A# - Free RAM is both free free + cache free. 1N/A# SEE ALSO: vmstat(1M) 1N/A# COPYRIGHT: Copyright (c) 2005 Brendan Gregg. 1N/A# The contents of this file are subject to the terms of the 1N/A# Common Development and Distribution License, Version 1.0 only 1N/A# (the "License"). You may not use this file except in compliance 1N/A# See the License for the specific language governing permissions 1N/A# and limitations under the License. 1N/A# 12-Jun-2005 Brendan Gregg Created this. 1N/A# 01-Mar-2006 " " Last update. 1N/A############################## 1N/A# --- Process Arguments --- 1N/Aif [
"$1" =
"-h" -o
"$1" =
"--help" ];
then 1N/A USAGE: xvmstat [interval [count]] 1N/A xvmstat # 1 second samples, infinite 1N/A xvmstat 1 # print every 1 second 1N/A xvmstat 5 6 # print every 5 seconds, 6 times 1N/Aif [ "$1" -gt 0 ]; then 1N/A interval=$1; count=-1; shift 1N/Aif [ "$1" -gt 0 ]; then 1N/Aif [ $interval -eq 0 ]; then 1N/A################################# 1N/A# --- Main Program, DTrace --- 1N/A/usr/sbin/dtrace -n ' 1N/A #pragma D option quiet 1N/A * Command line arguments 1N/A inline int INTERVAL = '$interval'; 1N/A inline int COUNTER = '$count'; 1N/A inline int SCREEN = 21; 1N/A * Initialise variables 1N/A re = 0; sr = 0; mf = 0; maj = 0; cow = 0; pro = 0; 1N/A epi = 0; epo = 0; epf = 0; api = 0; apo = 0; apf = 0; 1N/A fpi = 0; fpo = 0; fpf = 0; 1N/A /first || (secs == 0 && lines > SCREEN)/ 1N/A printf("%2s %6s %5s %5s %3s %4s %3s %3s %3s ", 1N/A "w", "swap", "free", "re", "maj", "mf", "cow", "pro", "sr"); 1N/A printf("%3s %3s %3s %3s %3s %3s %3s %3s %3s\n", 1N/A "epi", "epo", "epf", "api", "apo", "apf", "fpi", "fpo", "fpf"); 1N/A vminfo:::pgrec { re += arg0; } 1N/A vminfo:::scan { sr += arg0; } 1N/A vminfo:::as_fault { mf += arg0; } 1N/A vminfo:::execpgin { epi += arg0; } 1N/A vminfo:::execpgout { epo += arg0; } 1N/A vminfo:::execfree { epf += arg0; } 1N/A vminfo:::anonpgin { api += arg0; } 1N/A vminfo:::anonpgout { apo += arg0; } 1N/A vminfo:::anonfree { apf += arg0; } 1N/A vminfo:::fspgin { fpi += arg0; } 1N/A vminfo:::fspgout { fpo += arg0; } 1N/A vminfo:::fsfree { fpf += arg0; } 1N/A vminfo:::maj_fault { maj += arg0; } 1N/A vminfo:::cow_fault { cow += arg0; } 1N/A vminfo:::prot_fault { pro += arg0; } 1N/A /* fetch free mem */ 1N/A this->free = `freemem; 1N/A * free swap is described in /usr/include/vm/anon.h as, 1N/A * MAX(ani_max - ani_resv, 0) + (availrmem - swapfs_minfree) 1N/A this->ani_max = `k_anoninfo.ani_max; 1N/A this->ani_resv = `k_anoninfo.ani_phys_resv + `k_anoninfo.ani_mem_resv; 1N/A this->swap = (this->ani_max - this->ani_resv > 0 ? 1N/A this->ani_max - this->ani_resv : 0) + `availrmem - `swapfs_minfree; 1N/A this->w = `nswapped; 1N/A /* convert to Mbytes */ 1N/A this->swap *= `_pagesize; this->swap /= 1048576; 1N/A this->free *= `_pagesize; this->free /= 1048576; 1N/A /* convert to per second values */ 1N/A re /= INTERVAL; maj /= INTERVAL; mf /= INTERVAL; 1N/A cow /= INTERVAL; pro /= INTERVAL; sr /= INTERVAL; 1N/A epi /= INTERVAL; epo /= INTERVAL; epf /= INTERVAL; 1N/A api /= INTERVAL; apo /= INTERVAL; apf /= INTERVAL; 1N/A fpi /= INTERVAL; fpo /= INTERVAL; fpf /= INTERVAL; 1N/A printf("%2d %6d %5d %5d %3d %4d %3d %3d %3d ", 1N/A this->w, this->swap, this->free, re, maj, mf, cow, pro, sr); 1N/A printf("%3d %3d %3d %3d %3d %3d %3d %3d %3d\n", 1N/A epi, epo, epf, api, apo, apf, fpi, fpo, fpf); 1N/A /* clear counters */ 1N/A re = 0; sr = 0; mf = 0; maj = 0; cow = 0; pro = 0; 1N/A epi = 0; epo = 0; epf = 0; api = 0; apo = 0; apf = 0; 1N/A fpi = 0; fpo = 0; fpf = 0; 1N/A /* process counts */