From fb1f3af9842759518fdc08baf4a3f8724380e487 Mon Sep 17 00:00:00 2001 From: Ole Tange Date: Fri, 20 Oct 2023 19:50:57 +0200 Subject: [PATCH] seekmaniac: Better exponential average. --- Makefile | 2 +- audioping/audioping | 69 +++++++++++++++++++++++++++++++++++++++++++ clipboard/clipboard | 11 +++---- seekmaniac/seekmaniac | 32 +++++++++++++++----- 4 files changed, 101 insertions(+), 13 deletions(-) create mode 100755 audioping/audioping diff --git a/Makefile b/Makefile index 62b6a24..44fbce3 100644 --- a/Makefile +++ b/Makefile @@ -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 \ diff --git a/audioping/audioping b/audioping/audioping new file mode 100755 index 0000000..3cd735a --- /dev/null +++ b/audioping/audioping @@ -0,0 +1,69 @@ +#!/bin/bash + +: <<=cut +=pod + +=head1 NAME + +audioping - Play a sound if ping succeeds + + +=head1 SYNOPSIS + +B [options for ping] + + +=head1 DESCRIPTION + +B runs B and if B writes 'bytes from', +B 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 . + + +=head1 DEPENDENCIES + +B uses B and B. + + +=head1 SEE ALSO + +B + + +=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 }' diff --git a/clipboard/clipboard b/clipboard/clipboard index 4ccf7e2..e998d6e 100755 --- a/clipboard/clipboard +++ b/clipboard/clipboard @@ -22,7 +22,7 @@ B can be used in 3 ways. If placed last in a pipe B will take standard output from a command and save it to the clipboard. -Equivalent to: B +Equivalent to: B>B<(xsel -i -b) | xclip -i >>B =head3 Example @@ -45,7 +45,7 @@ If placed in the middle of a pipe B will copy standard output from a command and copy it to the clipboard and pass on the standard output. -Equivalent to: B +Equivalent to: B>B<(xsel -i -b) | xclip -i >>B =head3 Example @@ -78,7 +78,7 @@ along with this program. If not, see . =head1 SEE ALSO -B(1), B(1), B(1) +B(1), B(1), B(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 diff --git a/seekmaniac/seekmaniac b/seekmaniac/seekmaniac index 85cd701..2d66eae 100755 --- a/seekmaniac/seekmaniac +++ b/seekmaniac/seekmaniac @@ -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(); + my $s = $size * rand(); seek($fh,$s,SEEK_SET) || ::die_bug("cannot seek $dev"); read($fh,$buf,1); $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"; + $now = now(); + if($now - $next_print > 0.25) { + $spin++; + if($now - $last > 0) { + # Exponential moving average + $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");