#!/usr/bin/perl #Modify the first line and the line below ($PIO =...) as needed. #topio 1.1: This Perl script launches pio (Process I/O) to probe all processes #on the system and sort them based on absolute or delta Read/Write Characters #for each process. $PIO = "/usr/local/bin/pio"; ########## No need to modify below this line but hacking is welcome. ########## use Getopt::Std; getopts('ds:n:h'); if (defined $opt_h) { print "Usage: $0 [-d] [-s Delay] [-n Top_n_lines] [-h] -d: Show delta Read/Write Characters between calls of pio -s: Number of seconds delay between calls (default 5) -n: Only show processes of top n RWChar or (if -d) deltaRWChar (default 10) -h: Show this Usage\n"; exit; } $opt_s = 5 if !defined $opt_s; $opt_n = 10 if !defined $opt_n; if (defined $opt_d) { #Format to be used by write format = @>>>> @>>>>>>>>>>>>>>> @>>>>>> @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $_, $pio{$_}, $iodiff{$_}, $comm . undef $/; while (1) { $_ = qx{$PIO -A}; #slurp in all pio -A output @lines = split /\n/; @allpids = (); #@allpids is used to delete pid's that're gone between #calls to pio foreach (@lines) { next if /^$/; @line = split /\t/; #$line[0]: pid; $pio{$line[0]}: Saved RWChar for this pid if (defined $pio{$line[0]}) #$line[3]: RWChar; $iodiff{$line[0]}: delta RWChar for this pid { $iodiff{$line[0]} = $line[3] - $pio{$line[0]}; } $pio{$line[0]} = $line[3]; $allpids{$line[0]} = 1; #create this hash for all current processes } foreach $pid (keys %pio) { delete $pio{$pid} if ! exists $allpids{$pid}; #this process disappears } if (defined $show) #prevent printing all 0's the first time around { $n = 0; print "--PID-----------RWChar--DifRWC Command------------------------------------------\n"; foreach (sort { $iodiff{$b} <=> $iodiff{$a} } keys %iodiff) { #A poor man's way to provide command for pid (added 20040730) $comm = qx{/usr/bin/ps -ocomm= -p $_}; write if defined $iodiff{$_}; #print using the format defined earlier last if ++$n == $opt_n; } } $show = 1; sleep $opt_s; } } else #Don't reinvent the wheel. Use shell sort. { warn "** WARNING: Running topio without -d may not be ** ** what you want. Type topio -h for help. **\n"; system(" while true; do echo 'PID\tInpBlk\tOutpBlk\tRWChar' $PIO -A | sort -nr -k 4,4 | head -$opt_n sleep $opt_s done "); }