fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte# iopattern - print disk I/O pattern.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte# Written using DTrace (Solaris 10 3/05).
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte# This prints details on the I/O access pattern for the disks, such as
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte# percentage of events that were of a random or sequential nature.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte# By default totals for all disks are printed.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte# $Id: iopattern 65 2007-10-04 11:09:40Z brendan $
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte# USAGE: iopattern [-v] [-d device] [-f filename] [-m mount_point]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte# [interval [count]]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte# -v # print timestamp, string
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte# -d device # instance name to snoop (eg, dad0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte# -f filename # full pathname of file to snoop
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte# -m mount_point # this FS only (will skip raw events)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte# iopattern # default output, 1 second intervals
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte# iopattern 10 # 10 second samples
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte# iopattern 5 12 # print 12 x 5 second samples
a9ccff55d0a73a9d1d9011f705b910fba0f6e989bing zhao - Sun Microsystems - Beijing China# iopattern -m / # snoop events on filesystem / only
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte# %RAN percentage of events of a random nature
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte# %SEQ percentage of events of a sequential nature
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte# COUNT number of I/O events
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte# MIN minimum I/O event size
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte# MAX maximum I/O event size
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte# AVG average I/O event size
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte# KR total kilobytes read during sample
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte# KW total kilobytes written during sample
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte# DEVICE device name
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte# MOUNT mount point
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte# FILE filename
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte# TIME timestamp, string
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte# An event is considered random when the heads seek. This program prints
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte# the percentage of events that are random. The size of the seek is not
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte# measured - it's either random or not.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte# SEE ALSO: iosnoop, iotop
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte# IDEA: Ryan Matteson
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte# COPYRIGHT: Copyright (c) 2005 Brendan Gregg.
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap# CDDL HEADER START
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte# The contents of this file are subject to the terms of the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte# Common Development and Distribution License, Version 1.0 only
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap# (the "License"). You may not use this file except in compliance
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap# with the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte# You can obtain a copy of the license at Docs/cddl1.txt
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte# See the License for the specific language governing permissions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte# and limitations under the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte# CDDL HEADER END
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte# Author: Brendan Gregg [Sydney, Australia]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte# 25-Jul-2005 Brendan Gregg Created this.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte# 25-Jul-2005 " " Last update.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte##############################
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap# --- Process Arguments ---
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap### default variables
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlapopt_device=0; opt_file=0; opt_mount=0; opt_time=0
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlapfilter=0; device=.; filename=.; mount=.; interval=1; count=-1
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap### process options
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte USAGE: iopattern [-v] [-d device] [-f filename] [-m mount_point]
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap [interval [count]]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte -v # print timestamp
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte -d device # instance name to snoop
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte -f filename # snoop this file only
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte -m mount_point # this FS only
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iopattern # default output, 1 second samples
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iopattern 10 # 10 second samples
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iopattern 5 12 # print 12 x 5 second samples
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iopattern -m / # snoop events on filesystem / only
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteshift $(( $OPTIND - 1 ))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte### option logic
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteif [[ "$1" > 0 ]]; then
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte interval=$1; shift
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteif [[ "$1" > 0 ]]; then
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte count=$1; shift
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteif (( opt_device || opt_mount || opt_file )); then
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China#################################
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte# --- Main Program, DTrace ---
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/usr/sbin/dtrace -n '
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Command line arguments
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte inline int OPT_time = '$opt_time';
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte inline int OPT_device = '$opt_device';
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte inline int OPT_mount = '$opt_mount';
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte inline int OPT_file = '$opt_file';
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte inline int INTERVAL = '$interval';
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte inline int COUNTER = '$count';
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte inline int FILTER = '$filter';
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte inline string DEVICE = "'$device'";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte inline string FILENAME = "'$filename'";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte inline string MOUNT = "'$mount'";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte #pragma D option quiet
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int last_loc[string];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Program start
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dtrace:::BEGIN
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* starting values */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte diskcnt = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte diskmin = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte diskmax = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte diskran = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte counts = COUNTER;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte secs = INTERVAL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte last_event[""] = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Print header
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte profile:::tick-1sec
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /line <= 0 /
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* print optional headers */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte OPT_time ? printf("%-20s ", "TIME") : 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte OPT_device ? printf("%-9s ", "DEVICE") : 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte OPT_mount ? printf("%-12s ", "MOUNT") : 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte OPT_file ? printf("%-12s ", "FILE") : 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* print header */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte printf("%4s %4s %6s %6s %6s %6s %6s %6s\n",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "%RAN", "%SEQ", "COUNT", "MIN", "MAX", "AVG", "KR", "KW");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte line = LINES;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Check event is being traced
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte io:genunix::done
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* default is to trace unless filtering */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte self->ok = FILTER ? 0 : 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* check each filter */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (OPT_device == 1 && DEVICE == args[1]->dev_statname)? self->ok = 1 : 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (OPT_file == 1 && FILENAME == args[2]->fi_pathname) ? self->ok = 1 : 1;
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap (OPT_mount == 1 && MOUNT == args[2]->fi_mount) ? self->ok = 1 : 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Process and Print completion
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte io:genunix::done
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Save details
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte this->loc = args[0]->b_blkno * 512;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte this->pre = last_loc[args[1]->dev_statname];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte diskr += args[0]->b_flags & B_READ ? args[0]->b_bcount : 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte diskw += args[0]->b_flags & B_READ ? 0 : args[0]->b_bcount;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte diskran += this->pre == this->loc ? 0 : 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte diskmin = diskmin == 0 ? args[0]->b_bcount :
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (diskmin > args[0]->b_bcount ? args[0]->b_bcount : diskmin);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte diskmax = diskmax < args[0]->b_bcount ? args[0]->b_bcount : diskmax;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* save disk location */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte last_loc[args[1]->dev_statname] = this->loc + args[0]->b_bcount;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* cleanup */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte self->ok = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte profile:::tick-1sec
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Print Output
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte profile:::tick-1sec
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* calculate diskavg */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte diskavg = diskcnt > 0 ? (diskr + diskw) / diskcnt : 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* convert counters to Kbytes */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte diskr /= 1024;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte diskw /= 1024;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* convert to percentages */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte diskran = diskcnt == 0 ? 0 : (diskran * 100) / diskcnt;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte diskseq = diskcnt == 0 ? 0 : 100 - diskran;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng /* print optional fields */
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng OPT_time ? printf("%-20Y ", walltimestamp) : 1;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng OPT_device ? printf("%-9s ", DEVICE) : 1;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng OPT_mount ? printf("%-12s ", MOUNT) : 1;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng OPT_file ? printf("%-12s ", FILENAME) : 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* print data */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte printf("%4d %4d %6d %6d %6d %6d %6d %6d\n",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte diskran, diskseq, diskcnt, diskmin, diskmax, diskavg,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte diskr, diskw);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* clear data */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte diskmin = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte diskmax = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte diskcnt = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte diskran = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte secs = INTERVAL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * End of program
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte profile:::tick-1sec
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /counts == 0/