add proper error handling for all final exec calls
[hband-tools.git] / admin-tools / inodestats
blob1d8ff98e5aa42d07a95fa00bc7746818fa37f999
1 #!/usr/bin/env perl
3 use Data::Dumper;
5 $LINES = $ENV{'LINES'} || `tput lines`;
7 open LSOF, '-|', qw/lsof -n -Fcpi +c0/;
8 while(<LSOF>)
9 {
10 ($a, $b) = (/^(.)(.*)/);
11 if($a eq "p")
13 $pid=$b;
15 elsif($a eq "i")
17 push @{$T{$pid}->{$a}},$b;
19 else
21 $T{$pid}->{$a} = $b;
24 close LSOF;
26 for $pid (keys %T)
28 $C{$T{$pid}->{'c'}}->{'nproc'}++;
29 $C{$T{$pid}->{'c'}}->{'inodes'} += scalar @{$T{$pid}->{'i'}};
32 for $c (keys %C)
34 $C{$c}->{'iperp'} = $C{$c}->{'inodes'} / $C{$c}->{'nproc'};
38 $line = 0;
39 $sortby = $ARGV[0] || "inodes";
40 for $c (sort { $C{$b}->{$sortby} <=> $C{$a}->{$sortby} } keys %C)
42 printf "%-16s %4d prc %5s ino %7.1f i/p\n", $c, $C{$c}->{'nproc'}, $C{$c}->{'inodes'}, $C{$c}->{'iperp'} ;
43 $line++;
44 last if ($LINES and $line >= $LINES - 2);