Skip to content

Commit 80c6b92

Browse files
committed
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 <[email protected]> TryBot-Result: Go Bot <[email protected]> Trust: Michael Knyszek <[email protected]> Reviewed-by: Michael Pratt <[email protected]>
1 parent d39a89f commit 80c6b92

File tree

4 files changed

+18
-0
lines changed

4 files changed

+18
-0
lines changed

src/runtime/metrics.go

+6
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,12 @@ func initMetrics() {
214214
in.sysStats.gcMiscSys + in.sysStats.otherSys
215215
},
216216
},
217+
"/sched/goroutines:goroutines": {
218+
compute: func(_ *statAggregate, out *metricValue) {
219+
out.kind = metricKindUint64
220+
out.scalar = uint64(gcount())
221+
},
222+
},
217223
}
218224
metricsInit = true
219225
}

src/runtime/metrics/description.go

+5
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,11 @@ var allDesc = []Description{
163163
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.",
164164
Kind: KindUint64,
165165
},
166+
{
167+
Name: "/sched/goroutines:goroutines",
168+
Description: "Count of live goroutines.",
169+
Kind: KindUint64,
170+
},
166171
}
167172

168173
// All returns a slice of containing metric descriptions for all supported metrics.

src/runtime/metrics/doc.go

+3
Original file line numberDiff line numberDiff line change
@@ -123,5 +123,8 @@ Supported metrics
123123
as read-write. Note that this does not include memory mapped
124124
by code called via cgo or via the syscall package.
125125
Sum of all metrics in /memory/classes.
126+
127+
/sched/goroutines:goroutines
128+
Count of live goroutines.
126129
*/
127130
package metrics

src/runtime/metrics_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ func TestReadMetricsConsistency(t *testing.T) {
145145
for i := range h.Counts {
146146
gc.pauses += h.Counts[i]
147147
}
148+
case "/sched/goroutines:goroutines":
149+
if samples[i].Value.Uint64() < 1 {
150+
t.Error("number of goroutines is less than one")
151+
}
148152
}
149153
}
150154
if totalVirtual.got != totalVirtual.want {

0 commit comments

Comments
 (0)