Fixed error when oldest file was older than oldest bucket.

Realigned columns.
This commit is contained in:
hjp 2006-02-17 13:50:23 +00:00
parent c5c941a868
commit 1488372199
1 changed files with 14 additions and 10 deletions

View File

@ -1,6 +1,6 @@
#!@@@perl@@@ -w #!@@@perl@@@ -w
# #
# $Id: agestat.pl,v 1.6 2006-02-17 13:31:41 hjp Exp $ # $Id: agestat.pl,v 1.7 2006-02-17 13:50:23 hjp Exp $
# #
use strict; use strict;
@ -26,8 +26,8 @@ if (!defined($opts{scale})) {
} }
if ($opts{buckets} eq "log2") { if ($opts{buckets} eq "log2") {
for (0 .. 31) { for (my ($b, $s) = (0, 1); $b < 32; $b++, $s *= 2) {
$bucket_max[$_] = 2 << $_; $bucket_max[$b] = $s;
} }
} elsif ($opts{buckets} eq "cal") { } elsif ($opts{buckets} eq "cal") {
@bucket_max = ( @bucket_max = (
@ -56,7 +56,7 @@ sub wanted {
(! -d && $st->atime > $st->mtime ? $st->atime (! -d && $st->atime > $st->mtime ? $st->atime
: $st->mtime )); : $st->mtime ));
my $b = 0; my $b = 0;
while ($age > $bucket_max[$b]) { $b++ }; while ($b <= $#bucket_max && $age > $bucket_max[$b]) { $b++ };
#print $File::Find::name, ": $age sec, ", $st->size, " bytes, ", $st->nlink, " links, bucket $b\n"; #print $File::Find::name, ": $age sec, ", $st->size, " bytes, ", $st->nlink, " links, bucket $b\n";
$hist[$b] += $st->size / $st->nlink; $hist[$b] += $st->size / $st->nlink;
} }
@ -65,15 +65,15 @@ sub time2str {
my ($t) = (@_); my ($t) = (@_);
if ($t < 60) { if ($t < 60) {
return sprintf ("%5.1f s", $t); return sprintf ("%6.1f s", $t);
} elsif ($t < 3600) { } elsif ($t < 3600) {
return sprintf ("%5.1f m", $t/60); return sprintf ("%6.1f m", $t/60);
} elsif ($t < 3600 * 24) { } elsif ($t < 3600 * 24) {
return sprintf ("%5.1f h", $t/3600); return sprintf ("%6.1f h", $t/3600);
} elsif ($t < 3600 * 24 * 365.2422) { } elsif ($t < 3600 * 24 * 365.2422) {
return sprintf ("%5.1f d", $t/(3600*24)); return sprintf ("%6.1f d", $t/(3600*24));
} else { } else {
return sprintf ("%5.1f y", $t/(3600*24*365.2422)); return sprintf ("%6.1f y", $t/(3600*24*365.2422));
} }
} }
@ -102,7 +102,11 @@ for (my $i = 0; $i <= $#hist; $i++) {
} }
# $Log: agestat.pl,v $ # $Log: agestat.pl,v $
# Revision 1.6 2006-02-17 13:31:41 hjp # Revision 1.7 2006-02-17 13:50:23 hjp
# Fixed error when oldest file was older than oldest bucket.
# Realigned columns.
#
# Revision 1.6 2006/02/17 13:31:41 hjp
# Added option --buckets. # Added option --buckets.
# #
# Revision 1.5 2002/03/18 20:33:46 hjp # Revision 1.5 2002/03/18 20:33:46 hjp