1#!/usr/sbin/dtrace -s 2/* 3 * rwbytype.d - read/write bytes by vnode type. 4 * Written using DTrace (Solaris 10 3/05). 5 * 6 * This program identifies the vnode type of read/write activity - whether 7 * that is for regular files, sockets, character special devices, etc. 8 * 9 * 20-Apr-2006, ver 0.71 (early release) 10 * 11 * USAGE: rwbytype.d # hit Ctrl-C to end sample 12 * 13 * FIELDS: 14 * PID number of rwbytype 15 * CMD process name 16 * VTYPE vnode type (describes I/O type) 17 * DIR direction (Read/Write) 18 * BYTES bytes transferred 19 * 20 * COPYRIGHT: Copyright (c) 2005, 2006 Brendan Gregg. 21 * 22 * CDDL HEADER START 23 * 24 * The contents of this file are subject to the terms of the 25 * Common Development and Distribution License, Version 1.0 only 26 * (the "License"). You may not use this file except in compliance 27 * with the License. 28 * 29 * You can obtain a copy of the license at Docs/cddl1.txt 30 * or http://www.opensolaris.org/os/licensing. 31 * See the License for the specific language governing permissions 32 * and limitations under the License. 33 * 34 * CDDL HEADER END 35 * 36 * 18-Oct-2005 Brendan Gregg Created this. 37 */ 38 39#pragma D option quiet 40 41typedef struct vtype2str { 42 string code; 43}; 44 45translator struct vtype2str < int T > { 46 /* the order has been picked for performance reasons */ 47 code = 48 T == 1 ? "reg" : 49 T == 6 ? "sock" : 50 T == 4 ? "chr" : 51 T == 7 ? "fifo" : 52 T == 2 ? "dir" : 53 T == 3 ? "blk" : 54 T == 5 ? "lnk" : 55 T == 9 ? "str" : 56 T == 10 ? "cplx" : 57 T == 8 ? "bad" : "non"; 58}; 59 60dtrace:::BEGIN 61{ 62 printf("Tracing... Hit Ctrl-C to end.\n"); 63} 64 65fbt::VNOP_READ:entry, 66fbt::VNOP_WRITE:entry 67{ 68 self->type = xlate <struct vtype2str *>(((struct vnode *)arg0)->v_type)->code; 69 self->size = ((struct uio *)arg1)->uio_resid; 70 self->uiop = (struct uio *)arg1; 71} 72 73fbt::VNOP_READ:return 74/self->uiop/ 75{ 76 this->resid = self->uiop->uio_resid; 77 @bytes[pid, execname, self->type, "R"] = sum(self->size - this->resid); 78 self->type = 0; 79 self->size = 0; 80 self->uiop = 0; 81} 82 83/* this is delibrately redundant code for performance reasons */ 84fbt::VNOP_WRITE:return 85/self->uiop/ 86{ 87 this->resid = self->uiop->uio_resid; 88 @bytes[pid, execname, self->type, "W"] = sum(self->size - this->resid); 89 self->type = 0; 90 self->size = 0; 91 self->uiop = 0; 92} 93 94dtrace:::END 95{ 96 printf("%-6s %-16s %6s %4s %9s\n", 97 "PID", "CMD", "VTYPE", "DIR", "BYTES"); 98 printa("%-6d %-16s %6s %4s %@9d\n", @bytes); 99} 100