I have written a script that notifies me. Originally the main was:
while {True} {
waitMinutes ${sleepMins}
if {([clock format [clock seconds] -format %H] eq "00") && ${signalHour}} {
giveSignal ${hourDuration}
} else {
giveSignal ${normalDuration}
}
}
For the eventloop version I changed this to:
after [getWaitMinutesTicks ${sleepMins}] giveSignalLoop
vwait forever
And the proc is:
proc giveSignalLoop {} {
if {([clock format [clock seconds] -format %H] eq "00") && ${::signalHour}} {
giveSignal ${::hourDuration}
} else {
giveSignal ${::normalDuration}
}
after [getWaitMinutesTicks ${::sleepMins}] giveSignalLoop
}
The proc waitMinutes does an after until there are a multiply of the
minutes given. (In my case it is 30, so the signal is given at 00 and
30.
The proc getWaitMinuteTicks returns the ticks that waitMinutes would
wait.
Both are now running for 44 hours. The first one has used 9 seconds
CPU time and the second is still standing on zero. So that is a very
significant difference.
The procs used:
# Usage: waitMinutes INTERVAL
# Waits until minutes is a multiply of INTERVAL
# 60 % INTERVAL should be 0
proc waitMinutes {interval} {
if {[expr {(60 % ${interval}) != 0}]} {
error "[getProcName]: 60 is not a multiply of ${interval}"
}
after [getWaitMinutesTicks ${interval}]
}
# Usage: waitSeconds INTERVAL
# Waits until seconds is a multiply of INTERVAL
# 3600 % INTERVAL should be 0
proc waitSeconds {interval} {
if {[expr {(3600 % ${interval}) != 0}]} {
error "[getProcName]: 3600 is not a multiply of ${interval}"
}
after [getWaitSecondsTicks ${interval}]
}
And in the second case:
# Usage: getWaitMinutes INTERVAL
# Get ticks to wait until minutes is a multiply of INTERVAL
# 60 % INTERVAL should be 0
proc getWaitMinutesTicks {interval} {
if {[expr {(60 % ${interval}) != 0}]} {
error "[getProcName]: 60 is not a multiply of ${interval}"
}
getWaitSecondsTicks [expr {${interval} * 60}]
}
# Usage: getWaitSeconds INTERVAL
# Get ticks to wait until seconds is a multiply of INTERVAL
# 3600 % INTERVAL should be 0
proc getWaitSecondsTicks {interval} {
if {[expr {(3600 % ${interval}) != 0}]} {
error "[getProcName]: 3600 is not a multiply of ${interval}"
}
set secondsInHour [expr {[clock seconds] % 3600}]
set secondsToWait [expr {${interval} - (${secondsInHour} % ${interval})}]
expr {1000 * ${secondsToWait}}