Merge pull request #707 from Lomanic/issue599

[cpu] WIP #599 cap percent values returned by Percent() between 0 and 100
This commit is contained in:
shirou 2019-07-06 11:23:17 +09:00 committed by GitHub
commit 0e6ea68690
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 1 deletions

View File

@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"math"
"strconv"
"strings"
"sync"
@ -112,7 +113,7 @@ func calculateBusy(t1, t2 TimesStat) float64 {
if t2All <= t1All {
return 1
}
return (t2Busy - t1Busy) / (t2All - t1All) * 100
return math.Min(100, math.Max(0, (t2Busy-t1Busy)/(t2All-t1All)*100))
}
func calculateAllBusy(t1, t2 []TimesStat) ([]float64, error) {