seeksize.d revision 1
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#!/usr/sbin/dtrace -s
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * seeksize.d - analyse disk head seek distance by process.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Written using DTrace (Solaris 10 3/05).
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Disk I/O events caused by processes will in turn cause the disk heads
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * to seek. This program analyses those seeks, so that we can determine
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if processes are causing the disks to seek in a "random" or "sequential"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * manner.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * $Id: seeksize.d 3 2007-08-01 10:50:08Z brendan $
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * USAGE: seeksize.d # wait several seconds, then hit Ctrl-C
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * FIELDS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * PID process ID
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CMD command and argument list
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * value distance in disk blocks (sectors)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * count number of I/O operations
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * SEE ALSO: bitesize.d, iosnoop
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * COPYRIGHT: Copyright (c) 2006 Brendan Gregg.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER START
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
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
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * (the "License"). You may not use this file except in compliance
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * with the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You can obtain a copy of the license at Docs/cddl1.txt
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or http://www.opensolaris.org/os/licensing.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See the License for the specific language governing permissions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and limitations under the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER END
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 11-Sep-2004 Brendan Gregg Created this.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 10-Oct-2004 " " Rewrote to use the io provider.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 20-Apr-2006 " " Last update.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#pragma D option quiet
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Print header
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortedtrace:::BEGIN
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte printf("Tracing... Hit Ctrl-C to end.\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteself int last[dev_t];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Process io start
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteio:genunix::start
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/self->last[args[0]->b_edev] != 0/
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* calculate seek distance */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte this->last = self->last[args[0]->b_edev];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte this->dist = (int)(args[0]->b_blkno - this->last) > 0 ?
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte args[0]->b_blkno - this->last : this->last - args[0]->b_blkno;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* store details */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte @Size[pid, curpsinfo->pr_psargs] = quantize(this->dist);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteio:genunix::start
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* save last position of disk head */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte self->last[args[0]->b_edev] = args[0]->b_blkno +
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte args[0]->b_bcount / 512;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Print final report
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortedtrace:::END
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte printf("\n%8s %s\n", "PID", "CMD");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte printa("%8d %S\n%@d\n", @Size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte