seekmaniac: Better exponential average.

This commit is contained in:
Ole Tange 2023-10-20 19:50:57 +02:00
parent ed6f1078ff
commit fb1f3af984
4 changed files with 101 additions and 13 deletions

View file

@ -1,4 +1,4 @@
CMD = 2grep 2search blink burncpu bwlimit clipboard drac \
CMD = 2grep 2search audioping blink burncpu bwlimit clipboard drac \
duplicate-packets em emoticons encdir fanspeed field \
find-first-fail find-optimal forever fxkill G gitnext gitundo \
goodpasswd histogram Loffice mtrr mirrorpdf neno not off \

69
audioping/audioping Executable file
View file

@ -0,0 +1,69 @@
#!/bin/bash
: <<=cut
=pod
=head1 NAME
audioping - Play a sound if ping succeeds
=head1 SYNOPSIS
B<audioping> [options for ping]
=head1 DESCRIPTION
B<audioping> runs B<ping> and if B<ping> writes 'bytes from',
B<audioping> plays a sound.
=head1 EXAMPLE
Ping fsf.org
audioping fsf.org
=head1 AUTHOR
Copyright (C) 2023 Ole Tange,
http://ole.tange.dk and Free Software Foundation, Inc.
=head1 LICENSE
Copyright (C) 2012 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
at your option any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
=head1 DEPENDENCIES
B<audioping> uses B<ping> and B<perl>.
=head1 SEE ALSO
B<ping>
=cut
bip() {
play -q -n synth sine F4 sine C3 remix - fade 0 4 .0 norm -20 bend 0.1,2477,0.1 fade 0 0.3 0.1 2>/dev/null;
}
export -f bip
ping "$@" | perl -pe '/bytes from/ and qx{ bash -c bip }'

View file

@ -22,7 +22,7 @@ B<clipboard> can be used in 3 ways.
If placed last in a pipe B<clipboard> will take standard output from a
command and save it to the clipboard.
Equivalent to: B<cat | xsel -i -b>
Equivalent to: B<cat | tee >>B<(xsel -i -b) | xclip -i >>B</dev/null>
=head3 Example
@ -45,7 +45,7 @@ If placed in the middle of a pipe B<clipboard> will copy standard
output from a command and copy it to the clipboard and pass on the
standard output.
Equivalent to: B<xsel -i -b; xsel -o -b>
Equivalent to: B<tee >>B<(xsel -i -b) | xclip -i >>B</dev/null; xsel -o -b>
=head3 Example
@ -78,7 +78,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
=head1 SEE ALSO
B<xsel>(1), B<tee>(1), B<cat>(1)
B<tee>(1), B<xclip>(1), B<xsel>(1)
=cut
@ -99,11 +99,12 @@ else
# STDOUT = terminal
# cat | clipboard => copy to clipboard
echo xsel -i -b >> $debug_log
xsel -i -b
tee >(xsel -i -b) | xclip -i >/dev/null
else
# STDOUT redir'ed
# cat | clipboard | cat => copy and forward clipboard
echo xsel tee >> $debug_log
tee >(xsel -i -b)
tee >(xsel -i -b) | xclip -i >/dev/null
xsel -o -b
fi
fi

View file

@ -140,27 +140,45 @@ sub now() {
return (int(TimeHiRestime()*1000))/1000;
}
$Global::version = 20200301;
$Global::version = 20231020;
$Global::progname = "seekmaniac";
my $dev = shift;
my $size = size_of_block_dev($dev);
my ($buf,$t);
if(open(my $fh, "<", $dev)) {
$| = 1;
my @spin = split//,q[\|/-\|/-\|/-\|/-].
my @spin = split//,q[/-\|/-\|/-\|/-\|].
q[>)|(<-<(|)>->)|(<-<(|)>->)|(<-<(|].
q[!:.oOo.oOo.oOo.oOo.,;'"';,:=-];
my $start = now() - 0.0001;
my $avg = 1;
my $seeks = 1;
my $last_seeks = 0;
my $now = now();
my $last = $now;
my $next_print = $now;
my $spin = 0;
my $warmup = 0;
while(1) {
my $s = $size * rand();
seek($fh,$s,SEEK_SET) || ::die_bug("cannot seek $dev");
read($fh,$buf,1);
$seeks++;
$now = now();
if($now - $next_print > 0.25) {
$spin++;
if($now - $last > 0) {
# Exponential moving average
$avg = 0.9 * $avg + 0.1 * $seeks/(now()-$start);
print $spin[($seeks/$avg*4)%@spin]," ",int($avg)," seeks per seconds \r";
$warmup = $warmup * 0.95 + 0.05 * 0.9;
$avg = $warmup * $avg +
(1-$warmup) * ($seeks - $last_seeks) / ($now - $last);
$last_seeks = $seeks;
$last = $now;
}
print $spin[$spin % @spin]," ",
int($avg)," seeks per second \r";
# Print next time in 0.25 sec
$next_print += 0.25;
}
}
} else {
::error("cannot open $dev");