#!/bin/sh ########################################################## # Written Feb 20, 2008 and released under the GNU/GPLv2 ## # by Jeff Schroeder (jeffschroeder@computer.org) # # ########################################################## # # # # # top-disk-user - Prints disk reads and writes on a per # # # process level using the block dumping # # # feature of 2.6 series Linux kernels # # # # # ########################################################## #$Id$ # NOTE: THIS IS NOT DONE OR EVEN FULLY FUNCTIONAL! UPLOADED AS W.I.P. # Why not perl? Embedded distros like emdebian don't include perl in # their repositories. Those are the target for this script. ############ TODO ############ # - Configurable sleep with -n option using getopt or $1 # - Device filtering using -d option # - Way more sanity checking ########## / TODO ############ # Clear out the printk ring buffer. klogd gets this stuff permanently anyways dmesg -c >/dev/null 2>&1 # Enable block dumping echo 1 > /proc/sys/vm/block_dump # FIXME: Use getopt and configurable option here with default of 1 minute sleep 60 # Disable block dumping echo 0 > /proc/sys/vm/block_dump printf "%15s %10s %10s %10s %10s\n" COMMAND PID NUM ACTION DEVICE # Hide the eyes child! It gets ugly from here on IFS=" " for line in $(dmesg | awk '{if ( $3 ~ "READ" || $3 ~ "WRITE" ) { \ print $2 " " $3 " " $NF}}' $1 | sort | uniq -c); do num=$(echo $line | awk '{print $1}') command=$(echo $line | awk '{print $2}' | sed -re 's/\([[:digit:]]+\)://') pid=$(echo $line| awk -F'[()]' '{print $2}') action=$(echo $line | awk '{print $(NF - 1)}') device=$(echo $line | awk '{print $NF}') printf "%15s %10s %10s %10s %10s\n" "$command" "$pid" "$num" "$action" "$device" done