1N/A#!/usr/bin/sh
1N/A#
1N/A# fddist - file descriptor usage distributions.
1N/A# Written using DTrace (Solaris 10 3/05).
1N/A#
1N/A# This prints distributions for read and write events by file descriptor,
1N/A# by process. This can be used to determine which file descriptor a
1N/A# process is doing the most I/O with.
1N/A#
1N/A# $Id: fddist 3 2007-08-01 10:50:08Z brendan $
1N/A#
1N/A# USAGE: fddist [-r|-w] # hit Ctrl-C to end sample
1N/A#
1N/A# FIELDS:
1N/A# EXEC process name
1N/A# PID process ID
1N/A# value file descriptor
1N/A# count number of events
1N/A#
1N/A# BASED ON: /usr/demo/dtrace/lquantize.d
1N/A#
1N/A# SEE ALSO:
2N/A# DTrace Guide "Aggregations" chapter (docs.oracle.com)
1N/A#
1N/A# PORTIONS: Copyright (c) 2005, 2006 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# 09-Jun-2005 Brendan Gregg Created this.
1N/A# 20-Apr-2006 " " Last update.
1N/A
1N/A
1N/A##############################
1N/A# --- Process Arguments ---
1N/A#
1N/A
1N/A### Default variables
1N/Aopt_read=0; opt_write=0
1N/A
1N/A### Process options
1N/Awhile getopts hrw name
1N/Ado
1N/A case $name in
1N/A r) opt_read=1 ;;
1N/A w) opt_write=1 ;;
1N/A h|?) cat <<-END >&2
1N/A USAGE: fddist [-r|-w]
1N/A -r # reads only
1N/A -w # writes only
1N/A eg,
1N/A fddist # default, r+w counts
1N/A fddist -r # read count only
1N/A END
1N/A exit 1
1N/A esac
1N/Adone
1N/Ashift `expr $OPTIND - 1`
1N/A
1N/A### Option logic
1N/Aif [ $opt_read -eq 0 -a $opt_write -eq 0 ]; then
1N/A opt_read=1; opt_write=1
1N/Afi
1N/A
1N/A
1N/A#################################
1N/A# --- Main Program, DTrace ---
1N/A#
1N/A/usr/sbin/dtrace -n '
1N/A #pragma D option quiet
1N/A
1N/A inline int OPT_read = '$opt_read';
1N/A inline int OPT_write = '$opt_write';
1N/A inline int FDMAX = 255;
1N/A
1N/A /* print header */
1N/A dtrace:::BEGIN
1N/A {
1N/A printf("Tracing ");
1N/A OPT_read && OPT_write ? printf("reads and writes") : 1;
1N/A OPT_read && ! OPT_write ? printf("reads") : 1;
1N/A ! OPT_read && OPT_write ? printf("writes") : 1;
1N/A printf("... Hit Ctrl-C to end.\n");
1N/A }
1N/A
1N/A /* sample reads */
1N/A syscall::*read*:entry
1N/A /OPT_read/
1N/A {
1N/A @Count[execname, pid] = lquantize(arg0, 0, FDMAX, 1);
1N/A }
1N/A
1N/A /* sample writes */
1N/A syscall::*write*:entry
1N/A /OPT_write/
1N/A {
1N/A @Count[execname, pid] = lquantize(arg0, 0, FDMAX, 1);
1N/A }
1N/A
1N/A /* print report */
1N/A dtrace:::END
1N/A {
1N/A printa("EXEC: %-16s PID: %d\n%@d\n",@Count);
1N/A }
1N/A'