1#!/usr/sbin/dtrace -s 2/* 3 * rfileio.d - read file I/O stats, with cache miss rate. 4 * Written using DTrace (Solaris 10 3/05) 5 * 6 * This script provides statistics on the number of reads and the bytes 7 * read from filesystems (logical), and the number of bytes read from 8 * disk (physical). A summary is printed every five seconds by file. 9 * 10 * A total miss-rate is also provided for the file system cache. 11 * 12 * $Id: rfileio.d,v 1.1.1.1 2015/09/30 22:01:09 christos Exp $ 13 * 14 * USAGE: rfileio.d 15 * 16 * IDEA: Richard McDougall, Solaris Internals 2nd Ed, FS Chapter. 17 * 18 * COPYRIGHT: Copyright (c) 2006 Brendan Gregg. 19 * 20 * CDDL HEADER START 21 * 22 * The contents of this file are subject to the terms of the 23 * Common Development and Distribution License, Version 1.0 only 24 * (the "License"). You may not use this file except in compliance 25 * with the License. 26 * 27 * You can obtain a copy of the license at Docs/cddl1.txt 28 * or http://www.opensolaris.org/os/licensing. 29 * See the License for the specific language governing permissions 30 * and limitations under the License. 31 * 32 * CDDL HEADER END 33 * 34 * 19-Mar-2006 Brendan Gregg Created this. 35 * 23-Apr-2006 " " Last update. 36 */ 37 38#pragma D option quiet 39 40self int trace; 41uint64_t lbytes; 42uint64_t pbytes; 43 44dtrace:::BEGIN 45{ 46 trace("Tracing...\n"); 47} 48 49fbt::fop_read:entry 50/self->trace == 0 && args[0]->v_path/ 51{ 52 self->pathname = cleanpath(args[0]->v_path); 53 @rio[self->pathname, "logical"] = count(); 54 lbytes += args[1]->uio_resid; 55 self->size = args[1]->uio_resid; 56 self->uiop = args[1]; 57} 58 59fbt::fop_read:return 60/self->size/ 61{ 62 @rbytes[self->pathname, "logical"] = 63 sum(self->size - self->uiop->uio_resid); 64 self->size = 0; 65 self->uiop = 0; 66 self->pathname = 0; 67} 68 69io::bdev_strategy:start 70/self->size && args[0]->b_flags & B_READ/ 71{ 72 @rio[self->pathname, "physical"] = count(); 73 @rbytes[self->pathname, "physical"] = sum(args[0]->b_bcount); 74 pbytes += args[0]->b_bcount; 75} 76 77profile:::tick-5s 78{ 79 trunc(@rio, 20); 80 trunc(@rbytes, 20); 81 printf("\033[H\033[2J"); 82 printf("\nRead IOPS, top 20 (count)\n"); 83 printa("%-54s %10s %10@d\n", @rio); 84 printf("\nRead Bandwidth, top 20 (bytes)\n"); 85 printa("%-54s %10s %10@d\n", @rbytes); 86 printf("\nTotal File System miss-rate: %d%%\n", 87 lbytes ? 100 * pbytes / lbytes : 0); 88 trunc(@rbytes); 89 trunc(@rio); 90 lbytes = pbytes = 0; 91} 92