1N/A# iopattern - print disk I/O pattern. 1N/A# Written using DTrace (Solaris 10 3/05). 1N/A# This prints details on the I/O access pattern for the disks, such as 1N/A# percentage of events that were of a random or sequential nature. 1N/A# By default totals for all disks are printed. 1N/A# $Id: iopattern 65 2007-10-04 11:09:40Z brendan $ 1N/A# USAGE: iopattern [-v] [-d device] [-f filename] [-m mount_point] 1N/A# -v # print timestamp, string 1N/A# -d device # instance name to snoop (eg, dad0) 1N/A# -f filename # full pathname of file to snoop 1N/A# -m mount_point # this FS only (will skip raw events) 1N/A# iopattern # default output, 1 second intervals 1N/A# iopattern 10 # 10 second samples 1N/A# iopattern 5 12 # print 12 x 5 second samples 1N/A# iopattern -m / # snoop events on filesystem / only 1N/A# %RAN percentage of events of a random nature 1N/A# %SEQ percentage of events of a sequential nature 1N/A# COUNT number of I/O events 1N/A# MIN minimum I/O event size 1N/A# MAX maximum I/O event size 1N/A# AVG average I/O event size 1N/A# KR total kilobytes read during sample 1N/A# KW total kilobytes written during sample 1N/A# TIME timestamp, string 1N/A# An event is considered random when the heads seek. This program prints 1N/A# the percentage of events that are random. The size of the seek is not 1N/A# measured - it's either random or not. 1N/A# SEE ALSO: iosnoop, iotop 1N/A# IDEA: Ryan Matteson 1N/A# COPYRIGHT: Copyright (c) 2005 Brendan Gregg. 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# See the License for the specific language governing permissions 1N/A# and limitations under the License. 1N/A# Author: Brendan Gregg [Sydney, Australia] 1N/A# 25-Jul-2005 Brendan Gregg Created this. 1N/A# 25-Jul-2005 " " Last update. 1N/A############################## 1N/A# --- Process Arguments --- 1N/A### default variables 1N/A USAGE: iopattern [-v] [-d device] [-f filename] [-m mount_point] 1N/A -v # print timestamp 1N/A -d device # instance name to snoop 1N/A -f filename # snoop this file only 1N/A -m mount_point # this FS only 1N/A iopattern # default output, 1 second samples 1N/A iopattern 10 # 10 second samples 1N/A iopattern 5 12 # print 12 x 5 second samples 1N/A iopattern -m / # snoop events on filesystem / only 1N/Ashift $(( $OPTIND - 1 )) 1N/Aif [[ "$1" > 0 ]]; then 1N/Aif [[ "$1" > 0 ]]; then 1N/Aif (( opt_device || opt_mount || opt_file )); then 1N/A################################# 1N/A# --- Main Program, DTrace --- 1N/A/usr/sbin/dtrace -n ' 1N/A * Command line arguments 1N/A inline int OPT_time = '$opt_time'; 1N/A inline int OPT_device = '$opt_device'; 1N/A inline int OPT_mount = '$opt_mount'; 1N/A inline int OPT_file = '$opt_file'; 1N/A inline int INTERVAL = '$interval'; 1N/A inline int COUNTER = '$count'; 1N/A inline int FILTER = '$filter'; 1N/A inline string DEVICE = "'$device'"; 1N/A inline string FILENAME = "'$filename'"; 1N/A inline string MOUNT = "'$mount'"; 1N/A #pragma D option quiet 1N/A int last_loc[string]; 1N/A /* starting values */ 1N/A /* print optional headers */ 1N/A OPT_time ? printf("%-20s ", "TIME") : 1; 1N/A OPT_device ? printf("%-9s ", "DEVICE") : 1; 1N/A OPT_mount ? printf("%-12s ", "MOUNT") : 1; 1N/A OPT_file ? printf("%-12s ", "FILE") : 1; 1N/A printf("%4s %4s %6s %6s %6s %6s %6s %6s\n", 1N/A "%RAN", "%SEQ", "COUNT", "MIN", "MAX", "AVG", "KR", "KW"); 1N/A * Check event is being traced 1N/A /* default is to trace unless filtering */ 1N/A self->ok = FILTER ? 0 : 1; 1N/A /* check each filter */ 1N/A (OPT_device == 1 && DEVICE == args[1]->dev_statname)? self->ok = 1 : 1; 1N/A (OPT_file == 1 && FILENAME == args[2]->fi_pathname) ? self->ok = 1 : 1; 1N/A (OPT_mount == 1 && MOUNT == args[2]->fi_mount) ? self->ok = 1 : 1; 1N/A * Process and Print completion 1N/A this->loc = args[0]->b_blkno * 512; 1N/A this->pre = last_loc[args[1]->dev_statname]; 1N/A diskr += args[0]->b_flags & B_READ ? args[0]->b_bcount : 0; 1N/A diskw += args[0]->b_flags & B_READ ? 0 : args[0]->b_bcount; 1N/A diskran += this->pre == this->loc ? 0 : 1; 1N/A diskmin = diskmin == 0 ? args[0]->b_bcount : 1N/A (diskmin > args[0]->b_bcount ? args[0]->b_bcount : diskmin); 1N/A diskmax = diskmax < args[0]->b_bcount ? args[0]->b_bcount : diskmax; 1N/A /* save disk location */ 1N/A last_loc[args[1]->dev_statname] = this->loc + args[0]->b_bcount; 1N/A /* calculate diskavg */ 1N/A diskavg = diskcnt > 0 ? (diskr + diskw) / diskcnt : 0; 1N/A /* convert counters to Kbytes */ 1N/A /* convert to percentages */ 1N/A diskran = diskcnt == 0 ? 0 : (diskran * 100) / diskcnt; 1N/A diskseq = diskcnt == 0 ? 0 : 100 - diskran; 1N/A /* print optional fields */ 1N/A OPT_time ? printf("%-20Y ", walltimestamp) : 1; 1N/A OPT_device ? printf("%-9s ", DEVICE) : 1; 1N/A OPT_mount ? printf("%-12s ", MOUNT) : 1; 1N/A OPT_file ? printf("%-12s ", FILENAME) : 1; 1N/A printf("%4d %4d %6d %6d %6d %6d %6d %6d\n", 1N/A diskran, diskseq, diskcnt, diskmin, diskmax, diskavg,