Skip to content

Commit

Permalink
Change Cpu.Get() on Windows to not use floating point artimetic
Browse files Browse the repository at this point in the history
Backport of elastic#1128 to 1.2.1
  • Loading branch information
andrewkroh committed Apr 6, 2016
1 parent 0be8f24 commit 4930b6a
Show file tree
Hide file tree
Showing 29 changed files with 769 additions and 573 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ https://github.com/elastic/beats/compare/v1.1.2...v1.2.0[View commits]
*Topbeat*
- Add the command line used to start processes {issue}533[533]
- Fix issue with cpu.system_p being greater than 1 on Windows {pull}1128[1128]
*Filebeat*
Expand Down
2 changes: 1 addition & 1 deletion topbeat/beat/sigar.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"strings"
"time"

"github.com/elastic/gosigar"
sigar "github.com/elastic/gosigar"
)

type SystemLoad struct {
Expand Down
12 changes: 6 additions & 6 deletions topbeat/beat/topbeat.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"strconv"
"time"

"github.com/elastic/gosigar"
sigar "github.com/elastic/gosigar"

"github.com/elastic/beats/libbeat/beat"
"github.com/elastic/beats/libbeat/cfgfile"
Expand Down Expand Up @@ -383,9 +383,9 @@ func (t *Topbeat) addCpuPercentage(t2 *CpuTimes) {
calculate := func(field2 uint64, field1 uint64) float64 {

perc := 0.0
delta := field2 - field1
delta := int64(field2 - field1)
perc = float64(delta) / float64(all_delta)
return Round(perc, .5, 2)
return Round(perc, .5, 4)
}

t2.UserPercent = calculate(t2.User, t1.User)
Expand All @@ -405,9 +405,9 @@ func (t *Topbeat) addCpuPercentageList(t2 []CpuTimes) {
calculate := func(field2 uint64, field1 uint64, all_delta uint64) float64 {

perc := 0.0
delta := field2 - field1
delta := int64(field2 - field1)
perc = float64(delta) / float64(all_delta)
return Round(perc, .5, 2)
return Round(perc, .5, 4)
}

for i := 0; i < len(t1); i++ {
Expand Down Expand Up @@ -451,7 +451,7 @@ func (t *Topbeat) addProcCpuPercentage(proc *Process) {

t.procsMap[proc.Pid] = proc

proc.Cpu.UserPercent = Round(perc, .5, 2)
proc.Cpu.UserPercent = Round(perc, .5, 4)

}
}
Expand Down
6 changes: 3 additions & 3 deletions topbeat/beat/topbeat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ func TestCpuPercentage(t *testing.T) {

beat.addCpuPercentage(&cpu2)

assert.Equal(t, cpu2.UserPercent, 0.95)
assert.Equal(t, cpu2.SystemPercent, 0.04)
assert.Equal(t, cpu2.UserPercent, 0.9502)
assert.Equal(t, cpu2.SystemPercent, 0.0448)
}

func TestProcMemPercentage(t *testing.T) {
Expand Down Expand Up @@ -146,5 +146,5 @@ func TestProcCpuPercentage(t *testing.T) {
beat.procsMap[p1.Pid] = &p1

beat.addProcCpuPercentage(&p2)
assert.Equal(t, p2.Cpu.UserPercent, 3.46)
assert.Equal(t, p2.Cpu.UserPercent, 3.459)
}
80 changes: 80 additions & 0 deletions vendor/github.com/elastic/gosigar/.appveyor.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 33 additions & 1 deletion vendor/github.com/elastic/gosigar/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 8 additions & 6 deletions vendor/github.com/elastic/gosigar/.travis.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions vendor/github.com/elastic/gosigar/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/github.com/elastic/gosigar/concrete_sigar.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

147 changes: 69 additions & 78 deletions vendor/github.com/elastic/gosigar/concrete_sigar_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4930b6a

Please sign in to comment.