Skip to content

Commit 2e3f4fc

Browse files
committed
Add breakdown of free spans to distinguish ones that have
been given back to the OS from ones that haven't.
1 parent 7ea1f10 commit 2e3f4fc

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

gocore/parse.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ func (p *Process) readSpans() {
141141
allspans := mheap.Field("allspans")
142142
var allSpanSize int64
143143
var freeSpanSize int64
144+
var releasedSpanSize int64
144145
var manualSpanSize int64
145146
var inUseSpanSize int64
146147
var allocSize int64
@@ -154,7 +155,9 @@ func (p *Process) readSpans() {
154155
min := core.Address(s.Field("startAddr").Uintptr())
155156
elemSize := int64(s.Field("elemsize").Uintptr())
156157
nPages := int64(s.Field("npages").Uintptr())
158+
nReleased := int64(s.Field("npreleased").Uintptr())
157159
spanSize := nPages * pageSize
160+
nReleasedSize := nReleased * pageSize
158161
max := min.Add(spanSize)
159162
allSpanSize += spanSize
160163
switch s.Field("state").Cast("uint8").Uint8() {
@@ -207,6 +210,7 @@ func (p *Process) readSpans() {
207210
}
208211
case spanFree:
209212
freeSpanSize += spanSize
213+
releasedSpanSize += nReleasedSize
210214
case spanDead:
211215
// These are just deallocated span descriptors. They use no heap.
212216
case spanManual:
@@ -234,7 +238,10 @@ func (p *Process) readSpans() {
234238
&Stats{"alloc", manualAllocSize, nil},
235239
&Stats{"free", manualFreeSize, nil},
236240
}},
237-
&Stats{"free spans", freeSpanSize, nil},
241+
&Stats{"free spans", freeSpanSize, []*Stats{
242+
&Stats{"retained", freeSpanSize - releasedSpanSize, nil},
243+
&Stats{"released", releasedSpanSize, nil},
244+
}},
238245
}},
239246
&Stats{"ptr bitmap", bitmap, nil},
240247
&Stats{"span table", spanTable, nil},

main.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,10 @@ func main() {
210210
comment = "(grab bag, includes OS thread stacks, ...)"
211211
case "manual spans":
212212
comment = "(Go stacks)"
213+
case "retained":
214+
comment = "(kept for reuse by Go)"
215+
case "released":
216+
comment = "(given back to the OS)"
213217
}
214218
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)
215219
for _, c := range s.Children {

0 commit comments

Comments
 (0)