1N/A#!/usr/sbin/dtrace -s
1N/A/*
1N/A * rwbytype.d - read/write bytes by vnode type.
1N/A * Written using DTrace (Solaris 10 3/05).
1N/A *
1N/A * This program identifies the vnode type of read/write activity - whether
1N/A * that is for regular files, sockets, character special devices, etc.
1N/A *
1N/A * $Id: rwbytype.d 3 2007-08-01 10:50:08Z brendan $
1N/A *
1N/A * USAGE: rwbytype.d # hit Ctrl-C to end sample
1N/A *
1N/A * FIELDS:
1N/A * PID number of rwbytype
1N/A * CMD process name
1N/A * VTYPE vnode type (describes I/O type)
1N/A * DIR direction (Read/Write)
1N/A * BYTES bytes transferred
1N/A *
1N/A * COPYRIGHT: 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 * 18-Oct-2005 Brendan Gregg Created this.
1N/A * 20-Apr-2006 " " Last update.
1N/A */
1N/A
1N/A#pragma D option quiet
1N/A
1N/Atypedef struct vtype2str {
1N/A string code;
1N/A};
1N/A
1N/Atranslator struct vtype2str < int T > {
1N/A /* the order has been picked for performance reasons */
1N/A code =
1N/A T == 1 ? "reg" :
1N/A T == 9 ? "sock" :
1N/A T == 4 ? "chr" :
1N/A T == 6 ? "fifo" :
1N/A T == 8 ? "proc" :
1N/A T == 2 ? "dir" :
1N/A T == 3 ? "blk" :
1N/A T == 5 ? "lnk" :
1N/A T == 7 ? "door" :
1N/A T == 10 ? "port" :
1N/A T == 11 ? "bad" : "non";
1N/A};
1N/A
1N/Adtrace:::BEGIN
1N/A{
1N/A printf("Tracing... Hit Ctrl-C to end.\n");
1N/A}
1N/A
1N/Afbt::fop_read:entry,
1N/Afbt::fop_write:entry
1N/A{
1N/A self->type = xlate <struct vtype2str *>(args[0]->v_type)->code;
1N/A self->size = args[1]->uio_resid;
1N/A self->uiop = args[1];
1N/A}
1N/A
1N/Afbt::fop_read:return
1N/A/self->uiop/
1N/A{
1N/A this->resid = self->uiop->uio_resid;
1N/A @bytes[pid, execname, self->type, "R"] = sum(self->size - this->resid);
1N/A self->type = 0;
1N/A self->size = 0;
1N/A self->uiop = 0;
1N/A}
1N/A
1N/A/* this is delibrately redundant code for performance reasons */
1N/Afbt::fop_write:return
1N/A/self->uiop/
1N/A{
1N/A this->resid = self->uiop->uio_resid;
1N/A @bytes[pid, execname, self->type, "W"] = sum(self->size - this->resid);
1N/A self->type = 0;
1N/A self->size = 0;
1N/A self->uiop = 0;
1N/A}
1N/A
1N/Adtrace:::END
1N/A{
1N/A printf("%-6s %-16s %6s %4s %9s\n",
1N/A "PID", "CMD", "VTYPE", "DIR", "BYTES");
1N/A printa("%-6d %-16s %6s %4s %@9d\n", @bytes);
1N/A}