Skip to content

Commit

Permalink
Revert "[process] Fix shirou#599 cap percent values returned by *Perc…
Browse files Browse the repository at this point in the history
…ent() between 0 and 100"

This reverts commit f4e2355.
Fixes shirou#755
  • Loading branch information
sajoupa committed Oct 15, 2019
1 parent 1c09419 commit b3cfb9a
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions process/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"encoding/json"
"errors"
"math"
"runtime"
"sort"
"time"
Expand Down Expand Up @@ -265,7 +264,7 @@ func calculatePercent(t1, t2 *cpu.TimesStat, delta float64, numcpu int) float64
}
delta_proc := t2.Total() - t1.Total()
overall_percent := ((delta_proc / delta) * 100) * float64(numcpu)
return math.Min(100, math.Max(0, overall_percent))
return overall_percent
}

// MemoryPercent returns how many percent of the total RAM this process uses
Expand All @@ -286,7 +285,7 @@ func (p *Process) MemoryPercentWithContext(ctx context.Context) (float32, error)
}
used := processMemory.RSS

return float32(math.Min(100, math.Max(0, (100*float64(used)/float64(total))))), nil
return (100 * float32(used) / float32(total)), nil
}

// CPU_Percent returns how many percent of the CPU time this process uses
Expand All @@ -311,5 +310,5 @@ func (p *Process) CPUPercentWithContext(ctx context.Context) (float64, error) {
return 0, nil
}

return math.Min(100, math.Max(0, 100*cput.Total()/totalTime)), nil
return 100 * cput.Total() / totalTime, nil
}

0 comments on commit b3cfb9a

Please sign in to comment.