fddist revision 235380
1#!/usr/bin/sh 2# 3# fddist - file descriptor usage distributions. 4# Written using DTrace (Solaris 10 3/05). 5# 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. 9# 10# $Id: fddist 3 2007-08-01 10:50:08Z brendan $ 11# 12# USAGE: fddist [-r|-w] # hit Ctrl-C to end sample 13# 14# FIELDS: 15# EXEC process name 16# PID process ID 17# value file descriptor 18# count number of events 19# 20# BASED ON: /usr/demo/dtrace/lquantize.d 21# 22# SEE ALSO: 23# DTrace Guide "Aggregations" chapter (docs.sun.com) 24# 25# PORTIONS: Copyright (c) 2005, 2006 Brendan Gregg. 26# 27# CDDL HEADER START 28# 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 32# with the License. 33# 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. 38# 39# CDDL HEADER END 40# 41# 09-Jun-2005 Brendan Gregg Created this. 42# 20-Apr-2006 " " Last update. 43 44 45############################## 46# --- Process Arguments --- 47# 48 49### Default variables 50opt_read=0; opt_write=0 51 52### Process options 53while getopts hrw name 54do 55 case $name in 56 r) opt_read=1 ;; 57 w) opt_write=1 ;; 58 h|?) cat <<-END >&2 59 USAGE: fddist [-r|-w] 60 -r # reads only 61 -w # writes only 62 eg, 63 fddist # default, r+w counts 64 fddist -r # read count only 65 END 66 exit 1 67 esac 68done 69shift `expr $OPTIND - 1` 70 71### Option logic 72if [ $opt_read -eq 0 -a $opt_write -eq 0 ]; then 73 opt_read=1; opt_write=1 74fi 75 76 77################################# 78# --- Main Program, DTrace --- 79# 80/usr/sbin/dtrace -n ' 81 #pragma D option quiet 82 83 inline int OPT_read = '$opt_read'; 84 inline int OPT_write = '$opt_write'; 85 inline int FDMAX = 255; 86 87 /* print header */ 88 dtrace:::BEGIN 89 { 90 printf("Tracing "); 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"); 95 } 96 97 /* sample reads */ 98 syscall::*read*:entry 99 /OPT_read/ 100 { 101 @Count[execname, pid] = lquantize(arg0, 0, FDMAX, 1); 102 } 103 104 /* sample writes */ 105 syscall::*write*:entry 106 /OPT_write/ 107 { 108 @Count[execname, pid] = lquantize(arg0, 0, FDMAX, 1); 109 } 110 111 /* print report */ 112 dtrace:::END 113 { 114 printa("EXEC: %-16s PID: %d\n%@d\n",@Count); 115 } 116' 117