2024-01-15 19:24:48 -06:00
|
|
|
package linuxstatus
|
|
|
|
|
|
|
|
import (
|
2024-01-21 02:23:47 -06:00
|
|
|
"errors"
|
2024-01-15 19:24:48 -06:00
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"go.wit.com/log"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (ls *LinuxStatus) Update() {
|
2024-02-25 18:39:27 -06:00
|
|
|
if ls == nil {
|
|
|
|
return
|
|
|
|
}
|
2024-01-21 02:23:47 -06:00
|
|
|
if !ls.Ready() {
|
2024-01-15 19:24:48 -06:00
|
|
|
log.Log(WARN, "can't update yet. ready is false")
|
|
|
|
log.Error(errors.New("Update() is not ready yet"))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
log.Log(INFO, "Update() START")
|
2024-01-21 02:23:47 -06:00
|
|
|
duration := timeFunction(func() {
|
2024-01-15 19:24:48 -06:00
|
|
|
linuxLoop()
|
|
|
|
})
|
|
|
|
ls.setSpeed(duration)
|
|
|
|
log.Log(INFO, "Update() END")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ls *LinuxStatus) setSpeed(duration time.Duration) {
|
|
|
|
s := fmt.Sprint(duration)
|
|
|
|
if ls.speedActual == nil {
|
|
|
|
log.Log(WARN, "can't actually warn")
|
|
|
|
return
|
|
|
|
}
|
2024-01-31 12:41:28 -06:00
|
|
|
ls.speedActual.SetText(s)
|
2024-01-15 19:24:48 -06:00
|
|
|
|
2024-01-21 02:23:47 -06:00
|
|
|
if duration > 500*time.Millisecond {
|
2024-01-31 12:41:28 -06:00
|
|
|
ls.speed.SetText("SLOW")
|
2024-01-21 02:23:47 -06:00
|
|
|
} else if duration > 100*time.Millisecond {
|
2024-01-31 12:41:28 -06:00
|
|
|
ls.speed.SetText("OK")
|
2024-01-15 19:24:48 -06:00
|
|
|
} else {
|
2024-01-31 12:41:28 -06:00
|
|
|
ls.speed.SetText("FAST")
|
2024-01-15 19:24:48 -06:00
|
|
|
}
|
|
|
|
}
|