rwbbypid.d revision 235368
1235368Sgnn#!/usr/sbin/dtrace -s 2235368Sgnn/* 3235368Sgnn * rwbbypid.d - read/write bytes by PID. 4235368Sgnn * Written using DTrace (Solaris 10 3/05) 5235368Sgnn * 6235368Sgnn * This script tracks the bytes read and written at the syscall level 7235368Sgnn * by processes, printing the totals in a report. This is tracking the 8235368Sgnn * successful number of bytes read or written. 9235368Sgnn * 10235368Sgnn * $Id: rwbbypid.d 3 2007-08-01 10:50:08Z brendan $ 11235368Sgnn * 12235368Sgnn * USAGE: rwbbypid.d # hit Ctrl-C to end sample 13235368Sgnn * 14235368Sgnn * FIELDS: 15235368Sgnn * PID process ID 16235368Sgnn * CMD process name 17235368Sgnn * DIR direction, Read or Write 18235368Sgnn * BYTES total bytes 19235368Sgnn * 20235368Sgnn * COPYRIGHT: Copyright (c) 2005, 2006 Brendan Gregg. 21235368Sgnn * 22235368Sgnn * CDDL HEADER START 23235368Sgnn * 24235368Sgnn * The contents of this file are subject to the terms of the 25235368Sgnn * Common Development and Distribution License, Version 1.0 only 26235368Sgnn * (the "License"). You may not use this file except in compliance 27235368Sgnn * with the License. 28235368Sgnn * 29235368Sgnn * You can obtain a copy of the license at Docs/cddl1.txt 30235368Sgnn * or http://www.opensolaris.org/os/licensing. 31235368Sgnn * See the License for the specific language governing permissions 32235368Sgnn * and limitations under the License. 33235368Sgnn * 34235368Sgnn * CDDL HEADER END 35235368Sgnn * 36235368Sgnn * 28-Jun-2005 Brendan Gregg Created this. 37235368Sgnn * 20-Apr-2006 " " Last update. 38235368Sgnn */ 39235368Sgnn 40235368Sgnn#pragma D option quiet 41235368Sgnn 42235368Sgnndtrace:::BEGIN 43235368Sgnn{ 44235368Sgnn printf("Tracing... Hit Ctrl-C to end.\n"); 45235368Sgnn} 46235368Sgnn 47235368Sgnnsysinfo:::readch 48235368Sgnn{ 49235368Sgnn @bytes[pid, execname, "R"] = sum(arg0); 50235368Sgnn} 51235368Sgnn 52235368Sgnnsysinfo:::writech 53235368Sgnn{ 54235368Sgnn @bytes[pid, execname, "W"] = sum(arg0); 55235368Sgnn} 56235368Sgnn 57235368Sgnndtrace:::END 58235368Sgnn{ 59235368Sgnn printf("%6s %-24s %4s %16s\n", "PID", "CMD", "DIR", "BYTES"); 60235368Sgnn printa("%6d %-24s %4s %@16d\n", @bytes); 61235368Sgnn} 62