From 6173b1cab8a5df50de7d72eb42f3ababae782e49 Mon Sep 17 00:00:00 2001 From: jao Date: Sat, 12 Oct 2019 15:33:10 +0100 Subject: toggleMonitor --- bin/toggle-pipe.sh | 16 ++++++++++++++++ src/lib/Monitors.hs | 12 ++++++++---- 2 files changed, 24 insertions(+), 4 deletions(-) create mode 100755 bin/toggle-pipe.sh diff --git a/bin/toggle-pipe.sh b/bin/toggle-pipe.sh new file mode 100755 index 0000000..2dfc8b9 --- /dev/null +++ b/bin/toggle-pipe.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +[[ -z $1 ]] && echo "Usage: toggle-pipe.sh path-to-pipe" && exit 1 + +state="$1.state" + +[[ -p $1 ]] || mkfifo $1 + +[[ -f $state ]] || echo 0 > $state + +v=$(<$state) + +if [[ x$v == x1 ]]; then v=0; else v=1; fi + +echo $v > $state; +echo -e "$v\\\n" > $1; diff --git a/src/lib/Monitors.hs b/src/lib/Monitors.hs index 5639185..0dbe8b1 100644 --- a/src/lib/Monitors.hs +++ b/src/lib/Monitors.hs @@ -25,16 +25,20 @@ startMonitors a b cmb = do stb <- atomically $ newTVar "" _ <- async $ start a (\x -> atomically $ writeTVar sta x) _ <- async $ start b (\x -> atomically $ writeTVar stb x) - go sta stb cmb - where go sta' stb' cmb' = do + go sta stb + where go sta' stb' = do s <- atomically $ readTVar sta' t <- atomically $ readTVar stb' - cmb' s t + cmb s t tenthSeconds $ min (rate b) (rate a) - go sta' stb' cmb' + go sta' stb' + +guardedMonitor a p = CombinedMonitor (PipeReader p (alias a ++ "_g")) a f + where f s t = if (null s || head s == '0') then "" else t altMonitor a b = CombinedMonitor a b (\s t -> if null s then t else s) concatMonitor sep a b = CombinedMonitor a b (\s t -> s ++ sep ++ t) +toggleMonitor path a b = altMonitor (guardedMonitor a path) b topProc p = TopProc (p <~> ["-t" , " \ \ยท " -- cgit v1.2.3