Added option --buckets.
This commit is contained in:
parent
1d4e979fba
commit
c5c941a868
|
@ -1,6 +1,6 @@
|
||||||
#!@@@perl@@@ -w
|
#!@@@perl@@@ -w
|
||||||
#
|
#
|
||||||
# $Id: agestat.pl,v 1.5 2002-03-18 20:33:46 hjp Exp $
|
# $Id: agestat.pl,v 1.6 2006-02-17 13:31:41 hjp Exp $
|
||||||
#
|
#
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
|
@ -9,10 +9,10 @@ use File::Find;
|
||||||
use Getopt::Long;
|
use Getopt::Long;
|
||||||
|
|
||||||
my $now = time();
|
my $now = time();
|
||||||
my $log_2 = log(2);
|
my @bucket_max;
|
||||||
|
|
||||||
my %opts = ();
|
my %opts = (buckets => 'log2');
|
||||||
GetOptions(\%opts, "atime", "mtime", "scale=s");
|
GetOptions(\%opts, "atime", "mtime", "scale=s", "buckets=s");
|
||||||
my $scale;
|
my $scale;
|
||||||
if (!defined($opts{scale})) {
|
if (!defined($opts{scale})) {
|
||||||
$scale = 1;
|
$scale = 1;
|
||||||
|
@ -25,6 +25,26 @@ if (!defined($opts{scale})) {
|
||||||
exit 1;
|
exit 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($opts{buckets} eq "log2") {
|
||||||
|
for (0 .. 31) {
|
||||||
|
$bucket_max[$_] = 2 << $_;
|
||||||
|
}
|
||||||
|
} elsif ($opts{buckets} eq "cal") {
|
||||||
|
@bucket_max = (
|
||||||
|
3600,
|
||||||
|
86400,
|
||||||
|
7 * 86400,
|
||||||
|
30 * 86400,
|
||||||
|
182 * 86400,
|
||||||
|
1 * 365.2422 * 86400,
|
||||||
|
2 * 365.2422 * 86400,
|
||||||
|
3 * 365.2422 * 86400,
|
||||||
|
4 * 365.2422 * 86400,
|
||||||
|
5 * 365.2422 * 86400,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
my @hist;
|
my @hist;
|
||||||
|
|
||||||
sub wanted {
|
sub wanted {
|
||||||
|
@ -35,15 +55,14 @@ sub wanted {
|
||||||
$opts{mtime} ? $st->mtime :
|
$opts{mtime} ? $st->mtime :
|
||||||
(! -d && $st->atime > $st->mtime ? $st->atime
|
(! -d && $st->atime > $st->mtime ? $st->atime
|
||||||
: $st->mtime ));
|
: $st->mtime ));
|
||||||
#print $File::Find::name, ": $age sec, ", $st->size, " bytes, ", $st->nlink, " links\n";
|
my $b = 0;
|
||||||
my $log2age = log($age >= 1 ? $age : 1) / $log_2;
|
while ($age > $bucket_max[$b]) { $b++ };
|
||||||
$hist[$log2age] += $st->size / $st->nlink;
|
#print $File::Find::name, ": $age sec, ", $st->size, " bytes, ", $st->nlink, " links, bucket $b\n";
|
||||||
|
$hist[$b] += $st->size / $st->nlink;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub logtime2str {
|
sub time2str {
|
||||||
my ($lt) = (@_);
|
my ($t) = (@_);
|
||||||
|
|
||||||
my $t = 1 << $lt;
|
|
||||||
|
|
||||||
if ($t < 60) {
|
if ($t < 60) {
|
||||||
return sprintf ("%5.1f s", $t);
|
return sprintf ("%5.1f s", $t);
|
||||||
|
@ -59,6 +78,7 @@ sub logtime2str {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (@ARGV == 0) { push (@ARGV, "."); }
|
if (@ARGV == 0) { push (@ARGV, "."); }
|
||||||
find(\&wanted, @ARGV);
|
find(\&wanted, @ARGV);
|
||||||
|
|
||||||
|
@ -75,12 +95,17 @@ my $c = 0;
|
||||||
for (my $i = 0; $i <= $#hist; $i++) {
|
for (my $i = 0; $i <= $#hist; $i++) {
|
||||||
my $h = ($hist[$i] || 0);
|
my $h = ($hist[$i] || 0);
|
||||||
$c += $h;
|
$c += $h;
|
||||||
printf("%2d\t%s\t%12.0f\t%5.1f\t%12.0f\t%5.1f\n", $i,
|
printf("%2d\t%s\t%12.0f\t%5.1f\t%12.0f\t%5.1f\n",
|
||||||
logtime2str($i), $h/$scale, $h * 100 / $sum, $c/$scale, $c * 100 / $sum);
|
$i,
|
||||||
|
$i <= $#bucket_max ? time2str($bucket_max[$i]) : "infinity",
|
||||||
|
$h/$scale, $h * 100 / $sum, $c/$scale, $c * 100 / $sum);
|
||||||
}
|
}
|
||||||
|
|
||||||
# $Log: agestat.pl,v $
|
# $Log: agestat.pl,v $
|
||||||
# Revision 1.5 2002-03-18 20:33:46 hjp
|
# Revision 1.6 2006-02-17 13:31:41 hjp
|
||||||
|
# Added option --buckets.
|
||||||
|
#
|
||||||
|
# Revision 1.5 2002/03/18 20:33:46 hjp
|
||||||
# Ignore atime for directories
|
# Ignore atime for directories
|
||||||
#
|
#
|
||||||
# Revision 1.4 2001/01/19 19:06:01 hjp
|
# Revision 1.4 2001/01/19 19:06:01 hjp
|
||||||
|
|
Loading…
Reference in New Issue