diff options
Diffstat (limited to 'cddl/contrib/dtracetoolkit/Mem')
-rw-r--r-- | cddl/contrib/dtracetoolkit/Mem/Readme | 3 | ||||
-rwxr-xr-x | cddl/contrib/dtracetoolkit/Mem/anonpgpid.d | 75 | ||||
-rwxr-xr-x | cddl/contrib/dtracetoolkit/Mem/minfbypid.d | 57 | ||||
-rwxr-xr-x | cddl/contrib/dtracetoolkit/Mem/minfbyproc.d | 10 | ||||
-rwxr-xr-x | cddl/contrib/dtracetoolkit/Mem/pgpginbypid.d | 53 | ||||
-rwxr-xr-x | cddl/contrib/dtracetoolkit/Mem/pgpginbyproc.d | 10 | ||||
-rwxr-xr-x | cddl/contrib/dtracetoolkit/Mem/swapinfo.d | 149 | ||||
-rwxr-xr-x | cddl/contrib/dtracetoolkit/Mem/vmbypid.d | 54 | ||||
-rwxr-xr-x | cddl/contrib/dtracetoolkit/Mem/vmstat-p.d | 155 | ||||
-rwxr-xr-x | cddl/contrib/dtracetoolkit/Mem/vmstat.d | 137 | ||||
-rwxr-xr-x | cddl/contrib/dtracetoolkit/Mem/xvmstat | 217 |
11 files changed, 920 insertions, 0 deletions
diff --git a/cddl/contrib/dtracetoolkit/Mem/Readme b/cddl/contrib/dtracetoolkit/Mem/Readme new file mode 100644 index 0000000..c4f7e3d --- /dev/null +++ b/cddl/contrib/dtracetoolkit/Mem/Readme @@ -0,0 +1,3 @@ +Mem - Memory based analysis + + These scripts analyse memory and virtual memory related activity. diff --git a/cddl/contrib/dtracetoolkit/Mem/anonpgpid.d b/cddl/contrib/dtracetoolkit/Mem/anonpgpid.d new file mode 100755 index 0000000..73971d9 --- /dev/null +++ b/cddl/contrib/dtracetoolkit/Mem/anonpgpid.d @@ -0,0 +1,75 @@ +#!/usr/sbin/dtrace -Cs +/* + * anonpgpid.d - anonymous memory paging info by process on CPU. + * Written using DTrace (Solaris 10 3/05). + * + * This scripts may help identify which processes are affected by a system + * with low memory, which is paging to the physical swap device. A report + * of the process on the CPU when paging occured is printed. + * + * $Id: anonpgpid.d 8 2007-08-06 05:55:26Z brendan $ + * + * USAGE: anonpgpid.d # hit Ctrl-C to end + * + * FIELDS: + * PID Process ID + * CMD Process name + * D Direction, Read or Write + * BYTES Total bytes during sample + * + * NOTES: + * + * This program is currently an approximation - often the process when writing + * pages to swap will be "pageout" the pageout scanner, or "rcapd" the + * resource capping daemon. + * + * THANKS: James Dickens + * + * COPYRIGHT: Copyright (c) 2006 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 + * + * TODO: + * + * Track processes accurately. This is a little difficult - anonpgout + * occurs asynchronously to the process, and events related to this don't + * point back to the process. + * + * Author: Brendan Gregg [Sydney, Australia] + * + * 25-Jul-2005 Brendan Gregg Created this. + * 18-Feb-2006 " " Last update. + */ + +#include <sys/vnode.h> + +#pragma D option quiet + +dtrace:::BEGIN +{ + printf("Tracing... Hit Ctrl-C to end.\n"); +} + +fbt::pageio_setup:entry +/((args[2]->v_flag & (VISSWAP | VSWAPLIKE)) != 0)/ +{ + @total[pid, execname, args[3] & B_READ ? "R" : "W"] = sum(arg1); +} + +dtrace:::END +{ + printf("%6s %-16s %1s %s\n", "PID", "CMD", "D", "BYTES"); + printa("%6d %-16s %1s %@d\n", @total); +} diff --git a/cddl/contrib/dtracetoolkit/Mem/minfbypid.d b/cddl/contrib/dtracetoolkit/Mem/minfbypid.d new file mode 100755 index 0000000..43f6f83 --- /dev/null +++ b/cddl/contrib/dtracetoolkit/Mem/minfbypid.d @@ -0,0 +1,57 @@ +#!/usr/sbin/dtrace -s +/* + * minfbypid.d - minor faults by PID. + * Written using DTrace (Solaris 10 3/05) + * + * This program prints a report of minor faults by PID. Minor faults are + * an indiction of memory consumption. This script could be used to help + * determine which process was consuming the most memory during the sample. + * + * $Id: minfbypid.d 3 2007-08-01 10:50:08Z brendan $ + * + * USAGE: minfbypid.d # hit Ctrl-C to end sample + * + * FIELDS: + * PID process ID + * CMD process name + * MINFAULTS number of minor faults + * + * This is based on a script from DExplorer. + * + * COPYRIGHT: Copyright (c) 2005, 2006 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 + * + * 28-Jun-2005 Brendan Gregg Created this. + * 20-Apr-2006 " " Last update. + */ + +#pragma D option quiet + +dtrace:::BEGIN +{ + printf("Tracing... Hit Ctrl-C to end.\n"); +} + +vminfo:::as_fault +{ + @mem[pid, execname] = sum(arg0); +} + +dtrace:::END +{ + printf("%6s %-16s %16s\n", "PID", "CMD", "MINFAULTS"); + printa("%6d %-16s %@16d\n", @mem); +} diff --git a/cddl/contrib/dtracetoolkit/Mem/minfbyproc.d b/cddl/contrib/dtracetoolkit/Mem/minfbyproc.d new file mode 100755 index 0000000..4d7316c --- /dev/null +++ b/cddl/contrib/dtracetoolkit/Mem/minfbyproc.d @@ -0,0 +1,10 @@ +#!/usr/sbin/dtrace -s +/* + * minfbyproc.d - minor faults by process name. DTrace OneLiner. + * + * This is a DTrace OneLiner from the DTraceToolkit. + * + * $Id: minfbyproc.d 3 2007-08-01 10:50:08Z brendan $ + */ + +vminfo:::as_fault { @mem[execname] = sum(arg0); } diff --git a/cddl/contrib/dtracetoolkit/Mem/pgpginbypid.d b/cddl/contrib/dtracetoolkit/Mem/pgpginbypid.d new file mode 100755 index 0000000..bd0ee53 --- /dev/null +++ b/cddl/contrib/dtracetoolkit/Mem/pgpginbypid.d @@ -0,0 +1,53 @@ +#!/usr/sbin/dtrace -s +/* + * pgpginbypid.d - pages paged in by PID. + * Writen using DTrace (Solaris 10 3/05). + * + * $Id: pgpginbypid.d 3 2007-08-01 10:50:08Z brendan $ + * + * USAGE: pgpginbypid.d # hit Ctrl-C to end sample + * + * FIELDS: + * PID process ID + * CMD process name + * PAGES number of pages paged in + * + * This is based on a script from DExplorer. + * + * COPYRIGHT: Copyright (c) 2005, 2006 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 + * + * 28-Jun-2005 Brendan Gregg Created this. + * 20-Apr-2006 " " Last update. + */ + +#pragma D option quiet + +dtrace:::BEGIN +{ + printf("Tracing... Hit Ctrl-C to end.\n"); +} + +vminfo:::pgpgin +{ + @pg[pid, execname] = sum(arg0); +} + +dtrace:::END +{ + printf("%6s %-16s %16s\n", "PID", "CMD", "PAGES"); + printa("%6d %-16s %@16d\n", @pg); +} diff --git a/cddl/contrib/dtracetoolkit/Mem/pgpginbyproc.d b/cddl/contrib/dtracetoolkit/Mem/pgpginbyproc.d new file mode 100755 index 0000000..572271b --- /dev/null +++ b/cddl/contrib/dtracetoolkit/Mem/pgpginbyproc.d @@ -0,0 +1,10 @@ +#!/usr/sbin/dtrace -s +/* + * pgpginbyproc.d - pages paged in by process name. DTrace OneLiner. + * + * This is a DTrace OneLiner from the DTraceToolkit. + * + * $Id: pgpginbyproc.d 3 2007-08-01 10:50:08Z brendan $ + */ + +vminfo:::pgpgin { @pg[execname] = sum(arg0); } diff --git a/cddl/contrib/dtracetoolkit/Mem/swapinfo.d b/cddl/contrib/dtracetoolkit/Mem/swapinfo.d new file mode 100755 index 0000000..045cd72 --- /dev/null +++ b/cddl/contrib/dtracetoolkit/Mem/swapinfo.d @@ -0,0 +1,149 @@ +#!/usr/sbin/dtrace -s +/* + * swapinfo.d - print virtual memory info (swap). + * Written using DTrace (Solaris 10 3/05) + * + * Prints swap usage details for RAM and disk based swap. + * This script is UNDER CONSTRUCTION, check for newer versions. + * + * $Id: swapinfo.d 3 2007-08-01 10:50:08Z brendan $ + * + * USAGE: swapinfo.d (check for newer versions) + * + * FIELDS: + * RAM Total Total RAM installed + * RAM Unusable RAM consumed by the OBP and TSBs + * RAM Kernel Kernel resident in RAM (and usually locked) + * RAM Locked Locked memory pages from swap (Anon) + * RAM Used anon + exec + file pages used + * RAM Free free memory + page cache free + * Disk Total Total disk swap configured + * Disk Resv Disk swap allocated + reserved + * Disk Avail Disk swap available for reservation + * Swap Total Total Virtual Memory usable + * Swap Resv VM allocated + reserved + * Swap Avail VM available for reservation + * Swap MinFree VM kept free from reservations + * + * SEE ALSO: swapinfo - K9Toolkit, http://www.brendangregg.com/k9toolkit.html + * vmstat 1 2; swap -s; echo ::memstat | mdb -k + * RMCmem - The MemTool Package + * RICHPse - The SE Toolkit + * "Clearing up swap space confusion" Unix Insider, Adrian Cockcroft + * "Solaris Internals", Jim Mauro, Richard McDougall + * /usr/include/vm/anon.h, /usr/include/sys/systm.h + * + * COPYRIGHT: Copyright (c) 2005, 2006 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 + * + * Author: Brendan Gregg [Sydney, Australia] + * + * 11-Jun-2005 Brendan Gregg Created this. + * 24-Apr-2006 " " Improved disk measurements; changed terms. + * 24-Apr-2006 " " Last update. + */ + +#pragma D option quiet +#pragma D option bufsize=16k + +inline int DEBUG = 0; + +dtrace:::BEGIN +{ + /* Debug stats */ + this->ani_max = `k_anoninfo.ani_max; + this->ani_phys_resv = `k_anoninfo.ani_phys_resv; + this->ani_mem_resv = `k_anoninfo.ani_mem_resv; + this->ani_locked = `k_anoninfo.ani_locked_swap; + this->availrmem = `availrmem; + + /* RAM stats */ + this->ram_total = `physinstalled; + this->unusable = `physinstalled - `physmem; + this->locked = `pages_locked; + this->ram_used = `availrmem - `freemem; + this->freemem = `freemem; + this->kernel = `physmem - `pages_locked - `availrmem; + + /* Disk stats */ + this->disk_total = `k_anoninfo.ani_max; + this->disk_resv = `k_anoninfo.ani_phys_resv; + this->disk_avail = this->disk_total - this->disk_resv; + + /* Total Swap stats */ + this->minfree = `swapfs_minfree; + this->reserve = `swapfs_reserve; + /* this is TOTAL_AVAILABLE_SWAP from /usr/include/vm/anon.h, */ + this->swap_total = `k_anoninfo.ani_max + + (`availrmem - `swapfs_minfree > 0 ? + `availrmem - `swapfs_minfree : 0); + /* this is CURRENT_TOTAL_AVAILABLE_SWAP from /usr/include/vm/anon.h, */ + this->swap_avail = `k_anoninfo.ani_max - `k_anoninfo.ani_phys_resv + + (`availrmem - `swapfs_minfree > 0 ? + `availrmem - `swapfs_minfree : 0); + this->swap_resv = this->swap_total - this->swap_avail; + + /* Convert to Mbytes */ + this->ani_phys_resv *= `_pagesize; this->ani_phys_resv /= 1048576; + this->ani_mem_resv *= `_pagesize; this->ani_mem_resv /= 1048576; + this->ani_locked *= `_pagesize; this->ani_locked /= 1048576; + this->ani_max *= `_pagesize; this->ani_max /= 1048576; + this->availrmem *= `_pagesize; this->availrmem /= 1048576; + this->ram_total *= `_pagesize; this->ram_total /= 1048576; + this->unusable *= `_pagesize; this->unusable /= 1048576; + this->kernel *= `_pagesize; this->kernel /= 1048576; + this->locked *= `_pagesize; this->locked /= 1048576; + this->ram_used *= `_pagesize; this->ram_used /= 1048576; + this->freemem *= `_pagesize; this->freemem /= 1048576; + this->disk_total *= `_pagesize; this->disk_total /= 1048576; + this->disk_resv *= `_pagesize; this->disk_resv /= 1048576; + this->disk_avail *= `_pagesize; this->disk_avail /= 1048576; + this->swap_total *= `_pagesize; this->swap_total /= 1048576; + this->swap_avail *= `_pagesize; this->swap_avail /= 1048576; + this->swap_resv *= `_pagesize; this->swap_resv /= 1048576; + this->minfree *= `_pagesize; this->minfree /= 1048576; + this->reserve *= `_pagesize; this->reserve /= 1048576; + + /* Print debug */ + DEBUG ? printf("DEBUG availrmem %5d MB\n", this->availrmem) : 1; + DEBUG ? printf("DEBUG freemem %5d MB\n", this->freemem) : 1; + DEBUG ? printf("DEBUG ani_max %5d MB\n", this->ani_max) : 1; + DEBUG ? printf("DEBUG ani_phys_re %5d MB\n", this->ani_phys_resv) : 1; + DEBUG ? printf("DEBUG ani_mem_re %5d MB\n", this->ani_mem_resv) : 1; + DEBUG ? printf("DEBUG ani_locked %5d MB\n", this->ani_locked) : 1; + DEBUG ? printf("DEBUG reserve %5d MB\n", this->reserve) : 1; + DEBUG ? printf("\n") : 1; + + /* Print report */ + printf("RAM _______Total %5d MB\n", this->ram_total); + printf("RAM Unusable %5d MB\n", this->unusable); + printf("RAM Kernel %5d MB\n", this->kernel); + printf("RAM Locked %5d MB\n", this->locked); + printf("RAM Used %5d MB\n", this->ram_used); + printf("RAM Free %5d MB\n", this->freemem); + printf("\n"); + printf("Disk _______Total %5d MB\n", this->disk_total); + printf("Disk Resv %5d MB\n", this->disk_resv); + printf("Disk Avail %5d MB\n", this->disk_avail); + printf("\n"); + printf("Swap _______Total %5d MB\n", this->swap_total); + printf("Swap Resv %5d MB\n", this->swap_resv); + printf("Swap Avail %5d MB\n", this->swap_avail); + printf("Swap (Minfree) %5d MB\n", this->minfree); + + DEBUG ? printf("\nNow run other commands for confirmation.\n") : 1; + ! DEBUG ? exit(0) : 1; +} diff --git a/cddl/contrib/dtracetoolkit/Mem/vmbypid.d b/cddl/contrib/dtracetoolkit/Mem/vmbypid.d new file mode 100755 index 0000000..5160c14 --- /dev/null +++ b/cddl/contrib/dtracetoolkit/Mem/vmbypid.d @@ -0,0 +1,54 @@ +#!/usr/sbin/dtrace -s +/* + * vmbypid.d - print vminfo events by process. DTrace. + * + * $Id: vmbypid.d 8 2007-08-06 05:55:26Z brendan $ + * + * USAGE: vmbypid.d + * + * FIELDS: + * EXEC Process name + * PID Process ID + * VM Virtual Memory statistic (/usr/include/sys/sysinfo.h) + * VALUE Value by which statistic was incremented + * + * The virtual memory statistics are documented in the cpu_vminfo struct + * in the /usr/include/sys/sysinfo.h file; and also in the vminfo provider + * chapter of the DTrace Guide, http://docs.sun.com/db/doc/817-6223. + * + * 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 + * + * 14-May-2005 Brendan Gregg Created this. + * 20-Apr-2006 " " Last update. + */ + +#pragma D option quiet + +dtrace:::BEGIN +{ + printf("Tracing... Hit Ctrl-C to end.\n"); +} + +vminfo::: +{ + @VM[execname, pid, probename] = sum(arg0); +} + +dtrace:::END { + printf("%16s %8s %22s %8s\n", "EXEC", "PID", "VM", "VALUE"); + printa("%16s %8d %22s %@8d\n", @VM); +} diff --git a/cddl/contrib/dtracetoolkit/Mem/vmstat-p.d b/cddl/contrib/dtracetoolkit/Mem/vmstat-p.d new file mode 100755 index 0000000..835a0a6 --- /dev/null +++ b/cddl/contrib/dtracetoolkit/Mem/vmstat-p.d @@ -0,0 +1,155 @@ +#!/usr/sbin/dtrace -s +/* + * vmstat-p.d - vmstat -p demo in DTrace. + * Written using DTrace (Solaris 10 3/05). + * + * This has been written to demonstrate fetching similar data as vmstat + * from DTrace. This program is intended as a starting point for other + * DTrace scripts, by beginning with familiar statistics. + * + * $Id: vmstat-p.d 3 2007-08-01 10:50:08Z brendan $ + * + * USAGE: vmstat-p.d + * + * FIELDS: + * swap virtual memory free Kbytes + * free free RAM Kbytes + * re page reclaims Kbytes + * mf minor faults Kbytes + * sr scan rate pages + * epi executable page ins Kbytes + * epo executable page outs Kbytes + * epf executable frees Kbytes + * api anonymous page ins Kbytes + * apo anonymous page outs Kbytes + * apf anonymous frees Kbytes + * fpi filesystem page ins Kbytes + * fpo filesystem page outs Kbytes + * fpf filesystem frees Kbytes + * + * NOTES: + * Most of the statistics are in units of kilobytes, unlike the + * original vmstat command which sometimes uses page counts. + * 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 + * + * 11-Jun-2005 Brendan Gregg Created this. + * 08-Jan-2006 " " Last update. + */ + +#pragma D option quiet + +inline int SCREEN = 21; + +/* + * Initialise variables + */ +dtrace:::BEGIN +{ + pi = 0; po = 0; re = 0; sr = 0; mf = 0; fr = 0; + sy = 0; in = 0; cs = 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; +} + +/* + * Print header + */ +dtrace:::BEGIN, +tick-1sec +/lines++ > SCREEN/ +{ + printf("%14s %13s %16s %14s %13s\n", + "memory", "page", "executable", "anonymous", "filesystem"); + printf("%9s %7s %5s %4s %3s ", + "swap", "free", "re", "mf", "sr"); + printf("%4s %4s %4s %4s %4s %4s %4s %4s %4s\n", + "epi", "epo", "epf", "api", "apo", "apf", "fpi", "fpo", "fpf"); + lines = 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; } + +/* + * Print output line + */ +profile:::tick-1sec +{ + /* 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 Kbytes */ + epi *= `_pagesize / 1024; + epo *= `_pagesize / 1024; + epf *= `_pagesize / 1024; + api *= `_pagesize / 1024; + apo *= `_pagesize / 1024; + apf *= `_pagesize / 1024; + fpi *= `_pagesize / 1024; + fpo *= `_pagesize / 1024; + fpf *= `_pagesize / 1024; + re *= `_pagesize / 1024; + sr *= `_pagesize / 1024; + mf *= `_pagesize / 1024; + this->swap *= `_pagesize / 1024; + this->free *= `_pagesize / 1024; + + /* print line */ + printf("%9d %7d %5d %4d %3d ", + this->swap, this->free, re, mf, sr); + printf("%4d %4d %4d %4d %4d %4d %4d %4d %4d\n", + epi, epo, epf, api, apo, apf, fpi, fpo, fpf); + + /* clear counters */ + pi = 0; po = 0; re = 0; sr = 0; mf = 0; fr = 0; + sy = 0; in = 0; cs = 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; +} diff --git a/cddl/contrib/dtracetoolkit/Mem/vmstat.d b/cddl/contrib/dtracetoolkit/Mem/vmstat.d new file mode 100755 index 0000000..f8e0ead --- /dev/null +++ b/cddl/contrib/dtracetoolkit/Mem/vmstat.d @@ -0,0 +1,137 @@ +#!/usr/sbin/dtrace -s +/* + * vmstat.d - vmstat demo in DTrace. + * Written using DTrace (Solaris 10 3/05). + * + * This has been written to demonstrate fetching the same data as vmstat + * from DTrace. This program is intended as a starting point for other + * DTrace scripts, by beginning with familiar statistics. + * + * $Id: vmstat.d 8 2007-08-06 05:55:26Z brendan $ + * + * USAGE: vmstat.d + * + * FIELDS: + * w swapped out LWPs number + * swap virtual memory free Kbytes + * free free RAM Kbytes + * re page reclaims Kbytes + * mf minor faults Kbytes + * pi page ins Kbytes + * po page outs Kbytes + * fr pages freed Kbytes + * sr scan rate pages + * in interrupts number + * sy system calls number + * cs context switches number + * + * NOTES: + * Most of the statistics are in units of kilobytes, unlike the + * original vmstat command which sometimes uses page counts. + * 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 + * + * 11-Jun-2005 Brendan Gregg Created this. + * 08-Jan-2006 " " Last update. + */ + +#pragma D option quiet + +inline int SCREEN = 21; + +/* + * Initialise variables + */ +dtrace:::BEGIN +{ + pi = 0; po = 0; re = 0; sr = 0; mf = 0; fr = 0; + sy = 0; in = 0; cs = 0; + lines = SCREEN + 1; +} + +/* + * Print header + */ +dtrace:::BEGIN, +profile:::tick-1sec +/lines++ > SCREEN/ +{ + printf(" %1s %10s %8s %5s %5s %4s %4s %4s %4s %5s %6s %4s\n", + "w", "swap", "free", "re", "mf", "pi", "po", "fr", "sr", + "in", "sy", "cs"); + lines = 0; +} + +/* + * Probe events + */ +vminfo:::pgpgin { pi += arg0; } +vminfo:::pgpgout { po += arg0; } +vminfo:::pgrec { re += arg0; } +vminfo:::scan { sr += arg0; } +vminfo:::as_fault { mf += arg0; } +vminfo:::dfree { fr += arg0; } + +syscall:::entry { sy++; } +sdt:::interrupt-start { in++; } +sched::resume:on-cpu { cs++; } + +/* + * Print output line + */ +profile:::tick-1sec +{ + /* 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 Kbytes */ + pi *= `_pagesize / 1024; + po *= `_pagesize / 1024; + re *= `_pagesize / 1024; + sr *= `_pagesize / 1024; + mf *= `_pagesize / 1024; + fr *= `_pagesize / 1024; + this->swap *= `_pagesize / 1024; + this->free *= `_pagesize / 1024; + + /* print line */ + printf(" %1d %10d %8d %5d %5d %4d %4d %4d %4d %5d %6d %4d\n", + this->w, this->swap, this->free, re, mf, pi, po, fr, sr, + in, sy, cs); + + /* clear counters */ + pi = 0; po = 0; re = 0; sr = 0; mf = 0; fr = 0; + sy = 0; in = 0; cs = 0; +} diff --git a/cddl/contrib/dtracetoolkit/Mem/xvmstat b/cddl/contrib/dtracetoolkit/Mem/xvmstat new file mode 100755 index 0000000..ce13ce7 --- /dev/null +++ b/cddl/contrib/dtracetoolkit/Mem/xvmstat @@ -0,0 +1,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 3 2007-08-01 10:50:08Z brendan $ +# +# 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); + } +' |