Skip to content

Commit

Permalink
Fix incorrect Mem.Used calculation (#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
EOIDC authored and ruflin committed Nov 28, 2017
1 parent 52f14dd commit 96f2eb0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).

### Changed
- OpenBSD returns `ErrNotImplemented` for `ProcTime.Get` instead of `nil`. #83
- Fixed incorrect `Mem.Used` calculation under linux. #82
- Fixed `ProcState` on Linux and FreeBSD when process names contain parentheses. #81

### Deprecated
Expand Down
2 changes: 1 addition & 1 deletion sigar_linux_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (self *Mem) Get() error {
self.ActualFree = self.Free + buffers + cached
}

self.Used = self.Total - self.ActualFree
self.Used = self.Total - self.Free
self.ActualUsed = self.Total - self.ActualFree

return nil
Expand Down
5 changes: 5 additions & 0 deletions sigar_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,9 @@ DirectMap2M: 333824 kB
if assert.NoError(t, mem.Get()) {
assert.Equal(t, uint64(374256*1024), mem.Total)
assert.Equal(t, uint64(274460*1024), mem.Free)
assert.Equal(t, uint64(mem.Total-mem.Free), mem.Used)
assert.Equal(t, uint64((274460+9764+38648)*1024), mem.ActualFree)
assert.Equal(t, uint64(mem.Total-mem.ActualFree), mem.ActualUsed)
}

swap := sigar.Swap{}
Expand Down Expand Up @@ -293,6 +296,8 @@ DirectMap2M: 460800 kB
assert.Equal(t, uint64(500184*1024), mem.Total)
assert.Equal(t, uint64(31360*1024), mem.Free)
assert.Equal(t, uint64(414168*1024), mem.ActualFree)
assert.Equal(t, uint64(mem.Total-mem.Free), mem.Used)
assert.Equal(t, uint64(mem.Total-mem.ActualFree), mem.ActualUsed)
}

swap := sigar.Swap{}
Expand Down

0 comments on commit 96f2eb0

Please sign in to comment.