aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Anthony Knyszek <mknyszek@google.com>2020-08-07 16:37:29 +0000
committerMichael Knyszek <mknyszek@google.com>2020-10-26 21:48:03 +0000
commit80c6b92ecb911409f57d06793a1213395b75ebe2 (patch)
tree60b1a1ff9b161a445ebe1d5d6b3fac58a687d302
parentd39a89fd5843f535d634620d27110b320431f584 (diff)
downloadgo-80c6b92ecb911409f57d06793a1213395b75ebe2.tar.gz
go-80c6b92ecb911409f57d06793a1213395b75ebe2.zip
runtime,runtime/metrics: export goroutine count as a metric
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>
-rw-r--r--src/runtime/metrics.go6
-rw-r--r--src/runtime/metrics/description.go5
-rw-r--r--src/runtime/metrics/doc.go3
-rw-r--r--src/runtime/metrics_test.go4
4 files changed, 18 insertions, 0 deletions
diff --git a/src/runtime/metrics.go b/src/runtime/metrics.go
index 0e391472b2..d3c0341aee 100644
--- a/src/runtime/metrics.go
+++ b/src/runtime/metrics.go
@@ -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
}
diff --git a/src/runtime/metrics/description.go b/src/runtime/metrics/description.go
index 47959e467c..bc2e0882db 100644
--- a/src/runtime/metrics/description.go
+++ b/src/runtime/metrics/description.go
@@ -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.
diff --git a/src/runtime/metrics/doc.go b/src/runtime/metrics/doc.go
index 1e12ade5a1..e340f3d0dd 100644
--- a/src/runtime/metrics/doc.go
+++ b/src/runtime/metrics/doc.go
@@ -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
diff --git a/src/runtime/metrics_test.go b/src/runtime/metrics_test.go
index 7b3132bc30..167edd57fd 100644
--- a/src/runtime/metrics_test.go
+++ b/src/runtime/metrics_test.go
@@ -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 {