mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
limit cpu percent range to 0-100
This commit is contained in:
parent
e0d9c35170
commit
51c98236e4
@ -7,6 +7,7 @@ import (
|
|||||||
"github.com/senorprogrammer/wtf/wtf"
|
"github.com/senorprogrammer/wtf/wtf"
|
||||||
"github.com/shirou/gopsutil/cpu"
|
"github.com/shirou/gopsutil/cpu"
|
||||||
"github.com/shirou/gopsutil/mem"
|
"github.com/shirou/gopsutil/mem"
|
||||||
|
"math"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -43,6 +44,10 @@ func MakeGraph(widget *Widget) {
|
|||||||
var stats = make([]wtf.Bar, len(cpuStats)+2)
|
var stats = make([]wtf.Bar, len(cpuStats)+2)
|
||||||
|
|
||||||
for i, stat := range cpuStats {
|
for i, stat := range cpuStats {
|
||||||
|
// Stats sometimes jump outside the 0-100 range, possibly due to timing
|
||||||
|
stat = math.Min(100, stat)
|
||||||
|
stat = math.Max(0, stat)
|
||||||
|
|
||||||
bar := wtf.Bar{
|
bar := wtf.Bar{
|
||||||
Label: fmt.Sprint(i),
|
Label: fmt.Sprint(i),
|
||||||
Percent: int(stat),
|
Percent: int(stat),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user