1N/A# Written using DTrace (Solaris 10 3/05). 1N/A# This is measuring reads and writes at the application level. This matches 1N/A# read and write system calls. 1N/A# $Id: rwtop 3 2007-08-01 10:50:08Z brendan $ 1N/A# USAGE: rwtop [-cC] [-j|-Z] [-n name] [-p pid] 1N/A# [-t top] [interval [count]] 1N/A# rwtop # default output, 5 second samples 1N/A# -C # don't clear the screen 1N/A# -j # print project ID 1N/A# -n name # this process name only 1N/A# -p PID # this PID only 1N/A# -t top # print top number only 1N/A# rwtop 1 # 1 second samples 1N/A# rwtop -t 10 # print top 10 only 1N/A# rwtop -n bash # monitor processes named "bash" 1N/A# rwtop -C 5 12 # print 12 x 5 second samples 1N/A# PPID Parent Process ID 1N/A# D Direction, Read or Write 1N/A# BYTES Total bytes during sample 1N/A# app_r total reads during sample, Kbytes 1N/A# app_w total writes during sample, Kbytes 1N/A# INSPIRATION: top(1) by William LeFebvre 1N/A# COPYRIGHT: Copyright (c) 2005, 2006 Brendan Gregg. 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# See the License for the specific language governing permissions 1N/A# and limitations under the License. 1N/A# Author: Brendan Gregg [Sydney, Australia] 1N/A# 24-Jul-2005 Brendan Gregg Created this. 1N/A# 20-Apr-2006 " " Last update. 1N/A############################## 1N/A# --- Process Arguments --- 1N/A### default variables 1N/A USAGE: rwtop [-cC] [-j|-Z] [-n name] [-p pid] 1N/A [-t top] [interval [count]] 1N/A -C # don't clear the screen 1N/A -j # print project ID 1N/A -n name # this process name only 1N/A -p PID # this PID only 1N/A -t top # print top number only 1N/A rwtop # default output, 5 second samples 1N/A rwtop 1 # 1 second samples 1N/A rwtop -t 10 # print top 10 only 1N/A rwtop -n bash # monitor processes named "bash" 1N/A rwtop -C 5 12 # print 12 x 5 second samples 1N/Ashift $(( $OPTIND - 1 )) 1N/Aif [[ "$1" > 0 ]]; then 1N/Aif [[ "$1" > 0 ]]; then 1N/Aif (( opt_proj && opt_zone )); then 1N/Aif (( opt_name || opt_pid )); then 1N/Aif (( opt_clear )); then 1N/A################################# 1N/A# --- Main Program, DTrace --- 1N/A/usr/sbin/dtrace -n ' 1N/A * Command line arguments 1N/A inline int OPT_def = '$opt_def'; 1N/A inline int OPT_proj = '$opt_proj'; 1N/A inline int OPT_zone = '$opt_zone'; 1N/A inline int OPT_clear = '$opt_clear'; 1N/A inline int OPT_bytes = '$opt_bytes'; 1N/A inline int OPT_count = '$opt_count'; 1N/A inline int OPT_name = '$opt_name'; 1N/A inline int OPT_pid = '$opt_pid'; 1N/A inline int OPT_top = '$opt_top'; 1N/A inline int INTERVAL = '$interval'; 1N/A inline int COUNTER = '$count'; 1N/A inline int FILTER = '$filter'; 1N/A inline int TOP = '$top'; 1N/A inline int PID = '$pid'; 1N/A inline string NAME = "'$pname'"; 1N/A inline string CLEAR = "'$clearstr'"; 1N/A #pragma D option quiet 1N/A /* starting values */ 1N/A printf("Tracing... Please wait.\n"); 1N/A * Check event is being traced 1N/A /* default is to trace unless filtering, */ 1N/A this->ok = FILTER ? 0 : 1; 1N/A /* check each filter, */ 1N/A (OPT_name == 1 && NAME == execname)? this->ok = 1 : 1; 1N/A (OPT_pid == 1 && PID == pid) ? this->ok = 1 : 1; 1N/A /* choose statistic to track */ 1N/A this->value = OPT_bytes ? arg0 : 1; 1N/A OPT_def ? @out[uid, pid, ppid, execname, 1N/A probename == "readch" ? "R" : "W"] = sum(this->value) : 1; 1N/A OPT_proj ? @out[curpsinfo->pr_projid, pid, ppid, execname, 1N/A probename == "readch" ? "R" : "W"] = sum(this->value) : 1; 1N/A OPT_zone ? @out[curpsinfo->pr_zoneid, pid, ppid, execname, 1N/A probename == "readch" ? "R" : "W"] = sum(this->value) : 1; 1N/A /* fetch 1 min load average */ 1N/A this->load1a = `hp_avenrun[0] / 65536; 1N/A this->load1b = ((`hp_avenrun[0] % 65536) * 100) / 65536; 1N/A /* convert counters to Kbytes */ 1N/A OPT_clear ? printf("%s", CLEAR) : 1; 1N/A printf("%Y, load: %d.%02d, app_r: %6d KB, app_w: %6d KB\n\n", 1N/A walltimestamp, this->load1a, this->load1b, app_r, app_w); 1N/A OPT_def ? printf(" UID ") : 1; 1N/A OPT_proj ? printf(" PROJ ") : 1; 1N/A OPT_zone ? printf(" ZONE ") : 1; 1N/A printf("%6s %6s %-16s %1s", 1N/A "PID", "PPID", "CMD", "D"); 1N/A OPT_bytes ? printf(" %16s\n", "BYTES") : 1; 1N/A OPT_count ? printf(" %16s\n", "COUNT") : 1; 1N/A /* truncate to top lines if needed */ 1N/A OPT_top ? trunc(@out, TOP) : 1; 1N/A printa("%5d %6d %6d %-16s %1s %16@d\n", @out); 1N/A * Cleanup for Ctrl-C