Skip to content

Commit ece6ac4

Browse files
committed
runtime/metrics: add gomaxprocs metric
For #47216. Change-Id: Ib2d48c4583570a2dae9510a52d4c6ffc20161b31 Reviewed-on: https://go-review.googlesource.com/c/go/+/404305 Reviewed-by: David Chase <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Run-TryBot: Michael Knyszek <[email protected]>
1 parent 0f715f1 commit ece6ac4

File tree

4 files changed

+20
-0
lines changed

4 files changed

+20
-0
lines changed

src/runtime/metrics.go

+6
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,12 @@ func initMetrics() {
280280
in.sysStats.gcMiscSys + in.sysStats.otherSys
281281
},
282282
},
283+
"/sched/gomaxprocs:threads": {
284+
compute: func(_ *statAggregate, out *metricValue) {
285+
out.kind = metricKindUint64
286+
out.scalar = uint64(gomaxprocs)
287+
},
288+
},
283289
"/sched/goroutines:goroutines": {
284290
compute: func(_ *statAggregate, out *metricValue) {
285291
out.kind = metricKindUint64

src/runtime/metrics/description.go

+5
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,11 @@ var allDesc = []Description{
220220
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.",
221221
Kind: KindUint64,
222222
},
223+
{
224+
Name: "/sched/gomaxprocs:threads",
225+
Description: "The current runtime.GOMAXPROCS setting, or the number of operating system threads that can execute user-level Go code simultaneously.",
226+
Kind: KindUint64,
227+
},
223228
{
224229
Name: "/sched/goroutines:goroutines",
225230
Description: "Count of live goroutines.",

src/runtime/metrics/doc.go

+5
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,11 @@ Below is the full list of supported metrics, ordered lexicographically.
167167
by code called via cgo or via the syscall package.
168168
Sum of all metrics in /memory/classes.
169169
170+
/sched/gomaxprocs:threads
171+
The current runtime.GOMAXPROCS setting, or the number of
172+
operating system threads that can execute user-level Go code
173+
simultaneously.
174+
170175
/sched/goroutines:goroutines
171176
Count of live goroutines.
172177

src/runtime/metrics_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,10 @@ func TestReadMetricsConsistency(t *testing.T) {
223223
for i := range h.Counts {
224224
gc.pauses += h.Counts[i]
225225
}
226+
case "/sched/gomaxprocs:threads":
227+
if got, want := samples[i].Value.Uint64(), uint64(runtime.GOMAXPROCS(-1)); got != want {
228+
t.Errorf("gomaxprocs doesn't match runtime.GOMAXPROCS: got %d, want %d", got, want)
229+
}
226230
case "/sched/goroutines:goroutines":
227231
if samples[i].Value.Uint64() < 1 {
228232
t.Error("number of goroutines is less than one")

0 commit comments

Comments
 (0)