]> Cypherpunks.ru repositories - gostls13.git/commitdiff
runtime/metrics: add gomaxprocs metric
authorMichael Anthony Knyszek <mknyszek@google.com>
Wed, 4 May 2022 20:06:18 +0000 (20:06 +0000)
committerMichael Knyszek <mknyszek@google.com>
Fri, 13 May 2022 16:02:59 +0000 (16:02 +0000)
For #47216.

Change-Id: Ib2d48c4583570a2dae9510a52d4c6ffc20161b31
Reviewed-on: https://go-review.googlesource.com/c/go/+/404305
Reviewed-by: David Chase <drchase@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Michael Knyszek <mknyszek@google.com>

src/runtime/metrics.go
src/runtime/metrics/description.go
src/runtime/metrics/doc.go
src/runtime/metrics_test.go

index 8ef495faed74bb055b724047a12ae7323c61faa5..125539b682158ac644e92da7a83fa873f7473b62 100644 (file)
@@ -280,6 +280,12 @@ func initMetrics() {
                                        in.sysStats.gcMiscSys + in.sysStats.otherSys
                        },
                },
+               "/sched/gomaxprocs:threads": {
+                       compute: func(_ *statAggregate, out *metricValue) {
+                               out.kind = metricKindUint64
+                               out.scalar = uint64(gomaxprocs)
+                       },
+               },
                "/sched/goroutines:goroutines": {
                        compute: func(_ *statAggregate, out *metricValue) {
                                out.kind = metricKindUint64
index 80aa930fd0ed669671ab952a82b782a1af9c03ac..52351772363845c43858819b2edf9d0a351d6481 100644 (file)
@@ -220,6 +220,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/gomaxprocs:threads",
+               Description: "The current runtime.GOMAXPROCS setting, or the number of operating system threads that can execute user-level Go code simultaneously.",
+               Kind:        KindUint64,
+       },
        {
                Name:        "/sched/goroutines:goroutines",
                Description: "Count of live goroutines.",
index fcc9d1a3a4501d3e8748a898efb3b93c032b8321..30fdf06a71a684479ac4931efd59d1cf4cc80454 100644 (file)
@@ -167,6 +167,11 @@ Below is the full list of supported metrics, ordered lexicographically.
                by code called via cgo or via the syscall package.
                Sum of all metrics in /memory/classes.
 
+       /sched/gomaxprocs:threads
+               The current runtime.GOMAXPROCS setting, or the number of
+               operating system threads that can execute user-level Go code
+               simultaneously.
+
        /sched/goroutines:goroutines
                Count of live goroutines.
 
index 4bd1408dbea24cc93279b845d076569548ac612b..6c9ca1b5f0dd1082aab66f4305d3ca191df4748c 100644 (file)
@@ -223,6 +223,10 @@ func TestReadMetricsConsistency(t *testing.T) {
                        for i := range h.Counts {
                                gc.pauses += h.Counts[i]
                        }
+               case "/sched/gomaxprocs:threads":
+                       if got, want := samples[i].Value.Uint64(), uint64(runtime.GOMAXPROCS(-1)); got != want {
+                               t.Errorf("gomaxprocs doesn't match runtime.GOMAXPROCS: got %d, want %d", got, want)
+                       }
                case "/sched/goroutines:goroutines":
                        if samples[i].Value.Uint64() < 1 {
                                t.Error("number of goroutines is less than one")