3 # fddist - file descriptor usage distributions.
4 # Written using DTrace (Solaris 10 3/05).
6 # This prints distributions for read and write events by file descriptor,
7 # by process. This can be used to determine which file descriptor a
8 # process is doing the most I/O with.
10 # $Id: fddist 3 2007-08-01 10:50:08Z brendan $
12 # USAGE: fddist [-r|-w] # hit Ctrl-C to end sample
17 # value file descriptor
18 # count number of events
20 # BASED ON: /usr/demo/dtrace/lquantize.d
23 # DTrace Guide "Aggregations" chapter (docs.sun.com)
25 # PORTIONS: Copyright (c) 2005, 2006 Brendan Gregg.
29 # The contents of this file are subject to the terms of the
30 # Common Development and Distribution License, Version 1.0 only
31 # (the "License"). You may not use this file except in compliance
34 # You can obtain a copy of the license at Docs/cddl1.txt
35 # or http://www.opensolaris.org/os/licensing.
36 # See the License for the specific language governing permissions
37 # and limitations under the License.
41 # 09-Jun-2005 Brendan Gregg Created this.
42 # 20-Apr-2006 " " Last update.
45 ##############################
46 # --- Process Arguments ---
50 opt_read=0; opt_write=0
53 while getopts hrw name
63 fddist # default, r+w counts
64 fddist -r # read count only
69 shift `expr $OPTIND - 1`
72 if [ $opt_read -eq 0 -a $opt_write -eq 0 ]; then
73 opt_read=1; opt_write=1
77 #################################
78 # --- Main Program, DTrace ---
81 #pragma D option quiet
83 inline int OPT_read = '$opt_read';
84 inline int OPT_write = '$opt_write';
85 inline int FDMAX = 255;
91 OPT_read && OPT_write ? printf("reads and writes") : 1;
92 OPT_read && ! OPT_write ? printf("reads") : 1;
93 ! OPT_read && OPT_write ? printf("writes") : 1;
94 printf("... Hit Ctrl-C to end.\n");
101 @Count[execname, pid] = lquantize(arg0, 0, FDMAX, 1);
105 syscall::*write*:entry
108 @Count[execname, pid] = lquantize(arg0, 0, FDMAX, 1);
114 printa("EXEC: %-16s PID: %d\n%@d\n",@Count);