Skip to content

Commit

Permalink
Add breakdown of free spans to distinguish ones that have
Browse files Browse the repository at this point in the history
been given back to the OS from ones that haven't.
  • Loading branch information
randall77 committed Dec 7, 2017
1 parent 7ea1f10 commit 2e3f4fc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
9 changes: 8 additions & 1 deletion gocore/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ func (p *Process) readSpans() {
allspans := mheap.Field("allspans")
var allSpanSize int64
var freeSpanSize int64
var releasedSpanSize int64
var manualSpanSize int64
var inUseSpanSize int64
var allocSize int64
Expand All @@ -154,7 +155,9 @@ func (p *Process) readSpans() {
min := core.Address(s.Field("startAddr").Uintptr())
elemSize := int64(s.Field("elemsize").Uintptr())
nPages := int64(s.Field("npages").Uintptr())
nReleased := int64(s.Field("npreleased").Uintptr())
spanSize := nPages * pageSize
nReleasedSize := nReleased * pageSize
max := min.Add(spanSize)
allSpanSize += spanSize
switch s.Field("state").Cast("uint8").Uint8() {
Expand Down Expand Up @@ -207,6 +210,7 @@ func (p *Process) readSpans() {
}
case spanFree:
freeSpanSize += spanSize
releasedSpanSize += nReleasedSize
case spanDead:
// These are just deallocated span descriptors. They use no heap.
case spanManual:
Expand Down Expand Up @@ -234,7 +238,10 @@ func (p *Process) readSpans() {
&Stats{"alloc", manualAllocSize, nil},
&Stats{"free", manualFreeSize, nil},
}},
&Stats{"free spans", freeSpanSize, nil},
&Stats{"free spans", freeSpanSize, []*Stats{
&Stats{"retained", freeSpanSize - releasedSpanSize, nil},
&Stats{"released", releasedSpanSize, nil},
}},
}},
&Stats{"ptr bitmap", bitmap, nil},
&Stats{"span table", spanTable, nil},
Expand Down
4 changes: 4 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ func main() {
comment = "(grab bag, includes OS thread stacks, ...)"
case "manual spans":
comment = "(Go stacks)"
case "retained":
comment = "(kept for reuse by Go)"
case "released":
comment = "(given back to the OS)"
}
fmt.Fprintf(t, "%s\t%d\t%6.2f%%\t %s\n", fmt.Sprintf("%-20s", indent+s.Name), s.Size, float64(s.Size)*100/float64(all), comment)
for _, c := range s.Children {
Expand Down

0 comments on commit 2e3f4fc

Please sign in to comment.