github.com/twelsh-aw/go/src@v0.0.0-20230516233729-a56fe86a7c81/runtime/metrics/description.go (about)

     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  package metrics
     6  
     7  import "internal/godebugs"
     8  
     9  // Description describes a runtime metric.
    10  type Description struct {
    11  	// Name is the full name of the metric which includes the unit.
    12  	//
    13  	// The format of the metric may be described by the following regular expression.
    14  	//
    15  	// 	^(?P<name>/[^:]+):(?P<unit>[^:*/]+(?:[*/][^:*/]+)*)$
    16  	//
    17  	// The format splits the name into two components, separated by a colon: a path which always
    18  	// starts with a /, and a machine-parseable unit. The name may contain any valid Unicode
    19  	// codepoint in between / characters, but by convention will try to stick to lowercase
    20  	// characters and hyphens. An example of such a path might be "/memory/heap/free".
    21  	//
    22  	// The unit is by convention a series of lowercase English unit names (singular or plural)
    23  	// without prefixes delimited by '*' or '/'. The unit names may contain any valid Unicode
    24  	// codepoint that is not a delimiter.
    25  	// Examples of units might be "seconds", "bytes", "bytes/second", "cpu-seconds",
    26  	// "byte*cpu-seconds", and "bytes/second/second".
    27  	//
    28  	// For histograms, multiple units may apply. For instance, the units of the buckets and
    29  	// the count. By convention, for histograms, the units of the count are always "samples"
    30  	// with the type of sample evident by the metric's name, while the unit in the name
    31  	// specifies the buckets' unit.
    32  	//
    33  	// A complete name might look like "/memory/heap/free:bytes".
    34  	Name string
    35  
    36  	// Description is an English language sentence describing the metric.
    37  	Description string
    38  
    39  	// Kind is the kind of value for this metric.
    40  	//
    41  	// The purpose of this field is to allow users to filter out metrics whose values are
    42  	// types which their application may not understand.
    43  	Kind ValueKind
    44  
    45  	// Cumulative is whether or not the metric is cumulative. If a cumulative metric is just
    46  	// a single number, then it increases monotonically. If the metric is a distribution,
    47  	// then each bucket count increases monotonically.
    48  	//
    49  	// This flag thus indicates whether or not it's useful to compute a rate from this value.
    50  	Cumulative bool
    51  }
    52  
    53  // The English language descriptions below must be kept in sync with the
    54  // descriptions of each metric in doc.go by running 'go generate'.
    55  var allDesc = []Description{
    56  	{
    57  		Name:        "/cgo/go-to-c-calls:calls",
    58  		Description: "Count of calls made from Go to C by the current process.",
    59  		Kind:        KindUint64,
    60  		Cumulative:  true,
    61  	},
    62  	{
    63  		Name: "/cpu/classes/gc/mark/assist:cpu-seconds",
    64  		Description: "Estimated total CPU time goroutines spent performing GC tasks " +
    65  			"to assist the GC and prevent it from falling behind the application. " +
    66  			"This metric is an overestimate, and not directly comparable to " +
    67  			"system CPU time measurements. Compare only with other /cpu/classes " +
    68  			"metrics.",
    69  		Kind:       KindFloat64,
    70  		Cumulative: true,
    71  	},
    72  	{
    73  		Name: "/cpu/classes/gc/mark/dedicated:cpu-seconds",
    74  		Description: "Estimated total CPU time spent performing GC tasks on " +
    75  			"processors (as defined by GOMAXPROCS) dedicated to those tasks. " +
    76  			"This includes time spent with the world stopped due to the GC. " +
    77  			"This metric is an overestimate, and not directly comparable to " +
    78  			"system CPU time measurements. Compare only with other /cpu/classes " +
    79  			"metrics.",
    80  		Kind:       KindFloat64,
    81  		Cumulative: true,
    82  	},
    83  	{
    84  		Name: "/cpu/classes/gc/mark/idle:cpu-seconds",
    85  		Description: "Estimated total CPU time spent performing GC tasks on " +
    86  			"spare CPU resources that the Go scheduler could not otherwise find " +
    87  			"a use for. This should be subtracted from the total GC CPU time to " +
    88  			"obtain a measure of compulsory GC CPU time. " +
    89  			"This metric is an overestimate, and not directly comparable to " +
    90  			"system CPU time measurements. Compare only with other /cpu/classes " +
    91  			"metrics.",
    92  		Kind:       KindFloat64,
    93  		Cumulative: true,
    94  	},
    95  	{
    96  		Name: "/cpu/classes/gc/pause:cpu-seconds",
    97  		Description: "Estimated total CPU time spent with the application paused by " +
    98  			"the GC. Even if only one thread is running during the pause, this is " +
    99  			"computed as GOMAXPROCS times the pause latency because nothing else " +
   100  			"can be executing. This is the exact sum of samples in /gc/pause:seconds " +
   101  			"if each sample is multiplied by GOMAXPROCS at the time it is taken. " +
   102  			"This metric is an overestimate, and not directly comparable to " +
   103  			"system CPU time measurements. Compare only with other /cpu/classes " +
   104  			"metrics.",
   105  		Kind:       KindFloat64,
   106  		Cumulative: true,
   107  	},
   108  	{
   109  		Name: "/cpu/classes/gc/total:cpu-seconds",
   110  		Description: "Estimated total CPU time spent performing GC tasks. " +
   111  			"This metric is an overestimate, and not directly comparable to " +
   112  			"system CPU time measurements. Compare only with other /cpu/classes " +
   113  			"metrics. Sum of all metrics in /cpu/classes/gc.",
   114  		Kind:       KindFloat64,
   115  		Cumulative: true,
   116  	},
   117  	{
   118  		Name: "/cpu/classes/idle:cpu-seconds",
   119  		Description: "Estimated total available CPU time not spent executing any Go or Go runtime code. " +
   120  			"In other words, the part of /cpu/classes/total:cpu-seconds that was unused. " +
   121  			"This metric is an overestimate, and not directly comparable to " +
   122  			"system CPU time measurements. Compare only with other /cpu/classes " +
   123  			"metrics.",
   124  		Kind:       KindFloat64,
   125  		Cumulative: true,
   126  	},
   127  	{
   128  		Name: "/cpu/classes/scavenge/assist:cpu-seconds",
   129  		Description: "Estimated total CPU time spent returning unused memory to the " +
   130  			"underlying platform in response eagerly in response to memory pressure. " +
   131  			"This metric is an overestimate, and not directly comparable to " +
   132  			"system CPU time measurements. Compare only with other /cpu/classes " +
   133  			"metrics.",
   134  		Kind:       KindFloat64,
   135  		Cumulative: true,
   136  	},
   137  	{
   138  		Name: "/cpu/classes/scavenge/background:cpu-seconds",
   139  		Description: "Estimated total CPU time spent performing background tasks " +
   140  			"to return unused memory to the underlying platform. " +
   141  			"This metric is an overestimate, and not directly comparable to " +
   142  			"system CPU time measurements. Compare only with other /cpu/classes " +
   143  			"metrics.",
   144  		Kind:       KindFloat64,
   145  		Cumulative: true,
   146  	},
   147  	{
   148  		Name: "/cpu/classes/scavenge/total:cpu-seconds",
   149  		Description: "Estimated total CPU time spent performing tasks that return " +
   150  			"unused memory to the underlying platform. " +
   151  			"This metric is an overestimate, and not directly comparable to " +
   152  			"system CPU time measurements. Compare only with other /cpu/classes " +
   153  			"metrics. Sum of all metrics in /cpu/classes/scavenge.",
   154  		Kind:       KindFloat64,
   155  		Cumulative: true,
   156  	},
   157  	{
   158  		Name: "/cpu/classes/total:cpu-seconds",
   159  		Description: "Estimated total available CPU time for user Go code " +
   160  			"or the Go runtime, as defined by GOMAXPROCS. In other words, GOMAXPROCS " +
   161  			"integrated over the wall-clock duration this process has been executing for. " +
   162  			"This metric is an overestimate, and not directly comparable to " +
   163  			"system CPU time measurements. Compare only with other /cpu/classes " +
   164  			"metrics. Sum of all metrics in /cpu/classes.",
   165  		Kind:       KindFloat64,
   166  		Cumulative: true,
   167  	},
   168  	{
   169  		Name: "/cpu/classes/user:cpu-seconds",
   170  		Description: "Estimated total CPU time spent running user Go code. This may " +
   171  			"also include some small amount of time spent in the Go runtime. " +
   172  			"This metric is an overestimate, and not directly comparable to " +
   173  			"system CPU time measurements. Compare only with other /cpu/classes " +
   174  			"metrics.",
   175  		Kind:       KindFloat64,
   176  		Cumulative: true,
   177  	},
   178  	{
   179  		Name:        "/gc/cycles/automatic:gc-cycles",
   180  		Description: "Count of completed GC cycles generated by the Go runtime.",
   181  		Kind:        KindUint64,
   182  		Cumulative:  true,
   183  	},
   184  	{
   185  		Name:        "/gc/cycles/forced:gc-cycles",
   186  		Description: "Count of completed GC cycles forced by the application.",
   187  		Kind:        KindUint64,
   188  		Cumulative:  true,
   189  	},
   190  	{
   191  		Name:        "/gc/cycles/total:gc-cycles",
   192  		Description: "Count of all completed GC cycles.",
   193  		Kind:        KindUint64,
   194  		Cumulative:  true,
   195  	},
   196  	{
   197  		Name: "/gc/heap/allocs-by-size:bytes",
   198  		Description: "Distribution of heap allocations by approximate size. " +
   199  			"Bucket counts increase monotonically. " +
   200  			"Note that this does not include tiny objects as defined by " +
   201  			"/gc/heap/tiny/allocs:objects, only tiny blocks.",
   202  		Kind:       KindFloat64Histogram,
   203  		Cumulative: true,
   204  	},
   205  	{
   206  		Name:        "/gc/heap/allocs:bytes",
   207  		Description: "Cumulative sum of memory allocated to the heap by the application.",
   208  		Kind:        KindUint64,
   209  		Cumulative:  true,
   210  	},
   211  	{
   212  		Name: "/gc/heap/allocs:objects",
   213  		Description: "Cumulative count of heap allocations triggered by the application. " +
   214  			"Note that this does not include tiny objects as defined by " +
   215  			"/gc/heap/tiny/allocs:objects, only tiny blocks.",
   216  		Kind:       KindUint64,
   217  		Cumulative: true,
   218  	},
   219  	{
   220  		Name: "/gc/heap/frees-by-size:bytes",
   221  		Description: "Distribution of freed heap allocations by approximate size. " +
   222  			"Bucket counts increase monotonically. " +
   223  			"Note that this does not include tiny objects as defined by " +
   224  			"/gc/heap/tiny/allocs:objects, only tiny blocks.",
   225  		Kind:       KindFloat64Histogram,
   226  		Cumulative: true,
   227  	},
   228  	{
   229  		Name:        "/gc/heap/frees:bytes",
   230  		Description: "Cumulative sum of heap memory freed by the garbage collector.",
   231  		Kind:        KindUint64,
   232  		Cumulative:  true,
   233  	},
   234  	{
   235  		Name: "/gc/heap/frees:objects",
   236  		Description: "Cumulative count of heap allocations whose storage was freed " +
   237  			"by the garbage collector. " +
   238  			"Note that this does not include tiny objects as defined by " +
   239  			"/gc/heap/tiny/allocs:objects, only tiny blocks.",
   240  		Kind:       KindUint64,
   241  		Cumulative: true,
   242  	},
   243  	{
   244  		Name:        "/gc/heap/goal:bytes",
   245  		Description: "Heap size target for the end of the GC cycle.",
   246  		Kind:        KindUint64,
   247  	},
   248  	{
   249  		Name:        "/gc/heap/objects:objects",
   250  		Description: "Number of objects, live or unswept, occupying heap memory.",
   251  		Kind:        KindUint64,
   252  	},
   253  	{
   254  		Name: "/gc/heap/tiny/allocs:objects",
   255  		Description: "Count of small allocations that are packed together into blocks. " +
   256  			"These allocations are counted separately from other allocations " +
   257  			"because each individual allocation is not tracked by the runtime, " +
   258  			"only their block. Each block is already accounted for in " +
   259  			"allocs-by-size and frees-by-size.",
   260  		Kind:       KindUint64,
   261  		Cumulative: true,
   262  	},
   263  	{
   264  		Name: "/gc/limiter/last-enabled:gc-cycle",
   265  		Description: "GC cycle the last time the GC CPU limiter was enabled. " +
   266  			"This metric is useful for diagnosing the root cause of an out-of-memory " +
   267  			"error, because the limiter trades memory for CPU time when the GC's CPU " +
   268  			"time gets too high. This is most likely to occur with use of SetMemoryLimit. " +
   269  			"The first GC cycle is cycle 1, so a value of 0 indicates that it was never enabled.",
   270  		Kind: KindUint64,
   271  	},
   272  	{
   273  		Name:        "/gc/pauses:seconds",
   274  		Description: "Distribution of individual GC-related stop-the-world pause latencies. Bucket counts increase monotonically.",
   275  		Kind:        KindFloat64Histogram,
   276  		Cumulative:  true,
   277  	},
   278  	{
   279  		Name:        "/gc/stack/starting-size:bytes",
   280  		Description: "The stack size of new goroutines.",
   281  		Kind:        KindUint64,
   282  		Cumulative:  false,
   283  	},
   284  	{
   285  		Name: "/memory/classes/heap/free:bytes",
   286  		Description: "Memory that is completely free and eligible to be returned to the underlying system, " +
   287  			"but has not been. This metric is the runtime's estimate of free address space that is backed by " +
   288  			"physical memory.",
   289  		Kind: KindUint64,
   290  	},
   291  	{
   292  		Name:        "/memory/classes/heap/objects:bytes",
   293  		Description: "Memory occupied by live objects and dead objects that have not yet been marked free by the garbage collector.",
   294  		Kind:        KindUint64,
   295  	},
   296  	{
   297  		Name: "/memory/classes/heap/released:bytes",
   298  		Description: "Memory that is completely free and has been returned to the underlying system. This " +
   299  			"metric is the runtime's estimate of free address space that is still mapped into the process, " +
   300  			"but is not backed by physical memory.",
   301  		Kind: KindUint64,
   302  	},
   303  	{
   304  		Name:        "/memory/classes/heap/stacks:bytes",
   305  		Description: "Memory allocated from the heap that is reserved for stack space, whether or not it is currently in-use.",
   306  		Kind:        KindUint64,
   307  	},
   308  	{
   309  		Name:        "/memory/classes/heap/unused:bytes",
   310  		Description: "Memory that is reserved for heap objects but is not currently used to hold heap objects.",
   311  		Kind:        KindUint64,
   312  	},
   313  	{
   314  		Name:        "/memory/classes/metadata/mcache/free:bytes",
   315  		Description: "Memory that is reserved for runtime mcache structures, but not in-use.",
   316  		Kind:        KindUint64,
   317  	},
   318  	{
   319  		Name:        "/memory/classes/metadata/mcache/inuse:bytes",
   320  		Description: "Memory that is occupied by runtime mcache structures that are currently being used.",
   321  		Kind:        KindUint64,
   322  	},
   323  	{
   324  		Name:        "/memory/classes/metadata/mspan/free:bytes",
   325  		Description: "Memory that is reserved for runtime mspan structures, but not in-use.",
   326  		Kind:        KindUint64,
   327  	},
   328  	{
   329  		Name:        "/memory/classes/metadata/mspan/inuse:bytes",
   330  		Description: "Memory that is occupied by runtime mspan structures that are currently being used.",
   331  		Kind:        KindUint64,
   332  	},
   333  	{
   334  		Name:        "/memory/classes/metadata/other:bytes",
   335  		Description: "Memory that is reserved for or used to hold runtime metadata.",
   336  		Kind:        KindUint64,
   337  	},
   338  	{
   339  		Name:        "/memory/classes/os-stacks:bytes",
   340  		Description: "Stack memory allocated by the underlying operating system.",
   341  		Kind:        KindUint64,
   342  	},
   343  	{
   344  		Name:        "/memory/classes/other:bytes",
   345  		Description: "Memory used by execution trace buffers, structures for debugging the runtime, finalizer and profiler specials, and more.",
   346  		Kind:        KindUint64,
   347  	},
   348  	{
   349  		Name:        "/memory/classes/profiling/buckets:bytes",
   350  		Description: "Memory that is used by the stack trace hash map used for profiling.",
   351  		Kind:        KindUint64,
   352  	},
   353  	{
   354  		Name:        "/memory/classes/total:bytes",
   355  		Description: "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.",
   356  		Kind:        KindUint64,
   357  	},
   358  	{
   359  		Name:        "/sched/gomaxprocs:threads",
   360  		Description: "The current runtime.GOMAXPROCS setting, or the number of operating system threads that can execute user-level Go code simultaneously.",
   361  		Kind:        KindUint64,
   362  	},
   363  	{
   364  		Name:        "/sched/goroutines:goroutines",
   365  		Description: "Count of live goroutines.",
   366  		Kind:        KindUint64,
   367  	},
   368  	{
   369  		Name:        "/sched/latencies:seconds",
   370  		Description: "Distribution of the time goroutines have spent in the scheduler in a runnable state before actually running. Bucket counts increase monotonically.",
   371  		Kind:        KindFloat64Histogram,
   372  		Cumulative:  true,
   373  	},
   374  	{
   375  		Name:        "/sync/mutex/wait/total:seconds",
   376  		Description: "Approximate cumulative time goroutines have spent blocked on a sync.Mutex or sync.RWMutex. This metric is useful for identifying global changes in lock contention. Collect a mutex or block profile using the runtime/pprof package for more detailed contention data.",
   377  		Kind:        KindFloat64,
   378  		Cumulative:  true,
   379  	},
   380  }
   381  
   382  func init() {
   383  	// Insert all the non-default-reporting GODEBUGs into the table,
   384  	// preserving the overall sort order.
   385  	i := 0
   386  	for i < len(allDesc) && allDesc[i].Name < "/godebug/" {
   387  		i++
   388  	}
   389  	more := make([]Description, i, len(allDesc)+len(godebugs.All))
   390  	copy(more, allDesc)
   391  	for _, info := range godebugs.All {
   392  		if !info.Opaque {
   393  			more = append(more, Description{
   394  				Name: "/godebug/non-default-behavior/" + info.Name + ":events",
   395  				Description: "The number of non-default behaviors executed by the " +
   396  					info.Package + " package " + "due to a non-default " +
   397  					"GODEBUG=" + info.Name + "=... setting.",
   398  				Kind:       KindUint64,
   399  				Cumulative: true,
   400  			})
   401  		}
   402  	}
   403  	allDesc = append(more, allDesc[i:]...)
   404  }
   405  
   406  // All returns a slice of containing metric descriptions for all supported metrics.
   407  func All() []Description {
   408  	return allDesc
   409  }