cmd/syncthing: Report correct CPU usage on Windows (fixes #4133)

This commit is contained in:
Jakob Borg 2017-05-05 16:12:17 +02:00
parent 6386d079b0
commit c4b527e5e9

View File

@ -857,7 +857,10 @@ func init() {
return return
} }
go func() { go func() {
var prevUsage time.Duration // Initialize prevUsage to an actual value returned by cpuUsage
// instead of zero, because at least Windows returns a huge negative
// number here that then slowly increments...
prevUsage := cpuUsage()
for range time.NewTicker(cpuTickRate).C { for range time.NewTicker(cpuTickRate).C {
curUsage := cpuUsage() curUsage := cpuUsage()
cpuAverage.Update(int64((curUsage - prevUsage) / time.Millisecond)) cpuAverage.Update(int64((curUsage - prevUsage) / time.Millisecond))