2000-02-08 02:07:36 +01:00
|
|
|
#!@@@perl@@@ -w
|
2001-01-19 20:06:01 +01:00
|
|
|
#
|
|
|
|
# $Id: agestat.pl,v 1.4 2001-01-19 19:06:01 hjp Exp $
|
|
|
|
#
|
2000-02-08 02:01:06 +01:00
|
|
|
|
2000-02-08 02:07:36 +01:00
|
|
|
use strict;
|
2000-02-08 02:01:06 +01:00
|
|
|
use File::stat;
|
|
|
|
use File::Find;
|
2000-02-08 02:07:36 +01:00
|
|
|
use Getopt::Long;
|
2000-02-08 02:01:06 +01:00
|
|
|
|
2000-02-08 02:07:36 +01:00
|
|
|
my $now = time();
|
|
|
|
my $log_2 = log(2);
|
|
|
|
|
|
|
|
my %opts = ();
|
|
|
|
GetOptions(\%opts, "atime", "mtime", "scale=s");
|
|
|
|
my $scale;
|
|
|
|
if (!defined($opts{scale})) {
|
|
|
|
$scale = 1;
|
|
|
|
} elsif ($opts{scale} eq 'k') {
|
|
|
|
$scale = 1024;
|
|
|
|
} elsif ($opts{scale} eq 'M') {
|
|
|
|
$scale = 1024*1024;
|
|
|
|
} else {
|
2001-01-19 20:06:01 +01:00
|
|
|
print STDERR "Usage: $0 [-atime|-mtime] [-scale=(k|M)]\n";
|
2000-02-08 02:07:36 +01:00
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
my @hist;
|
2000-02-08 02:01:06 +01:00
|
|
|
|
|
|
|
sub wanted {
|
|
|
|
|
2000-02-08 02:07:36 +01:00
|
|
|
my $st = lstat($_);
|
|
|
|
my $age = $now - (
|
|
|
|
$opts{atime} ? $st->atime :
|
|
|
|
$opts{mtime} ? $st->mtime :
|
|
|
|
($st->atime > $st->mtime ? $st->atime
|
|
|
|
: $st->mtime ));
|
2000-02-08 02:01:06 +01:00
|
|
|
#print $File::Find::name, ": $age sec, ", $st->size, " bytes, ", $st->nlink, " links\n";
|
2000-02-08 02:07:36 +01:00
|
|
|
my $log2age = log($age >= 1 ? $age : 1) / $log_2;
|
2000-02-08 02:01:06 +01:00
|
|
|
$hist[$log2age] += $st->size / $st->nlink;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub logtime2str {
|
|
|
|
my ($lt) = (@_);
|
|
|
|
|
2000-02-08 02:07:36 +01:00
|
|
|
my $t = 1 << $lt;
|
2000-02-08 02:01:06 +01:00
|
|
|
|
|
|
|
if ($t < 60) {
|
|
|
|
return sprintf ("%5.1f s", $t);
|
|
|
|
} elsif ($t < 3600) {
|
|
|
|
return sprintf ("%5.1f m", $t/60);
|
|
|
|
} elsif ($t < 3600 * 24) {
|
|
|
|
return sprintf ("%5.1f h", $t/3600);
|
|
|
|
} elsif ($t < 3600 * 24 * 365.2422) {
|
|
|
|
return sprintf ("%5.1f d", $t/(3600*24));
|
|
|
|
} else {
|
|
|
|
return sprintf ("%5.1f y", $t/(3600*24*365.2422));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-08-17 17:15:30 +02:00
|
|
|
if (@ARGV == 0) { push (@ARGV, "."); }
|
2000-02-08 02:01:06 +01:00
|
|
|
find(\&wanted, @ARGV);
|
|
|
|
|
|
|
|
print "\n\n";
|
|
|
|
|
2000-02-08 02:07:36 +01:00
|
|
|
my $sum = 0;
|
2000-02-08 02:01:06 +01:00
|
|
|
|
2000-02-08 02:07:36 +01:00
|
|
|
for (my $i = 0; $i <= $#hist; $i++) {
|
|
|
|
$sum += ($hist[$i] || 0);
|
2000-02-08 02:01:06 +01:00
|
|
|
}
|
|
|
|
|
2000-02-08 02:07:36 +01:00
|
|
|
|
|
|
|
my $c = 0;
|
|
|
|
for (my $i = 0; $i <= $#hist; $i++) {
|
|
|
|
my $h = ($hist[$i] || 0);
|
2000-02-08 02:01:06 +01:00
|
|
|
$c += $h;
|
2000-02-08 02:07:36 +01:00
|
|
|
printf("%2d\t%s\t%12.0f\t%5.1f\t%12.0f\t%5.1f\n", $i,
|
|
|
|
logtime2str($i), $h/$scale, $h * 100 / $sum, $c/$scale, $c * 100 / $sum);
|
2000-02-08 02:01:06 +01:00
|
|
|
}
|
2001-01-19 20:06:01 +01:00
|
|
|
|
|
|
|
# $Log: agestat.pl,v $
|
|
|
|
# Revision 1.4 2001-01-19 19:06:01 hjp
|
|
|
|
# Removed superfluous "total" line.
|
|
|
|
# Fixed usage message.
|
|
|
|
#
|