Source File
doc.go
Belonging Package
runtime/metrics
// Copyright 2020 The Go Authors. All rights reserved.// Use of this source code is governed by a BSD-style// license that can be found in the LICENSE file.// Note: run 'go generate' (which will run 'go test -generate') to update the "Supported metrics" list.//go:generate go test -run=Docs -generate/*Package metrics provides a stable interface to access implementation-definedmetrics exported by the Go runtime. This package is similar to existing functionslike [runtime.ReadMemStats] and [runtime/debug.ReadGCStats], but significantly more general.The set of metrics defined by this package may evolve as the runtime itselfevolves, and also enables variation across Go implementations, whose relevantmetric sets may not intersect.# InterfaceMetrics are designated by a string key, rather than, for example, a field name ina struct. The full list of supported metrics is always available in the slice ofDescriptions returned by [All]. Each [Description] also includes useful informationabout the metric.Thus, users of this API are encouraged to sample supported metrics defined by theslice returned by All to remain compatible across Go versions. Of course, situationsarise where reading specific metrics is critical. For these cases, users areencouraged 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 avery large change in a particular Go implementation.Each metric key also has a "kind" (see [ValueKind]) that describes the format of themetric's value.In the interest of not breaking users of this package, the "kind" for a given metricis guaranteed not to change. If it must change, then a new metric will be introducedwith a new key and a new "kind."# Metric key formatAs 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 inthe key is motivated by compatibility: if a metric's unit changes, its semantics likelydid also, and a new key should be introduced.For more details on the precise definition of the metric key's path and unit formats, seethe documentation of the Name field of the Description struct.# A note about floatsThis package supports metrics whose values have a floating-point representation. Inorder to improve ease-of-use, this package promises to never produce the followingclasses of floating-point values: NaN, infinity.# Supported metricsBelow is the full list of supported metrics, ordered lexicographically./cgo/go-to-c-calls:callsCount of calls made from Go to C by the current process./cpu/classes/gc/mark/assist:cpu-secondsEstimated total CPU time goroutines spent performing GCtasks to assist the GC and prevent it from falling behind theapplication. This metric is an overestimate, and not directlycomparable to system CPU time measurements. Compare only withother /cpu/classes metrics./cpu/classes/gc/mark/dedicated:cpu-secondsEstimated total CPU time spent performing GC tasks on processors(as defined by GOMAXPROCS) dedicated to those tasks. This metricis an overestimate, and not directly comparable to system CPUtime measurements. Compare only with other /cpu/classes metrics./cpu/classes/gc/mark/idle:cpu-secondsEstimated total CPU time spent performing GC tasks on spare CPUresources that the Go scheduler could not otherwise find a usefor. This should be subtracted from the total GC CPU time toobtain a measure of compulsory GC CPU time. This metric is anoverestimate, and not directly comparable to system CPU timemeasurements. Compare only with other /cpu/classes metrics./cpu/classes/gc/pause:cpu-secondsEstimated total CPU time spent with the application paused bythe GC. Even if only one thread is running during the pause,this is computed as GOMAXPROCS times the pause latency becausenothing else can be executing. This is the exact sum of samplesin /sched/pauses/total/gc:seconds if each sample is multipliedby GOMAXPROCS at the time it is taken. This metric is anoverestimate, and not directly comparable to system CPU timemeasurements. Compare only with other /cpu/classes metrics./cpu/classes/gc/total:cpu-secondsEstimated total CPU time spent performing GC tasks. This metricis an overestimate, and not directly comparable to system CPUtime measurements. Compare only with other /cpu/classes metrics.Sum of all metrics in /cpu/classes/gc./cpu/classes/idle:cpu-secondsEstimated total available CPU time not spent executingany Go or Go runtime code. In other words, the part of/cpu/classes/total:cpu-seconds that was unused. This metric isan overestimate, and not directly comparable to system CPU timemeasurements. Compare only with other /cpu/classes metrics./cpu/classes/scavenge/assist:cpu-secondsEstimated total CPU time spent returning unused memory to theunderlying platform in response eagerly in response to memorypressure. This metric is an overestimate, and not directlycomparable to system CPU time measurements. Compare only withother /cpu/classes metrics./cpu/classes/scavenge/background:cpu-secondsEstimated total CPU time spent performing background tasks toreturn unused memory to the underlying platform. This metric isan overestimate, and not directly comparable to system CPU timemeasurements. Compare only with other /cpu/classes metrics./cpu/classes/scavenge/total:cpu-secondsEstimated total CPU time spent performing tasks that returnunused memory to the underlying platform. This metric is anoverestimate, and not directly comparable to system CPU timemeasurements. Compare only with other /cpu/classes metrics.Sum of all metrics in /cpu/classes/scavenge./cpu/classes/total:cpu-secondsEstimated total available CPU time for user Go code or the Goruntime, as defined by GOMAXPROCS. In other words, GOMAXPROCSintegrated over the wall-clock duration this process has beenexecuting for. This metric is an overestimate, and not directlycomparable to system CPU time measurements. Compare only withother /cpu/classes metrics. Sum of all metrics in /cpu/classes./cpu/classes/user:cpu-secondsEstimated total CPU time spent running user Go code. This mayalso include some small amount of time spent in the Go runtime.This metric is an overestimate, and not directly comparableto system CPU time measurements. Compare only with other/cpu/classes metrics./gc/cycles/automatic:gc-cyclesCount of completed GC cycles generated by the Go runtime./gc/cycles/forced:gc-cyclesCount of completed GC cycles forced by the application./gc/cycles/total:gc-cyclesCount of all completed GC cycles./gc/gogc:percentHeap size target percentage configured by the user, otherwise100. This value is set by the GOGC environment variable, and theruntime/debug.SetGCPercent function./gc/gomemlimit:bytesGo runtime memory limit configured by the user, otherwisemath.MaxInt64. This value is set by the GOMEMLIMIT environmentvariable, and the runtime/debug.SetMemoryLimit function./gc/heap/allocs-by-size:bytesDistribution of heap allocations by approximate size.Bucket counts increase monotonically. Note that this does notinclude tiny objects as defined by /gc/heap/tiny/allocs:objects,only tiny blocks./gc/heap/allocs:bytesCumulative sum of memory allocated to the heap by theapplication./gc/heap/allocs:objectsCumulative count of heap allocations triggered by theapplication. Note that this does not include tiny objects asdefined by /gc/heap/tiny/allocs:objects, only tiny blocks./gc/heap/frees-by-size:bytesDistribution of freed heap allocations by approximate size.Bucket counts increase monotonically. Note that this does notinclude tiny objects as defined by /gc/heap/tiny/allocs:objects,only tiny blocks./gc/heap/frees:bytesCumulative sum of heap memory freed by the garbage collector./gc/heap/frees:objectsCumulative count of heap allocations whose storage was freedby the garbage collector. Note that this does not include tinyobjects as defined by /gc/heap/tiny/allocs:objects, only tinyblocks./gc/heap/goal:bytesHeap size target for the end of the GC cycle./gc/heap/live:bytesHeap memory occupied by live objects that were marked by theprevious GC./gc/heap/objects:objectsNumber of objects, live or unswept, occupying heap memory./gc/heap/tiny/allocs:objectsCount of small allocations that are packed together into blocks.These allocations are counted separately from other allocationsbecause each individual allocation is not tracked by theruntime, only their block. Each block is already accounted forin allocs-by-size and frees-by-size./gc/limiter/last-enabled:gc-cycleGC cycle the last time the GC CPU limiter was enabled.This metric is useful for diagnosing the root cause of anout-of-memory error, because the limiter trades memory for CPUtime when the GC's CPU time gets too high. This is most likelyto occur with use of SetMemoryLimit. The first GC cycle is cycle1, so a value of 0 indicates that it was never enabled./gc/pauses:secondsDeprecated. Prefer the identical /sched/pauses/total/gc:seconds./gc/scan/globals:bytesThe total amount of global variable space that is scannable./gc/scan/heap:bytesThe total amount of heap space that is scannable./gc/scan/stack:bytesThe number of bytes of stack that were scanned last GC cycle./gc/scan/total:bytesThe total amount space that is scannable. Sum of all metrics in/gc/scan./gc/stack/starting-size:bytesThe stack size of new goroutines./godebug/non-default-behavior/allowmultiplevcs:eventsThe number of non-default behaviors executed by the cmd/gopackage due to a non-default GODEBUG=allowmultiplevcs=...setting./godebug/non-default-behavior/asynctimerchan:eventsThe number of non-default behaviors executed by the time packagedue to a non-default GODEBUG=asynctimerchan=... setting./godebug/non-default-behavior/containermaxprocs:eventsThe number of non-default behaviors executed by the runtimepackage due to a non-default GODEBUG=containermaxprocs=...setting./godebug/non-default-behavior/embedfollowsymlinks:eventsThe number of non-default behaviors executed by the cmd/gopackage due to a non-default GODEBUG=embedfollowsymlinks=...setting./godebug/non-default-behavior/execerrdot:eventsThe number of non-default behaviors executed by the os/execpackage due to a non-default GODEBUG=execerrdot=... setting./godebug/non-default-behavior/gocachehash:eventsThe number of non-default behaviors executed by the cmd/gopackage due to a non-default GODEBUG=gocachehash=... setting./godebug/non-default-behavior/gocachetest:eventsThe number of non-default behaviors executed by the cmd/gopackage due to a non-default GODEBUG=gocachetest=... setting./godebug/non-default-behavior/gocacheverify:eventsThe number of non-default behaviors executed by the cmd/gopackage due to a non-default GODEBUG=gocacheverify=... setting./godebug/non-default-behavior/gotestjsonbuildtext:eventsThe number of non-default behaviors executed by the cmd/gopackage due to a non-default GODEBUG=gotestjsonbuildtext=...setting./godebug/non-default-behavior/gotypesalias:eventsThe number of non-default behaviors executed by the go/typespackage due to a non-default GODEBUG=gotypesalias=... setting./godebug/non-default-behavior/http2client:eventsThe number of non-default behaviors executed by the net/httppackage due to a non-default GODEBUG=http2client=... setting./godebug/non-default-behavior/http2server:eventsThe number of non-default behaviors executed by the net/httppackage due to a non-default GODEBUG=http2server=... setting./godebug/non-default-behavior/httplaxcontentlength:eventsThe number of non-default behaviors executed by the net/httppackage due to a non-default GODEBUG=httplaxcontentlength=...setting./godebug/non-default-behavior/httpmuxgo121:eventsThe number of non-default behaviors executed by the net/httppackage due to a non-default GODEBUG=httpmuxgo121=... setting./godebug/non-default-behavior/httpservecontentkeepheaders:eventsThe number of non-default behaviors executedby the net/http package due to a non-defaultGODEBUG=httpservecontentkeepheaders=... setting./godebug/non-default-behavior/installgoroot:eventsThe number of non-default behaviors executed by the go/buildpackage due to a non-default GODEBUG=installgoroot=... setting./godebug/non-default-behavior/multipartmaxheaders:eventsThe number of non-default behaviors executed bythe mime/multipart package due to a non-defaultGODEBUG=multipartmaxheaders=... setting./godebug/non-default-behavior/multipartmaxparts:eventsThe number of non-default behaviors executed bythe mime/multipart package due to a non-defaultGODEBUG=multipartmaxparts=... setting./godebug/non-default-behavior/multipathtcp:eventsThe number of non-default behaviors executed by the net packagedue to a non-default GODEBUG=multipathtcp=... setting./godebug/non-default-behavior/netedns0:eventsThe number of non-default behaviors executed by the net packagedue to a non-default GODEBUG=netedns0=... setting./godebug/non-default-behavior/panicnil:eventsThe number of non-default behaviors executed by the runtimepackage due to a non-default GODEBUG=panicnil=... setting./godebug/non-default-behavior/randautoseed:eventsThe number of non-default behaviors executed by the math/randpackage due to a non-default GODEBUG=randautoseed=... setting./godebug/non-default-behavior/randseednop:eventsThe number of non-default behaviors executed by the math/randpackage due to a non-default GODEBUG=randseednop=... setting./godebug/non-default-behavior/rsa1024min:eventsThe number of non-default behaviors executed by the crypto/rsapackage due to a non-default GODEBUG=rsa1024min=... setting./godebug/non-default-behavior/tarinsecurepath:eventsThe number of non-default behaviors executed by the archive/tarpackage due to a non-default GODEBUG=tarinsecurepath=...setting./godebug/non-default-behavior/tls10server:eventsThe number of non-default behaviors executed by the crypto/tlspackage due to a non-default GODEBUG=tls10server=... setting./godebug/non-default-behavior/tls3des:eventsThe number of non-default behaviors executed by the crypto/tlspackage due to a non-default GODEBUG=tls3des=... setting./godebug/non-default-behavior/tlsmaxrsasize:eventsThe number of non-default behaviors executed by the crypto/tlspackage due to a non-default GODEBUG=tlsmaxrsasize=... setting./godebug/non-default-behavior/tlsrsakex:eventsThe number of non-default behaviors executed by the crypto/tlspackage due to a non-default GODEBUG=tlsrsakex=... setting./godebug/non-default-behavior/tlssha1:eventsThe number of non-default behaviors executed by the crypto/tlspackage due to a non-default GODEBUG=tlssha1=... setting./godebug/non-default-behavior/tlsunsafeekm:eventsThe number of non-default behaviors executed by the crypto/tlspackage due to a non-default GODEBUG=tlsunsafeekm=... setting./godebug/non-default-behavior/updatemaxprocs:eventsThe number of non-default behaviors executed by the runtimepackage due to a non-default GODEBUG=updatemaxprocs=... setting./godebug/non-default-behavior/winreadlinkvolume:eventsThe number of non-default behaviors executed by the os packagedue to a non-default GODEBUG=winreadlinkvolume=... setting./godebug/non-default-behavior/winsymlink:eventsThe number of non-default behaviors executed by the os packagedue to a non-default GODEBUG=winsymlink=... setting./godebug/non-default-behavior/x509keypairleaf:eventsThe number of non-default behaviors executed by the crypto/tlspackage due to a non-default GODEBUG=x509keypairleaf=...setting./godebug/non-default-behavior/x509negativeserial:eventsThe number of non-default behaviors executed by the crypto/x509package due to a non-default GODEBUG=x509negativeserial=...setting./godebug/non-default-behavior/x509rsacrt:eventsThe number of non-default behaviors executed by the crypto/x509package due to a non-default GODEBUG=x509rsacrt=... setting./godebug/non-default-behavior/x509sha256skid:eventsThe number of non-default behaviors executed by the crypto/x509package due to a non-default GODEBUG=x509sha256skid=... setting./godebug/non-default-behavior/x509usefallbackroots:eventsThe number of non-default behaviors executed by the crypto/x509package due to a non-default GODEBUG=x509usefallbackroots=...setting./godebug/non-default-behavior/x509usepolicies:eventsThe number of non-default behaviors executed by the crypto/x509package due to a non-default GODEBUG=x509usepolicies=...setting./godebug/non-default-behavior/zipinsecurepath:eventsThe number of non-default behaviors executed by the archive/zippackage due to a non-default GODEBUG=zipinsecurepath=...setting./memory/classes/heap/free:bytesMemory that is completely free and eligible to be returned tothe underlying system, but has not been. This metric is theruntime's estimate of free address space that is backed byphysical memory./memory/classes/heap/objects:bytesMemory occupied by live objects and dead objects that have notyet been marked free by the garbage collector./memory/classes/heap/released:bytesMemory that is completely free and has been returned to theunderlying system. This metric is the runtime's estimate of freeaddress space that is still mapped into the process, but is notbacked by physical memory./memory/classes/heap/stacks:bytesMemory allocated from the heap that is reserved for stack space,whether or not it is currently in-use. Currently, thisrepresents all stack memory for goroutines. It also includes allOS thread stacks in non-cgo programs. Note that stacks may beallocated differently in the future, and this may change./memory/classes/heap/unused:bytesMemory that is reserved for heap objects but is not currentlyused to hold heap objects./memory/classes/metadata/mcache/free:bytesMemory that is reserved for runtime mcache structures, but notin-use./memory/classes/metadata/mcache/inuse:bytesMemory that is occupied by runtime mcache structures that arecurrently being used./memory/classes/metadata/mspan/free:bytesMemory that is reserved for runtime mspan structures, but notin-use./memory/classes/metadata/mspan/inuse:bytesMemory that is occupied by runtime mspan structures that arecurrently being used./memory/classes/metadata/other:bytesMemory that is reserved for or used to hold runtime metadata./memory/classes/os-stacks:bytesStack memory allocated by the underlying operating system.In non-cgo programs this metric is currently zero. This maychange in the future.In cgo programs this metric includesOS thread stacks allocated directly from the OS. Currently,this only accounts for one stack in c-shared and c-archive buildmodes, and other sources of stacks from the OS are not measured.This too may change in the future./memory/classes/other:bytesMemory used by execution trace buffers, structures for debuggingthe runtime, finalizer and profiler specials, and more./memory/classes/profiling/buckets:bytesMemory that is used by the stack trace hash map used forprofiling./memory/classes/total:bytesAll memory mapped by the Go runtime into the current processas read-write. Note that this does not include memory mappedby code called via cgo or via the syscall package. Sum of allmetrics in /memory/classes./sched/gomaxprocs:threadsThe current runtime.GOMAXPROCS setting, or the number ofoperating system threads that can execute user-level Go codesimultaneously./sched/goroutines:goroutinesCount of live goroutines./sched/latencies:secondsDistribution of the time goroutines have spent in the schedulerin a runnable state before actually running. Bucket countsincrease monotonically./sched/pauses/stopping/gc:secondsDistribution of individual GC-related stop-the-world stoppinglatencies. This is the time it takes from deciding to stop theworld until all Ps are stopped. This is a subset of the totalGC-related stop-the-world time (/sched/pauses/total/gc:seconds).During this time, some threads may be executing. Bucket countsincrease monotonically./sched/pauses/stopping/other:secondsDistribution of individual non-GC-related stop-the-worldstopping latencies. This is the time it takes from decidingto stop the world until all Ps are stopped. This is asubset of the total non-GC-related stop-the-world time(/sched/pauses/total/other:seconds). During this time, somethreads may be executing. Bucket counts increase monotonically./sched/pauses/total/gc:secondsDistribution of individual GC-related stop-the-world pauselatencies. This is the time from deciding to stop the worlduntil the world is started again. Some of this time is spentgetting all threads to stop (this is measured directly in/sched/pauses/stopping/gc:seconds), during which some threadsmay still be running. Bucket counts increase monotonically./sched/pauses/total/other:secondsDistribution of individual non-GC-related stop-the-worldpause latencies. This is the time from deciding to stop theworld until the world is started again. Some of this timeis spent getting all threads to stop (measured directly in/sched/pauses/stopping/other:seconds). Bucket counts increasemonotonically./sync/mutex/wait/total:secondsApproximate cumulative time goroutines have spent blocked on async.Mutex, sync.RWMutex, or runtime-internal lock. This metricis useful for identifying global changes in lock contention.Collect a mutex or block profile using the runtime/pprof packagefor more detailed contention data.*/package metrics
![]() |
The pages are generated with Golds v0.7.9-preview. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |