...

Source file src/runtime/metrics/doc.go

Documentation: runtime/metrics

     1  // Copyright 2020 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // Note: run 'go generate' (which will run 'go test -generate') to update the "Supported metrics" list.
     6  //go:generate go test -run=Docs -generate
     7  
     8  /*
     9  Package metrics provides a stable interface to access implementation-defined
    10  metrics exported by the Go runtime. This package is similar to existing functions
    11  like [runtime.ReadMemStats] and [runtime/debug.ReadGCStats], but significantly more general.
    12  
    13  The set of metrics defined by this package may evolve as the runtime itself
    14  evolves, and also enables variation across Go implementations, whose relevant
    15  metric sets may not intersect.
    16  
    17  # Interface
    18  
    19  Metrics are designated by a string key, rather than, for example, a field name in
    20  a struct. The full list of supported metrics is always available in the slice of
    21  Descriptions returned by [All]. Each [Description] also includes useful information
    22  about the metric.
    23  
    24  Thus, users of this API are encouraged to sample supported metrics defined by the
    25  slice returned by All to remain compatible across Go versions. Of course, situations
    26  arise where reading specific metrics is critical. For these cases, users are
    27  encouraged to use build tags, and although metrics may be deprecated and removed,
    28  users should consider this to be an exceptional and rare event, coinciding with a
    29  very large change in a particular Go implementation.
    30  
    31  Each metric key also has a "kind" (see [ValueKind]) that describes the format of the
    32  metric's value.
    33  In the interest of not breaking users of this package, the "kind" for a given metric
    34  is guaranteed not to change. If it must change, then a new metric will be introduced
    35  with a new key and a new "kind."
    36  
    37  # Metric key format
    38  
    39  As mentioned earlier, metric keys are strings. Their format is simple and well-defined,
    40  designed to be both human and machine readable. It is split into two components,
    41  separated by a colon: a rooted path and a unit. The choice to include the unit in
    42  the key is motivated by compatibility: if a metric's unit changes, its semantics likely
    43  did also, and a new key should be introduced.
    44  
    45  For more details on the precise definition of the metric key's path and unit formats, see
    46  the documentation of the Name field of the Description struct.
    47  
    48  # A note about floats
    49  
    50  This package supports metrics whose values have a floating-point representation. In
    51  order to improve ease-of-use, this package promises to never produce the following
    52  classes of floating-point values: NaN, infinity.
    53  
    54  # Supported metrics
    55  
    56  Below is the full list of supported metrics, ordered lexicographically.
    57  
    58  	/cgo/go-to-c-calls:calls
    59  		Count of calls made from Go to C by the current process.
    60  
    61  	/cpu/classes/gc/mark/assist:cpu-seconds
    62  		Estimated total CPU time goroutines spent performing GC
    63  		tasks to assist the GC and prevent it from falling behind the
    64  		application. This metric is an overestimate, and not directly
    65  		comparable to system CPU time measurements. Compare only with
    66  		other /cpu/classes metrics.
    67  
    68  	/cpu/classes/gc/mark/dedicated:cpu-seconds
    69  		Estimated total CPU time spent performing GC tasks on processors
    70  		(as defined by GOMAXPROCS) dedicated to those tasks. This metric
    71  		is an overestimate, and not directly comparable to system CPU
    72  		time measurements. Compare only with other /cpu/classes metrics.
    73  
    74  	/cpu/classes/gc/mark/idle:cpu-seconds
    75  		Estimated total CPU time spent performing GC tasks on spare CPU
    76  		resources that the Go scheduler could not otherwise find a use
    77  		for. This should be subtracted from the total GC CPU time to
    78  		obtain a measure of compulsory GC CPU time. This metric is an
    79  		overestimate, and not directly comparable to system CPU time
    80  		measurements. Compare only with other /cpu/classes metrics.
    81  
    82  	/cpu/classes/gc/pause:cpu-seconds
    83  		Estimated total CPU time spent with the application paused by
    84  		the GC. Even if only one thread is running during the pause,
    85  		this is computed as GOMAXPROCS times the pause latency because
    86  		nothing else can be executing. This is the exact sum of samples
    87  		in /sched/pauses/total/gc:seconds if each sample is multiplied
    88  		by GOMAXPROCS at the time it is taken. This metric is an
    89  		overestimate, and not directly comparable to system CPU time
    90  		measurements. Compare only with other /cpu/classes metrics.
    91  
    92  	/cpu/classes/gc/total:cpu-seconds
    93  		Estimated total CPU time spent performing GC tasks. This metric
    94  		is an overestimate, and not directly comparable to system CPU
    95  		time measurements. Compare only with other /cpu/classes metrics.
    96  		Sum of all metrics in /cpu/classes/gc.
    97  
    98  	/cpu/classes/idle:cpu-seconds
    99  		Estimated total available CPU time not spent executing
   100  		any Go or Go runtime code. In other words, the part of
   101  		/cpu/classes/total:cpu-seconds that was unused. This metric is
   102  		an overestimate, and not directly comparable to system CPU time
   103  		measurements. Compare only with other /cpu/classes metrics.
   104  
   105  	/cpu/classes/scavenge/assist:cpu-seconds
   106  		Estimated total CPU time spent returning unused memory to the
   107  		underlying platform in response eagerly in response to memory
   108  		pressure. This metric is an overestimate, and not directly
   109  		comparable to system CPU time measurements. Compare only with
   110  		other /cpu/classes metrics.
   111  
   112  	/cpu/classes/scavenge/background:cpu-seconds
   113  		Estimated total CPU time spent performing background tasks to
   114  		return unused memory to the underlying platform. This metric is
   115  		an overestimate, and not directly comparable to system CPU time
   116  		measurements. Compare only with other /cpu/classes metrics.
   117  
   118  	/cpu/classes/scavenge/total:cpu-seconds
   119  		Estimated total CPU time spent performing tasks that return
   120  		unused memory to the underlying platform. This metric is an
   121  		overestimate, and not directly comparable to system CPU time
   122  		measurements. Compare only with other /cpu/classes metrics.
   123  		Sum of all metrics in /cpu/classes/scavenge.
   124  
   125  	/cpu/classes/total:cpu-seconds
   126  		Estimated total available CPU time for user Go code or the Go
   127  		runtime, as defined by GOMAXPROCS. In other words, GOMAXPROCS
   128  		integrated over the wall-clock duration this process has been
   129  		executing for. This metric is an overestimate, and not directly
   130  		comparable to system CPU time measurements. Compare only with
   131  		other /cpu/classes metrics. Sum of all metrics in /cpu/classes.
   132  
   133  	/cpu/classes/user:cpu-seconds
   134  		Estimated total CPU time spent running user Go code. This may
   135  		also include some small amount of time spent in the Go runtime.
   136  		This metric is an overestimate, and not directly comparable
   137  		to system CPU time measurements. Compare only with other
   138  		/cpu/classes metrics.
   139  
   140  	/gc/cycles/automatic:gc-cycles
   141  		Count of completed GC cycles generated by the Go runtime.
   142  
   143  	/gc/cycles/forced:gc-cycles
   144  		Count of completed GC cycles forced by the application.
   145  
   146  	/gc/cycles/total:gc-cycles
   147  		Count of all completed GC cycles.
   148  
   149  	/gc/gogc:percent
   150  		Heap size target percentage configured by the user, otherwise
   151  		100. This value is set by the GOGC environment variable, and the
   152  		runtime/debug.SetGCPercent function.
   153  
   154  	/gc/gomemlimit:bytes
   155  		Go runtime memory limit configured by the user, otherwise
   156  		math.MaxInt64. This value is set by the GOMEMLIMIT environment
   157  		variable, and the runtime/debug.SetMemoryLimit function.
   158  
   159  	/gc/heap/allocs-by-size:bytes
   160  		Distribution of heap allocations by approximate size.
   161  		Bucket counts increase monotonically. Note that this does not
   162  		include tiny objects as defined by /gc/heap/tiny/allocs:objects,
   163  		only tiny blocks.
   164  
   165  	/gc/heap/allocs:bytes
   166  		Cumulative sum of memory allocated to the heap by the
   167  		application.
   168  
   169  	/gc/heap/allocs:objects
   170  		Cumulative count of heap allocations triggered by the
   171  		application. Note that this does not include tiny objects as
   172  		defined by /gc/heap/tiny/allocs:objects, only tiny blocks.
   173  
   174  	/gc/heap/frees-by-size:bytes
   175  		Distribution of freed heap allocations by approximate size.
   176  		Bucket counts increase monotonically. Note that this does not
   177  		include tiny objects as defined by /gc/heap/tiny/allocs:objects,
   178  		only tiny blocks.
   179  
   180  	/gc/heap/frees:bytes
   181  		Cumulative sum of heap memory freed by the garbage collector.
   182  
   183  	/gc/heap/frees:objects
   184  		Cumulative count of heap allocations whose storage was freed
   185  		by the garbage collector. Note that this does not include tiny
   186  		objects as defined by /gc/heap/tiny/allocs:objects, only tiny
   187  		blocks.
   188  
   189  	/gc/heap/goal:bytes
   190  		Heap size target for the end of the GC cycle.
   191  
   192  	/gc/heap/live:bytes
   193  		Heap memory occupied by live objects that were marked by the
   194  		previous GC.
   195  
   196  	/gc/heap/objects:objects
   197  		Number of objects, live or unswept, occupying heap memory.
   198  
   199  	/gc/heap/tiny/allocs:objects
   200  		Count of small allocations that are packed together into blocks.
   201  		These allocations are counted separately from other allocations
   202  		because each individual allocation is not tracked by the
   203  		runtime, only their block. Each block is already accounted for
   204  		in allocs-by-size and frees-by-size.
   205  
   206  	/gc/limiter/last-enabled:gc-cycle
   207  		GC cycle the last time the GC CPU limiter was enabled.
   208  		This metric is useful for diagnosing the root cause of an
   209  		out-of-memory error, because the limiter trades memory for CPU
   210  		time when the GC's CPU time gets too high. This is most likely
   211  		to occur with use of SetMemoryLimit. The first GC cycle is cycle
   212  		1, so a value of 0 indicates that it was never enabled.
   213  
   214  	/gc/pauses:seconds
   215  		Deprecated. Prefer the identical /sched/pauses/total/gc:seconds.
   216  
   217  	/gc/scan/globals:bytes
   218  		The total amount of global variable space that is scannable.
   219  
   220  	/gc/scan/heap:bytes
   221  		The total amount of heap space that is scannable.
   222  
   223  	/gc/scan/stack:bytes
   224  		The number of bytes of stack that were scanned last GC cycle.
   225  
   226  	/gc/scan/total:bytes
   227  		The total amount space that is scannable. Sum of all metrics in
   228  		/gc/scan.
   229  
   230  	/gc/stack/starting-size:bytes
   231  		The stack size of new goroutines.
   232  
   233  	/godebug/non-default-behavior/allowmultiplevcs:events
   234  		The number of non-default behaviors executed by the cmd/go
   235  		package due to a non-default GODEBUG=allowmultiplevcs=...
   236  		setting.
   237  
   238  	/godebug/non-default-behavior/asynctimerchan:events
   239  		The number of non-default behaviors executed by the time package
   240  		due to a non-default GODEBUG=asynctimerchan=... setting.
   241  
   242  	/godebug/non-default-behavior/execerrdot:events
   243  		The number of non-default behaviors executed by the os/exec
   244  		package due to a non-default GODEBUG=execerrdot=... setting.
   245  
   246  	/godebug/non-default-behavior/gocachehash:events
   247  		The number of non-default behaviors executed by the cmd/go
   248  		package due to a non-default GODEBUG=gocachehash=... setting.
   249  
   250  	/godebug/non-default-behavior/gocachetest:events
   251  		The number of non-default behaviors executed by the cmd/go
   252  		package due to a non-default GODEBUG=gocachetest=... setting.
   253  
   254  	/godebug/non-default-behavior/gocacheverify:events
   255  		The number of non-default behaviors executed by the cmd/go
   256  		package due to a non-default GODEBUG=gocacheverify=... setting.
   257  
   258  	/godebug/non-default-behavior/gotestjsonbuildtext:events
   259  		The number of non-default behaviors executed by the cmd/go
   260  		package due to a non-default GODEBUG=gotestjsonbuildtext=...
   261  		setting.
   262  
   263  	/godebug/non-default-behavior/gotypesalias:events
   264  		The number of non-default behaviors executed by the go/types
   265  		package due to a non-default GODEBUG=gotypesalias=... setting.
   266  
   267  	/godebug/non-default-behavior/http2client:events
   268  		The number of non-default behaviors executed by the net/http
   269  		package due to a non-default GODEBUG=http2client=... setting.
   270  
   271  	/godebug/non-default-behavior/http2server:events
   272  		The number of non-default behaviors executed by the net/http
   273  		package due to a non-default GODEBUG=http2server=... setting.
   274  
   275  	/godebug/non-default-behavior/httpcookiemaxnum:events
   276  		The number of non-default behaviors executed by the net/http
   277  		package due to a non-default GODEBUG=httpcookiemaxnum=...
   278  		setting.
   279  
   280  	/godebug/non-default-behavior/httplaxcontentlength:events
   281  		The number of non-default behaviors executed by the net/http
   282  		package due to a non-default GODEBUG=httplaxcontentlength=...
   283  		setting.
   284  
   285  	/godebug/non-default-behavior/httpmuxgo121:events
   286  		The number of non-default behaviors executed by the net/http
   287  		package due to a non-default GODEBUG=httpmuxgo121=... setting.
   288  
   289  	/godebug/non-default-behavior/httpservecontentkeepheaders:events
   290  		The number of non-default behaviors executed
   291  		by the net/http package due to a non-default
   292  		GODEBUG=httpservecontentkeepheaders=... setting.
   293  
   294  	/godebug/non-default-behavior/installgoroot:events
   295  		The number of non-default behaviors executed by the go/build
   296  		package due to a non-default GODEBUG=installgoroot=... setting.
   297  
   298  	/godebug/non-default-behavior/multipartmaxheaders:events
   299  		The number of non-default behaviors executed by
   300  		the mime/multipart package due to a non-default
   301  		GODEBUG=multipartmaxheaders=... setting.
   302  
   303  	/godebug/non-default-behavior/multipartmaxparts:events
   304  		The number of non-default behaviors executed by
   305  		the mime/multipart package due to a non-default
   306  		GODEBUG=multipartmaxparts=... setting.
   307  
   308  	/godebug/non-default-behavior/multipathtcp:events
   309  		The number of non-default behaviors executed by the net package
   310  		due to a non-default GODEBUG=multipathtcp=... setting.
   311  
   312  	/godebug/non-default-behavior/netedns0:events
   313  		The number of non-default behaviors executed by the net package
   314  		due to a non-default GODEBUG=netedns0=... setting.
   315  
   316  	/godebug/non-default-behavior/panicnil:events
   317  		The number of non-default behaviors executed by the runtime
   318  		package due to a non-default GODEBUG=panicnil=... setting.
   319  
   320  	/godebug/non-default-behavior/randautoseed:events
   321  		The number of non-default behaviors executed by the math/rand
   322  		package due to a non-default GODEBUG=randautoseed=... setting.
   323  
   324  	/godebug/non-default-behavior/randseednop:events
   325  		The number of non-default behaviors executed by the math/rand
   326  		package due to a non-default GODEBUG=randseednop=... setting.
   327  
   328  	/godebug/non-default-behavior/rsa1024min:events
   329  		The number of non-default behaviors executed by the crypto/rsa
   330  		package due to a non-default GODEBUG=rsa1024min=... setting.
   331  
   332  	/godebug/non-default-behavior/tarinsecurepath:events
   333  		The number of non-default behaviors executed by the archive/tar
   334  		package due to a non-default GODEBUG=tarinsecurepath=...
   335  		setting.
   336  
   337  	/godebug/non-default-behavior/tls10server:events
   338  		The number of non-default behaviors executed by the crypto/tls
   339  		package due to a non-default GODEBUG=tls10server=... setting.
   340  
   341  	/godebug/non-default-behavior/tls3des:events
   342  		The number of non-default behaviors executed by the crypto/tls
   343  		package due to a non-default GODEBUG=tls3des=... setting.
   344  
   345  	/godebug/non-default-behavior/tlsmaxrsasize:events
   346  		The number of non-default behaviors executed by the crypto/tls
   347  		package due to a non-default GODEBUG=tlsmaxrsasize=... setting.
   348  
   349  	/godebug/non-default-behavior/tlsrsakex:events
   350  		The number of non-default behaviors executed by the crypto/tls
   351  		package due to a non-default GODEBUG=tlsrsakex=... setting.
   352  
   353  	/godebug/non-default-behavior/tlsunsafeekm:events
   354  		The number of non-default behaviors executed by the crypto/tls
   355  		package due to a non-default GODEBUG=tlsunsafeekm=... setting.
   356  
   357  	/godebug/non-default-behavior/winreadlinkvolume:events
   358  		The number of non-default behaviors executed by the os package
   359  		due to a non-default GODEBUG=winreadlinkvolume=... setting.
   360  
   361  	/godebug/non-default-behavior/winsymlink:events
   362  		The number of non-default behaviors executed by the os package
   363  		due to a non-default GODEBUG=winsymlink=... setting.
   364  
   365  	/godebug/non-default-behavior/x509keypairleaf:events
   366  		The number of non-default behaviors executed by the crypto/tls
   367  		package due to a non-default GODEBUG=x509keypairleaf=...
   368  		setting.
   369  
   370  	/godebug/non-default-behavior/x509negativeserial:events
   371  		The number of non-default behaviors executed by the crypto/x509
   372  		package due to a non-default GODEBUG=x509negativeserial=...
   373  		setting.
   374  
   375  	/godebug/non-default-behavior/x509rsacrt:events
   376  		The number of non-default behaviors executed by the crypto/x509
   377  		package due to a non-default GODEBUG=x509rsacrt=... setting.
   378  
   379  	/godebug/non-default-behavior/x509usefallbackroots:events
   380  		The number of non-default behaviors executed by the crypto/x509
   381  		package due to a non-default GODEBUG=x509usefallbackroots=...
   382  		setting.
   383  
   384  	/godebug/non-default-behavior/x509usepolicies:events
   385  		The number of non-default behaviors executed by the crypto/x509
   386  		package due to a non-default GODEBUG=x509usepolicies=...
   387  		setting.
   388  
   389  	/godebug/non-default-behavior/zipinsecurepath:events
   390  		The number of non-default behaviors executed by the archive/zip
   391  		package due to a non-default GODEBUG=zipinsecurepath=...
   392  		setting.
   393  
   394  	/memory/classes/heap/free:bytes
   395  		Memory that is completely free and eligible to be returned to
   396  		the underlying system, but has not been. This metric is the
   397  		runtime's estimate of free address space that is backed by
   398  		physical memory.
   399  
   400  	/memory/classes/heap/objects:bytes
   401  		Memory occupied by live objects and dead objects that have not
   402  		yet been marked free by the garbage collector.
   403  
   404  	/memory/classes/heap/released:bytes
   405  		Memory that is completely free and has been returned to the
   406  		underlying system. This metric is the runtime's estimate of free
   407  		address space that is still mapped into the process, but is not
   408  		backed by physical memory.
   409  
   410  	/memory/classes/heap/stacks:bytes
   411  		Memory allocated from the heap that is reserved for stack space,
   412  		whether or not it is currently in-use. Currently, this
   413  		represents all stack memory for goroutines. It also includes all
   414  		OS thread stacks in non-cgo programs. Note that stacks may be
   415  		allocated differently in the future, and this may change.
   416  
   417  	/memory/classes/heap/unused:bytes
   418  		Memory that is reserved for heap objects but is not currently
   419  		used to hold heap objects.
   420  
   421  	/memory/classes/metadata/mcache/free:bytes
   422  		Memory that is reserved for runtime mcache structures, but not
   423  		in-use.
   424  
   425  	/memory/classes/metadata/mcache/inuse:bytes
   426  		Memory that is occupied by runtime mcache structures that are
   427  		currently being used.
   428  
   429  	/memory/classes/metadata/mspan/free:bytes
   430  		Memory that is reserved for runtime mspan structures, but not
   431  		in-use.
   432  
   433  	/memory/classes/metadata/mspan/inuse:bytes
   434  		Memory that is occupied by runtime mspan structures that are
   435  		currently being used.
   436  
   437  	/memory/classes/metadata/other:bytes
   438  		Memory that is reserved for or used to hold runtime metadata.
   439  
   440  	/memory/classes/os-stacks:bytes
   441  		Stack memory allocated by the underlying operating system.
   442  		In non-cgo programs this metric is currently zero. This may
   443  		change in the future.In cgo programs this metric includes
   444  		OS thread stacks allocated directly from the OS. Currently,
   445  		this only accounts for one stack in c-shared and c-archive build
   446  		modes, and other sources of stacks from the OS are not measured.
   447  		This too may change in the future.
   448  
   449  	/memory/classes/other:bytes
   450  		Memory used by execution trace buffers, structures for debugging
   451  		the runtime, finalizer and profiler specials, and more.
   452  
   453  	/memory/classes/profiling/buckets:bytes
   454  		Memory that is used by the stack trace hash map used for
   455  		profiling.
   456  
   457  	/memory/classes/total:bytes
   458  		All memory mapped by the Go runtime into the current process
   459  		as read-write. Note that this does not include memory mapped
   460  		by code called via cgo or via the syscall package. Sum of all
   461  		metrics in /memory/classes.
   462  
   463  	/sched/gomaxprocs:threads
   464  		The current runtime.GOMAXPROCS setting, or the number of
   465  		operating system threads that can execute user-level Go code
   466  		simultaneously.
   467  
   468  	/sched/goroutines:goroutines
   469  		Count of live goroutines.
   470  
   471  	/sched/latencies:seconds
   472  		Distribution of the time goroutines have spent in the scheduler
   473  		in a runnable state before actually running. Bucket counts
   474  		increase monotonically.
   475  
   476  	/sched/pauses/stopping/gc:seconds
   477  		Distribution of individual GC-related stop-the-world stopping
   478  		latencies. This is the time it takes from deciding to stop the
   479  		world until all Ps are stopped. This is a subset of the total
   480  		GC-related stop-the-world time (/sched/pauses/total/gc:seconds).
   481  		During this time, some threads may be executing. Bucket counts
   482  		increase monotonically.
   483  
   484  	/sched/pauses/stopping/other:seconds
   485  		Distribution of individual non-GC-related stop-the-world
   486  		stopping latencies. This is the time it takes from deciding
   487  		to stop the world until all Ps are stopped. This is a
   488  		subset of the total non-GC-related stop-the-world time
   489  		(/sched/pauses/total/other:seconds). During this time, some
   490  		threads may be executing. Bucket counts increase monotonically.
   491  
   492  	/sched/pauses/total/gc:seconds
   493  		Distribution of individual GC-related stop-the-world pause
   494  		latencies. This is the time from deciding to stop the world
   495  		until the world is started again. Some of this time is spent
   496  		getting all threads to stop (this is measured directly in
   497  		/sched/pauses/stopping/gc:seconds), during which some threads
   498  		may still be running. Bucket counts increase monotonically.
   499  
   500  	/sched/pauses/total/other:seconds
   501  		Distribution of individual non-GC-related stop-the-world
   502  		pause latencies. This is the time from deciding to stop the
   503  		world until the world is started again. Some of this time
   504  		is spent getting all threads to stop (measured directly in
   505  		/sched/pauses/stopping/other:seconds). Bucket counts increase
   506  		monotonically.
   507  
   508  	/sync/mutex/wait/total:seconds
   509  		Approximate cumulative time goroutines have spent blocked on a
   510  		sync.Mutex, sync.RWMutex, or runtime-internal lock. This metric
   511  		is useful for identifying global changes in lock contention.
   512  		Collect a mutex or block profile using the runtime/pprof package
   513  		for more detailed contention data.
   514  */
   515  package metrics
   516  

View as plain text