Namespace: go.std.runtime.metrics
v1.0Contents
Summary
Provides a low-level interface to the runtime/metrics package.
Package metrics provides a stable interface to access implementation-defined
metrics exported by the Go runtime. This package is similar to existing functions
like runtime.ReadMemStats and debug.ReadGCStats, but significantly more general.
The set of metrics defined by this package may evolve as the runtime itself
evolves, and also enables variation across Go implementations, whose relevant
metric sets may not intersect.
# Interface
Metrics are designated by a string key, rather than, for example, a field name in
a struct. The full list of supported metrics is always available in the slice of
Descriptions returned by All. Each Description also includes useful information
about the metric.
Thus, users of this API are encouraged to sample supported metrics defined by the
slice returned by All to remain compatible across Go versions. Of course, situations
arise where reading specific metrics is critical. For these cases, users are
encouraged to use build tags, and although metrics may be deprecated and removed,
users should consider this to be an exceptional and rare event, coinciding with a
very large change in a particular Go implementation.
Each metric key also has a "kind" that describes the format of the metric's value.
In the interest of not breaking users of this package, the "kind" for a given metric
is guaranteed not to change. If it must change, then a new metric will be introduced
with a new key and a new "kind."
# Metric key format
As mentioned earlier, metric keys are strings. Their format is simple and well-defined,
designed to be both human and machine readable. It is split into two components,
separated by a colon: a rooted path and a unit. The choice to include the unit in
the key is motivated by compatibility: if a metric's unit changes, its semantics likely
did also, and a new key should be introduced.
For more details on the precise definition of the metric key's path and unit formats, see
the documentation of the Name field of the Description struct.
# A note about floats
This package supports metrics whose values have a floating-point representation. In
order to improve ease-of-use, this package promises to never produce the following
classes of floating-point values: NaN, infinity.
# Supported metrics
Below is the full list of supported metrics, ordered lexicographically.
/cgo/go-to-c-calls:calls
Count of calls made from Go to C by the current process.
/gc/cycles/automatic:gc-cycles
Count of completed GC cycles generated by the Go runtime.
/gc/cycles/forced:gc-cycles
Count of completed GC cycles forced by the application.
/gc/cycles/total:gc-cycles
Count of all completed GC cycles.
/gc/heap/allocs-by-size:bytes
Distribution of heap allocations by approximate size.
Note that this does not include tiny objects as defined by /gc/heap/tiny/allocs:objects,
only tiny blocks.
/gc/heap/allocs:bytes
Cumulative sum of memory allocated to the heap by the application.
/gc/heap/allocs:objects
Cumulative count of heap allocations triggered by the application.
Note that this does not include tiny objects as defined by /gc/heap/tiny/allocs:objects,
only tiny blocks.
/gc/heap/frees-by-size:bytes
Distribution of freed heap allocations by approximate size.
Note that this does not include tiny objects as defined by /gc/heap/tiny/allocs:objects,
only tiny blocks.
/gc/heap/frees:bytes
Cumulative sum of heap memory freed by the garbage collector.
/gc/heap/frees:objects
Cumulative count of heap allocations whose storage was freed by the garbage collector.
Note that this does not include tiny objects as defined by /gc/heap/tiny/allocs:objects,
only tiny blocks.
/gc/heap/goal:bytes
Heap size target for the end of the GC cycle.
/gc/heap/objects:objects
Number of objects, live or unswept, occupying heap memory.
/gc/heap/tiny/allocs:objects
Count of small allocations that are packed together into blocks.
These allocations are counted separately from other allocations
because each individual allocation is not tracked by the runtime,
only their block. Each block is already accounted for in
allocs-by-size and frees-by-size.
/gc/limiter/last-enabled:gc-cycle
GC cycle the last time the GC CPU limiter was enabled.
This metric is useful for diagnosing the root cause of an out-of-memory
error, because the limiter trades memory for CPU time when the GC's CPU
time gets too high. This is most likely to occur with use of SetMemoryLimit.
The first GC cycle is cycle 1, so a value of 0 indicates that it was never enabled.
/gc/pauses:seconds
Distribution individual GC-related stop-the-world pause latencies.
/gc/stack/starting-size:bytes
The stack size of new goroutines.
/memory/classes/heap/free:bytes
Memory that is completely free and eligible to be returned to
the underlying system, but has not been. This metric is the
runtime's estimate of free address space that is backed by
physical memory.
/memory/classes/heap/objects:bytes
Memory occupied by live objects and dead objects that have
not yet been marked free by the garbage collector.
/memory/classes/heap/released:bytes
Memory that is completely free and has been returned to
the underlying system. This metric is the runtime's estimate of
free address space that is still mapped into the process, but
is not backed by physical memory.
/memory/classes/heap/stacks:bytes
Memory allocated from the heap that is reserved for stack
space, whether or not it is currently in-use.
/memory/classes/heap/unused:bytes
Memory that is reserved for heap objects but is not currently
used to hold heap objects.
/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.
/sched/gomaxprocs:threads
The current runtime.GOMAXPROCS setting, or the number of
operating system threads that can execute user-level Go code
simultaneously.
/sched/goroutines:goroutines
Count of live goroutines.
/sched/latencies:seconds
Distribution of the time goroutines have spent in the scheduler
in a runnable state before actually running.
Index
- *Description
- *Float64Histogram
- *Sample
- *Value
- *ValueKind
- All
- Description
- Float64Histogram
- KindBad
- KindFloat64
- KindFloat64Histogram
- KindUint64
- Read
- Sample
- Value
- ValueKind
- arrayOfDescription
- arrayOfFloat64Histogram
- arrayOfSample
- arrayOfValue
- arrayOfValueKind
Legend
-
Constant
Variable
Function
Macro
Special form
Type
GoVar
Receiver/Method
Constants
Constants are variables with :const true in their metadata. Joker currently does not recognize them as special; as such, it allows redefining them or their values.-
(None.)
Variables
-
KindBad
GoObject v1.0KindBad indicates that the Value has no type and should not be used.
-
KindFloat64
GoObject v1.0KindFloat64 indicates that the type of the Value is a float64.
-
KindFloat64Histogram
GoObject v1.0KindFloat64Histogram indicates that the type of the Value is a *Float64Histogram.
-
KindUint64
GoObject v1.0KindUint64 indicates that the type of the Value is a uint64.
Functions, Macros, and Special Forms
-
All
Function v1.0(All)
All returns a slice of containing metric descriptions for all supported metrics.
Go returns: []Description
Joker input arguments: []
Joker returns: ^arrayOfDescription -
Read
Function v1.0(Read m)
Read populates each Value field in the given slice of metric samples.
Desired metrics should be present in the slice with the appropriate name.
The user of this API is encouraged to re-use the same slice between calls for
efficiency, but is not required to do so.
Note that re-use has some caveats. Notably, Values should not be read or
manipulated while a Read with that value is outstanding; that is a data race.
This property includes pointer-typed Values (for example, Float64Histogram)
whose underlying storage will be reused by Read when possible. To safely use
such values in a concurrent setting, all data must be deep-copied.
It is safe to execute multiple Read calls concurrently, but their arguments
must share no underlying memory. When in doubt, create a new []Sample from
scratch, which is always safe, though may be inefficient.
Sample values with names not appearing in All will have their Value populated
as KindBad to indicate that the name is unknown.
Go input arguments: (m []Sample)
Joker input arguments: [^arrayOfSample m]
Types
-
*Description
Concrete Type v1.0Description describes a runtime metric.
-
*Float64Histogram
Concrete Type v1.0Float64Histogram represents a distribution of float64 values.
-
*Sample
Concrete Type v1.0Sample captures a single metric sample.
-
*Value
Concrete Type v1.0Value represents a metric value returned by the runtime.
-
*ValueKind
Concrete Type v1.0ValueKind is a tag for a metric Value which indicates its type.
-
Description
Concrete Type v1.0Description describes a runtime metric.
-
Float64Histogram
Concrete Type v1.0Float64Histogram represents a distribution of float64 values.
-
Sample
Concrete Type v1.0Sample captures a single metric sample.
-
Value
Concrete Type v1.0Value represents a metric value returned by the runtime.
-
Float64
Receiver for Value v1.0([])
Float64 returns the internal float64 value for the metric.
If v.Kind() != KindFloat64, this method panics.
-
Float64Histogram
Receiver for Value v1.0([])
Float64Histogram returns the internal *Float64Histogram value for the metric.
If v.Kind() != KindFloat64Histogram, this method panics.
-
Kind
Receiver for Value v1.0([])
Kind returns the tag representing the kind of value this is.
-
Uint64
Receiver for Value v1.0([])
Uint64 returns the internal uint64 value for the metric.
If v.Kind() != KindUint64, this method panics.
-
ValueKind
Concrete Type v1.0ValueKind is a tag for a metric Value which indicates its type.
-
arrayOfDescription
Concrete Type v1.0Description describes a runtime metric.
-
arrayOfFloat64Histogram
Concrete Type v1.0Float64Histogram represents a distribution of float64 values.
-
arrayOfSample
Concrete Type v1.0Sample captures a single metric sample.
-
arrayOfValue
Concrete Type v1.0Value represents a metric value returned by the runtime.
-
arrayOfValueKind
Concrete Type v1.0ValueKind is a tag for a metric Value which indicates its type.