runtime,runtime/metrics: add memory metrics

This change adds support for a variety of runtime memory metrics and
contains the base implementation of Read for the runtime/metrics
package, which lives in the runtime.

It also adds testing infrastructure for the metrics package, and a bunch
of format and documentation tests.

For #37112.

Change-Id: I16a2c4781eeeb2de0abcb045c15105f1210e2d8a
Reviewed-on: https://go-review.googlesource.com/c/go/+/247041
Run-TryBot: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Michael Pratt <mpratt@google.com>
Trust: Michael Knyszek <mknyszek@google.com>
This commit is contained in:
Michael Anthony Knyszek 2020-07-01 16:02:42 +00:00 committed by Michael Knyszek
parent 79781e8dd3
commit b08dfbaa43
9 changed files with 781 additions and 6 deletions

View file

@ -44,6 +44,60 @@ the documentation of the Name field of the Description struct.
Supported metrics
TODO(mknyszek): List them here as they're added.
/memory/classes/heap/free:bytes
Memory that is available for allocation, and may be returned
to the underlying system.
/memory/classes/heap/objects:bytes
Memory occupied by live objects and dead objects that have
not yet been collected.
/memory/classes/heap/released:bytes
Memory that has been returned to the underlying system.
/memory/classes/heap/stacks:bytes
Memory allocated from the heap that is occupied by stacks.
/memory/classes/heap/unused:bytes
Memory that is unavailable for allocation, but cannot be
returned to the underlying system.
/memory/classes/metadata/mcache/free:bytes
Memory that is reserved for runtime mcache structures, but
not in-use.
/memory/classes/metadata/mcache/inuse:bytes
Memory that is occupied by runtime mcache structures that
are currently being used.
/memory/classes/metadata/mspan/free:bytes
Memory that is reserved for runtime mspan structures, but
not in-use.
/memory/classes/metadata/mspan/inuse:bytes
Memory that is occupied by runtime mspan structures that are
currently being used.
/memory/classes/metadata/other:bytes
Memory that is reserved for or used to hold runtime
metadata.
/memory/classes/os-stacks:bytes
Stack memory allocated by the underlying operating system.
/memory/classes/other:bytes
Memory used by execution trace buffers, structures for
debugging the runtime, finalizer and profiler specials, and
more.
/memory/classes/profiling/buckets:bytes
Memory that is used by the stack trace hash map used for
profiling.
/memory/classes/total:bytes
All memory mapped by the Go runtime into the current process
as read-write. Note that this does not include memory mapped
by code called via cgo or via the syscall package.
Sum of all metrics in /memory/classes.
*/
package metrics