1N/A#!/usr/sbin/dtrace -s
1N/A/*
1N/A * fsrw.d - file system read/write event tracing.
1N/A * Written using DTrace (Solaris 10 3/05)
1N/A *
1N/A * This traces file related activity: system call reads and writes,
1N/A * vnode logical read and writes (fop), and disk I/O. It can be used
1N/A * to examine the behaviour of each I/O layer, from the syscall
1N/A * interface to what the disk is doing. Behaviour such as read-ahead, and
1N/A * max I/O size breakup can be observed.
1N/A *
1N/A * $Id: fsrw.d 3 2007-08-01 10:50:08Z brendan $
1N/A *
1N/A * USAGE: fsrw.d
1N/A *
1N/A * FIELDS:
1N/A * Event Traced event (see EVENTS below)
1N/A * Device Device, for disk I/O
1N/A * RW Either Read or Write
1N/A * Size Size of I/O in bytes
1N/A * Offset Offset of I/O in kilobytes
1N/A * Path Path to file on disk
1N/A *
1N/A * EVENTS:
1N/A * sc-read System call read
1N/A * sc-write System call write
1N/A * fop_read Logical read
1N/A * fop_write Logical write
1N/A * disk_io Physical disk I/O
1N/A * disk_ra Physical disk I/O, read ahead
1N/A *
1N/A * The events are drawn with a level of indentation, which can sometimes
1N/A * help identify related events.
1N/A *
1N/A * SEE ALSO: fspaging.d
1N/A *
1N/A * IDEA: Richard McDougall, Solaris Internals 2nd Ed, FS Chapter.
1N/A *
1N/A * COPYRIGHT: Copyright (c) 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 * ToDo: readv()
1N/A *
1N/A * 20-Mar-2006 Brendan Gregg Created this.
1N/A * 23-Apr-2006 " " Last update.
1N/A */
1N/A
1N/A#pragma D option quiet
1N/A#pragma D option switchrate=10hz
1N/A
1N/Adtrace:::BEGIN
1N/A{
1N/A printf("%-12s %10s %2s %8s %6s %s\n",
1N/A "Event", "Device", "RW", "Size", "Offset", "Path");
1N/A}
1N/A
1N/Asyscall::*read:entry,
1N/Asyscall::*write*:entry
1N/A{
1N/A /*
1N/A * starting with a file descriptior, dig out useful info
1N/A * from the corresponding file_t and vnode_t.
1N/A */
1N/A this->filistp = curthread->t_procp->p_user.u_finfo.fi_list;
1N/A this->ufentryp = (uf_entry_t *)((uint64_t)this->filistp +
1N/A (uint64_t)arg0 * (uint64_t)sizeof (uf_entry_t));
1N/A this->filep = this->ufentryp->uf_file;
1N/A self->offset = this->filep->f_offset;
1N/A this->vnodep = this->filep != 0 ? this->filep->f_vnode : 0;
1N/A self->vpath = this->vnodep ? (this->vnodep->v_path != 0 ?
1N/A cleanpath(this->vnodep->v_path) : "<unknown>") : "<unknown>";
1N/A
1N/A /* only trace activity to regular files and directories, as */
1N/A self->sc_trace = this->vnodep ? this->vnodep->v_type == VREG ||
1N/A this->vnodep->v_type == VDIR ? 1 : 0 : 0;
1N/A}
1N/A
1N/Asyscall::*read:entry
1N/A/self->sc_trace/
1N/A{
1N/A printf("sc-%-9s %10s %2s %8d %6d %s\n", probefunc, ".", "R",
1N/A (int)arg2, self->offset / 1024, self->vpath);
1N/A}
1N/A
1N/Asyscall::*write*:entry
1N/A/self->sc_trace/
1N/A{
1N/A printf("sc-%-9s %10s %2s %8d %6d %s\n", probefunc, ".", "W",
1N/A (int)arg2, self->offset / 1024, self->vpath);
1N/A}
1N/A
1N/Asyscall::*read:return,
1N/Asyscall::*write*:return
1N/A{
1N/A self->vpath = 0;
1N/A self->offset = 0;
1N/A self->sc_trace = 0;
1N/A}
1N/A
1N/Afbt::fop_read:entry,
1N/Afbt::fop_write:entry
1N/A/self->sc_trace && args[0]->v_path/
1N/A{
1N/A printf(" %-10s %10s %2s %8d %6d %s\n", probefunc, ".",
1N/A probefunc == "fop_read" ? "R" : "W", args[1]->uio_resid,
1N/A args[1]->_uio_offset._f / 1024, cleanpath(args[0]->v_path));
1N/A}
1N/A
1N/Afbt:ufs:ufs_getpage_ra:entry
1N/A{
1N/A /* fetch the real offset (file_t is unaware of this) */
1N/A self->ra_offset = ((inode_t *)args[0]->v_data)->i_nextrio;
1N/A self->read_ahead = 1;
1N/A}
1N/A
1N/Afbt:ufs:ufs_getpage_ra:return
1N/A{
1N/A self->read_ahead = 0;
1N/A self->ra_offset = 0;
1N/A}
1N/A
1N/Aio::bdev_strategy:start
1N/A{
1N/A this->offset = self->read_ahead ? self->ra_offset : args[2]->fi_offset;
1N/A printf(" %-8s %10s %2s %8d %6d %s\n",
1N/A self->read_ahead ? "disk_ra" : "disk_io", args[1]->dev_statname,
1N/A args[0]->b_flags & B_READ ? "R" : "W", args[0]->b_bcount,
1N/A this->offset / 1024, args[2]->fi_pathname);
1N/A /*
1N/A * it would seem to make sense to only trace disk events during
1N/A * an fop event, easily coded with a self->fop_trace flag. However
1N/A * writes are asynchronous to the fop_write calls (they are flushed
1N/A * at some later time), and so this approach will miss tracing
1N/A * most of the disk writes.
1N/A */
1N/A}