1N/A#!/usr/sbin/dtrace -s
1N/A/*
1N/A * vmstat-p.d - vmstat -p demo in DTrace.
1N/A * Written using DTrace (Solaris 10 3/05).
1N/A *
1N/A * This has been written to demonstrate fetching similar data as vmstat
1N/A * from DTrace. This program is intended as a starting point for other
1N/A * DTrace scripts, by beginning with familiar statistics.
1N/A *
1N/A * $Id: vmstat-p.d 3 2007-08-01 10:50:08Z brendan $
1N/A *
1N/A * USAGE: vmstat-p.d
1N/A *
1N/A * FIELDS:
1N/A * swap virtual memory free Kbytes
1N/A * free free RAM Kbytes
1N/A * re page reclaims Kbytes
1N/A * mf minor faults Kbytes
1N/A * sr scan rate pages
1N/A * epi executable page ins Kbytes
1N/A * epo executable page outs Kbytes
1N/A * epf executable frees Kbytes
1N/A * api anonymous page ins Kbytes
1N/A * apo anonymous page outs Kbytes
1N/A * apf anonymous frees Kbytes
1N/A * fpi filesystem page ins Kbytes
1N/A * fpo filesystem page outs Kbytes
1N/A * fpf filesystem frees Kbytes
1N/A *
1N/A * NOTES:
1N/A * Most of the statistics are in units of kilobytes, unlike the
1N/A * original vmstat command which sometimes uses page counts.
1N/A * As this program does not use Kstat, there is no summary since
1N/A * boot line. Free RAM is both free free + cache free.
1N/A *
1N/A * SEE ALSO: vmstat(1M)
1N/A *
1N/A * COPYRIGHT: Copyright (c) 2005 Brendan Gregg.
1N/A *
1N/A * CDDL HEADER START
1N/A *
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 * with the License.
1N/A *
1N/A * You can obtain a copy of the license at Docs/cddl1.txt
1N/A * or http://www.opensolaris.org/os/licensing.
1N/A * See the License for the specific language governing permissions
1N/A * and limitations under the License.
1N/A *
1N/A * CDDL HEADER END
1N/A *
1N/A * 11-Jun-2005 Brendan Gregg Created this.
1N/A * 08-Jan-2006 " " Last update.
1N/A */
1N/A
1N/A#pragma D option quiet
1N/A
1N/Ainline int SCREEN = 21;
1N/A
1N/A/*
1N/A * Initialise variables
1N/A */
1N/Adtrace:::BEGIN
1N/A{
1N/A pi = 0; po = 0; re = 0; sr = 0; mf = 0; fr = 0;
1N/A sy = 0; in = 0; cs = 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 lines = SCREEN + 1;
1N/A}
1N/A
1N/A/*
1N/A * Print header
1N/A */
1N/Adtrace:::BEGIN,
1N/Atick-1sec
1N/A/lines++ > SCREEN/
1N/A{
1N/A printf("%14s %13s %16s %14s %13s\n",
1N/A "memory", "page", "executable", "anonymous", "filesystem");
1N/A printf("%9s %7s %5s %4s %3s ",
1N/A "swap", "free", "re", "mf", "sr");
1N/A printf("%4s %4s %4s %4s %4s %4s %4s %4s %4s\n",
1N/A "epi", "epo", "epf", "api", "apo", "apf", "fpi", "fpo", "fpf");
1N/A lines = 0;
1N/A}
1N/A
1N/A/*
1N/A * Probe events
1N/A */
1N/Avminfo:::pgrec { re += arg0; }
1N/Avminfo:::scan { sr += arg0; }
1N/Avminfo:::as_fault { mf += arg0; }
1N/Avminfo:::execpgin { epi += arg0; }
1N/Avminfo:::execpgout { epo += arg0; }
1N/Avminfo:::execfree { epf += arg0; }
1N/Avminfo:::anonpgin { api += arg0; }
1N/Avminfo:::anonpgout { apo += arg0; }
1N/Avminfo:::anonfree { apf += arg0; }
1N/Avminfo:::fspgin { fpi += arg0; }
1N/Avminfo:::fspgout { fpo += arg0; }
1N/Avminfo:::fsfree { fpf += arg0; }
1N/A
1N/A/*
1N/A * Print output line
1N/A */
1N/Aprofile:::tick-1sec
1N/A{
1N/A /* fetch free mem */
1N/A this->free = `freemem;
1N/A
1N/A /*
1N/A * fetch free swap
1N/A *
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 */
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
1N/A /* fetch w */
1N/A this->w = `nswapped;
1N/A
1N/A /* convert to Kbytes */
1N/A epi *= `_pagesize / 1024;
1N/A epo *= `_pagesize / 1024;
1N/A epf *= `_pagesize / 1024;
1N/A api *= `_pagesize / 1024;
1N/A apo *= `_pagesize / 1024;
1N/A apf *= `_pagesize / 1024;
1N/A fpi *= `_pagesize / 1024;
1N/A fpo *= `_pagesize / 1024;
1N/A fpf *= `_pagesize / 1024;
1N/A re *= `_pagesize / 1024;
1N/A sr *= `_pagesize / 1024;
1N/A mf *= `_pagesize / 1024;
1N/A this->swap *= `_pagesize / 1024;
1N/A this->free *= `_pagesize / 1024;
1N/A
1N/A /* print line */
1N/A printf("%9d %7d %5d %4d %3d ",
1N/A this->swap, this->free, re, mf, sr);
1N/A printf("%4d %4d %4d %4d %4d %4d %4d %4d %4d\n",
1N/A epi, epo, epf, api, apo, apf, fpi, fpo, fpf);
1N/A
1N/A /* clear counters */
1N/A pi = 0; po = 0; re = 0; sr = 0; mf = 0; fr = 0;
1N/A sy = 0; in = 0; cs = 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}