]> Cypherpunks repositories - gostls13.git/commitdiff
runtime,runtime/metrics: export goroutine count as a metric
authorMichael Anthony Knyszek <mknyszek@google.com>
Fri, 7 Aug 2020 16:37:29 +0000 (16:37 +0000)
committerMichael Knyszek <mknyszek@google.com>
Mon, 26 Oct 2020 21:48:03 +0000 (21:48 +0000)
For #37112.

Change-Id: I994dfe848605b95ef6aec24f53869e929247e987
Reviewed-on: https://go-review.googlesource.com/c/go/+/247049
Run-TryBot: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
src/runtime/metrics.go
src/runtime/metrics/description.go
src/runtime/metrics/doc.go
src/runtime/metrics_test.go

index 0e391472b299da3a2d70f0efc5fb9c502c3ac54a..d3c0341aee81fb17667d1d34ff38c37ca93330fc 100644 (file)
@@ -214,6 +214,12 @@ func initMetrics() {
                                        in.sysStats.gcMiscSys + in.sysStats.otherSys
                        },
                },
+               "/sched/goroutines:goroutines": {
+                       compute: func(_ *statAggregate, out *metricValue) {
+                               out.kind = metricKindUint64
+                               out.scalar = uint64(gcount())
+                       },
+               },
        }
        metricsInit = true
 }
index 47959e467cd52ed5f8d25c81658a99d1d0581f33..bc2e0882db6535032e2a63c076b54bf8c4c929a0 100644 (file)
@@ -163,6 +163,11 @@ var allDesc = []Description{
                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.",
                Kind:        KindUint64,
        },
+       {
+               Name:        "/sched/goroutines:goroutines",
+               Description: "Count of live goroutines.",
+               Kind:        KindUint64,
+       },
 }
 
 // All returns a slice of containing metric descriptions for all supported metrics.
index 1e12ade5a1b59b4fb08608b6710e0e2f838c20f4..e340f3d0dd6f6f4d76ea56e0b811a30d9076d0d6 100644 (file)
@@ -123,5 +123,8 @@ Supported metrics
                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/goroutines:goroutines
+               Count of live goroutines.
 */
 package metrics
index 7b3132bc30a8478994c553f1396324ff34ef0081..167edd57fd882151a3eab3f2954280b613feda46 100644 (file)
@@ -145,6 +145,10 @@ func TestReadMetricsConsistency(t *testing.T) {
                        for i := range h.Counts {
                                gc.pauses += h.Counts[i]
                        }
+               case "/sched/goroutines:goroutines":
+                       if samples[i].Value.Uint64() < 1 {
+                               t.Error("number of goroutines is less than one")
+                       }
                }
        }
        if totalVirtual.got != totalVirtual.want {