mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
runtime/metrics: add tiny allocs metric
Currently tiny allocations are not represented in either MemStats or runtime/metrics, but they're represented in MemStats (indirectly) via Mallocs. Add them to runtime/metrics by first merging memstats.tinyallocs into consistentHeapStats (just for simplicity; it's monotonic so metrics would still be self-consistent if we just read it atomically) and then adding /gc/heap/tiny/allocs:objects to the list of supported metrics. Change-Id: Ie478006ab942a3e877b4a79065ffa43569722f3d Reviewed-on: https://go-review.googlesource.com/c/go/+/312909 Trust: Michael Knyszek <mknyszek@google.com> Run-TryBot: Michael Knyszek <mknyszek@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Michael Pratt <mpratt@google.com>
This commit is contained in:
parent
7d22c2181b
commit
0b9ca4d907
7 changed files with 64 additions and 13 deletions
|
|
@ -176,18 +176,18 @@ func (c *mcache) refill(spc spanClass) {
|
|||
// mcache. If it gets uncached, we'll adjust this.
|
||||
stats := memstats.heapStats.acquire()
|
||||
atomic.Xadduintptr(&stats.smallAllocCount[spc.sizeclass()], uintptr(s.nelems)-uintptr(s.allocCount))
|
||||
|
||||
// Flush tinyAllocs.
|
||||
if spc == tinySpanClass {
|
||||
atomic.Xadduintptr(&stats.tinyAllocCount, c.tinyAllocs)
|
||||
c.tinyAllocs = 0
|
||||
}
|
||||
memstats.heapStats.release()
|
||||
|
||||
// Update gcController.heapLive with the same assumption.
|
||||
usedBytes := uintptr(s.allocCount) * s.elemsize
|
||||
atomic.Xadd64(&gcController.heapLive, int64(s.npages*pageSize)-int64(usedBytes))
|
||||
|
||||
// Flush tinyAllocs.
|
||||
if spc == tinySpanClass {
|
||||
atomic.Xadd64(&memstats.tinyallocs, int64(c.tinyAllocs))
|
||||
c.tinyAllocs = 0
|
||||
}
|
||||
|
||||
// While we're here, flush scanAlloc, since we have to call
|
||||
// revise anyway.
|
||||
atomic.Xadd64(&gcController.heapScan, int64(c.scanAlloc))
|
||||
|
|
@ -280,8 +280,12 @@ func (c *mcache) releaseAll() {
|
|||
// Clear tinyalloc pool.
|
||||
c.tiny = 0
|
||||
c.tinyoffset = 0
|
||||
atomic.Xadd64(&memstats.tinyallocs, int64(c.tinyAllocs))
|
||||
|
||||
// Flush tinyAllocs.
|
||||
stats := memstats.heapStats.acquire()
|
||||
atomic.Xadduintptr(&stats.tinyAllocCount, c.tinyAllocs)
|
||||
c.tinyAllocs = 0
|
||||
memstats.heapStats.release()
|
||||
|
||||
// Updated heapScan and possible gcController.heapLive.
|
||||
if gcBlackenEnabled != 0 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue