seekmaniac: Show number of seeks averaged over time.

This commit is contained in:
Ole Tange 2020-03-23 17:05:45 +01:00
parent 1111353240
commit 9efd18d0fc

View file

@ -122,6 +122,24 @@ sub die_bug($) {
exit(255); exit(255);
} }
sub now() {
# Returns time since epoch as in seconds with 3 decimals
# Uses:
# @Global::use
# Returns:
# $time = time now with millisecond accuracy
if(not $Global::use{"Time::HiRes"}) {
if(eval "use Time::HiRes qw ( time );") {
eval "sub TimeHiRestime { return Time::HiRes::time };";
} else {
eval "sub TimeHiRestime { return time() };";
}
$Global::use{"Time::HiRes"} = 1;
}
return (int(TimeHiRestime()*1000))/1000;
}
$Global::version = 20200301; $Global::version = 20200301;
$Global::progname = "seekmaniac"; $Global::progname = "seekmaniac";
my $dev = shift; my $dev = shift;
@ -129,12 +147,20 @@ my $size = size_of_block_dev($dev);
my ($buf,$t); my ($buf,$t);
if(open(my $fh, "<", $dev)) { if(open(my $fh, "<", $dev)) {
$| = 1; $| = 1;
my @spin = qw(/ - \ |); my @spin = split//,q[\|/-\|/-\|/-\|/-].
q[>)|(<-<(|)>->)|(<-<(|)>->)|(<-<(|].
q[!:.oOo.oOo.oOo.oOo.,;'"';,:=-];
my $start = now() - 0.0001;
my $avg = 1;
my $seeks = 1;
while(1) { while(1) {
my $s = $size*rand(); my $s = $size*rand();
seek($fh,$s,SEEK_SET) || ::die_bug("cannot seek $dev"); seek($fh,$s,SEEK_SET) || ::die_bug("cannot seek $dev");
read($fh,$buf,1); read($fh,$buf,1);
print $spin[($t++/10)%@spin],"\r"; $seeks++;
# Exponential moving average
$avg = 0.9 * $avg + 0.1 * $seeks/(now()-$start);
print $spin[($seeks/$avg*4)%@spin]," ",int($avg)," seeks per seconds \r";
} }
} else { } else {
::error("cannot open $dev"); ::error("cannot open $dev");