3 # dvmstat - vmstat by PID/name/command.
4 # Written using DTrace (Solaris 10 3/05).
6 # This program provides vmstat like data for one particular PID, a
7 # process name, or when running a command. It prints statistics
10 # $Id: dvmstat 3 2007-08-01 10:50:08Z brendan $
12 # USAGE: dvmstat { -p PID | -n name | command }
14 # dvmstat -p 1871 # examine PID 1871
15 # dvmstat -n tar # examine processes called "tar"
16 # dvmstat df -h # run and examine "df -h"
19 # re page reclaims Kbytes
20 # maj major faults Kbytes
21 # mf minor faults Kbytes
22 # fr page frees Kbytes
23 # epi executable page ins Kbytes
24 # epo executable page out Kbytes
25 # api anonymous page ins Kbytes
26 # apo anonymous page outs Kbytes
27 # fpi filesystem page ins Kbytes
28 # fpo filesystem page outs Kbytes
29 # sy system calls number
31 # SEE ALSO: vmstat(1M)
35 # When using dvmstat to run a command - if the command takes some time
36 # to execute, dvmstat will print output every second. If the command runs
37 # in less than a second, then the only one line of output will be printed.
39 # COPYRIGHT: Copyright (c) 2005 Brendan Gregg.
43 # The contents of this file are subject to the terms of the
44 # Common Development and Distribution License, Version 1.0 only
45 # (the "License"). You may not use this file except in compliance
48 # You can obtain a copy of the license at Docs/cddl1.txt
49 # or http://www.opensolaris.org/os/licensing.
50 # See the License for the specific language governing permissions
51 # and limitations under the License.
55 # Author: Brendan Gregg [Sydney, Australia]
57 # 12-Jun-2005 Brendan Gregg Created this.
58 # 08-Jan-2006 " " Last update.
61 ##############################
62 # --- Process Arguments ---
66 opt_pid=0; opt_name=0; pid=0; pname="."; opt_command=0; command=""
69 while getopts hn:p: name
72 p) opt_pid=1; pid=$OPTARG ;;
73 n) opt_name=1; pname=$OPTARG ;;
75 USAGE: dvmstat [-h] { -p PID | -n name | command }
76 -p PID # examine this PID
77 -n name # examine this process name
79 dvmstat -p 1871 # examine PID 1871
80 dvmstat -n tar # examine processes called "tar"
81 dvmstat df -h # run and examine "df -h"
86 shift `expr $OPTIND - 1`
90 if [ $opt_pid -eq 0 -a $opt_name -eq 0 ]; then
92 if [ "$*" = "" ]; then
100 #################################
101 # --- Main Program, DTrace ---
104 #pragma D option quiet
107 * Command line arguments
109 inline int OPT_pid = '$opt_pid';
110 inline int OPT_name = '$opt_name';
111 inline int OPT_command = '$opt_command';
112 inline int PID = '$pid';
113 inline string NAME = "'$pname'";
114 inline string COMMAND = "'$command'";
115 inline int SCREEN = 21;
118 * Initialise variables
122 epi = 0; epo = 0; api = 0; apo = 0; fpi = 0; fpo = 0;
123 re = 0; mf = 0; maj = 0; fr = 0; sy = 0;
134 /(OPT_command && probename == "END") ||
135 (!(OPT_command && probename == "BEGIN") && lines++ > SCREEN)/
137 printf("%6s %5s %5s %4s %4s %4s %4s %4s %4s %4s %6s\n",
138 "re", "maj", "mf", "fr", "epi", "epo", "api", "apo",
146 * this intentionally does not use an associative array for storing data,
147 * for reasons of performance.
151 /(OPT_pid && pid == PID) ||
152 (OPT_name && execname == NAME) ||
153 (OPT_command && pid == $target)/
157 /(OPT_pid && pid == PID) ||
158 (OPT_name && execname == NAME) ||
159 (OPT_command && pid == $target)/
163 /(OPT_pid && pid == PID) ||
164 (OPT_name && execname == NAME) ||
165 (OPT_command && pid == $target)/
169 /(OPT_pid && pid == PID) ||
170 (OPT_name && execname == NAME) ||
171 (OPT_command && pid == $target)/
175 /(OPT_pid && pid == PID) ||
176 (OPT_name && execname == NAME) ||
177 (OPT_command && pid == $target)/
181 /(OPT_pid && pid == PID) ||
182 (OPT_name && execname == NAME) ||
183 (OPT_command && pid == $target)/
187 /(OPT_pid && pid == PID) ||
188 (OPT_name && execname == NAME) ||
189 (OPT_command && pid == $target)/
193 /(OPT_pid && pid == PID) ||
194 (OPT_name && execname == NAME) ||
195 (OPT_command && pid == $target)/
199 /(OPT_pid && pid == PID) ||
200 (OPT_name && execname == NAME) ||
201 (OPT_command && pid == $target)/
205 /(OPT_pid && pid == PID) ||
206 (OPT_name && execname == NAME) ||
207 (OPT_command && pid == $target)/
211 /(OPT_pid && pid == PID) ||
212 (OPT_name && execname == NAME) ||
213 (OPT_command && pid == $target)/
222 /* convert to Kbytes */
223 re *= `_pagesize / 1024;
224 maj *= `_pagesize / 1024;
225 mf *= `_pagesize / 1024;
226 fr *= `_pagesize / 1024;
227 epi *= `_pagesize / 1024;
228 epo *= `_pagesize / 1024;
229 api *= `_pagesize / 1024;
230 apo *= `_pagesize / 1024;
231 fpi *= `_pagesize / 1024;
232 fpo *= `_pagesize / 1024;
235 printf("%6d %5d %5d %4d %4d %4d %4d %4d %4d %4d %6d\n",
236 re, maj, mf, fr, epi, epo, api, apo, fpi, fpo, sy);
239 epi = 0; epo = 0; api = 0; apo = 0; fpi = 0; fpo = 0;
240 re = 0; mf = 0; maj = 0; fr = 0; sy = 0;
245 if [ $opt_command -eq 1 ]; then
246 /usr/sbin/dtrace -n "$dtrace" -x evaltime=exec -c "$command" >&2
248 /usr/sbin/dtrace -n "$dtrace" >&2