From: Michael Anthony Knyszek Date: Thu, 5 May 2022 16:54:44 +0000 (+0000) Subject: runtime/metrics: add the number of Go-to-C calls X-Git-Tag: go1.19beta1~257 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=9bd6e2776f7dde746dc39923fd2bd994c91fd182;p=gostls13.git runtime/metrics: add the number of Go-to-C calls For #47216. Change-Id: I1c2cd518e6ff510cc3ac8d8f72fd52eadcabc16c Reviewed-on: https://go-review.googlesource.com/c/go/+/404306 TryBot-Result: Gopher Robot Reviewed-by: David Chase Run-TryBot: Michael Knyszek --- diff --git a/src/runtime/metrics.go b/src/runtime/metrics.go index 125539b682..2bff44c466 100644 --- a/src/runtime/metrics.go +++ b/src/runtime/metrics.go @@ -65,6 +65,12 @@ func initMetrics() { timeHistBuckets = timeHistogramMetricsBuckets() metrics = map[string]metricData{ + "/cgo/go-to-c-calls:calls": { + compute: func(_ *statAggregate, out *metricValue) { + out.kind = metricKindUint64 + out.scalar = uint64(NumCgoCall()) + }, + }, "/gc/cycles/automatic:gc-cycles": { deps: makeStatDepSet(sysStatsDep), compute: func(in *statAggregate, out *metricValue) { diff --git a/src/runtime/metrics/description.go b/src/runtime/metrics/description.go index 5235177236..a33d9a2c35 100644 --- a/src/runtime/metrics/description.go +++ b/src/runtime/metrics/description.go @@ -51,6 +51,12 @@ type Description struct { // The English language descriptions below must be kept in sync with the // descriptions of each metric in doc.go. var allDesc = []Description{ + { + Name: "/cgo/go-to-c-calls:calls", + Description: "Count of calls made from Go to C by the current process.", + Kind: KindUint64, + Cumulative: true, + }, { Name: "/gc/cycles/automatic:gc-cycles", Description: "Count of completed GC cycles generated by the Go runtime.", diff --git a/src/runtime/metrics/doc.go b/src/runtime/metrics/doc.go index 30fdf06a71..b4d99f72bb 100644 --- a/src/runtime/metrics/doc.go +++ b/src/runtime/metrics/doc.go @@ -51,6 +51,9 @@ classes of floating-point values: NaN, infinity. Below is the full list of supported metrics, ordered lexicographically. + /cgo/go-to-c-calls:calls + Count of calls made from Go to C by the current process. + /gc/cycles/automatic:gc-cycles Count of completed GC cycles generated by the Go runtime. diff --git a/src/runtime/metrics_test.go b/src/runtime/metrics_test.go index 6c9ca1b5f0..8baf020900 100644 --- a/src/runtime/metrics_test.go +++ b/src/runtime/metrics_test.go @@ -46,6 +46,8 @@ func TestReadMetrics(t *testing.T) { var mallocs, frees uint64 for i := range samples { switch name := samples[i].Name; name { + case "/cgo/go-to-c-calls:calls": + checkUint64(t, name, samples[i].Value.Uint64(), uint64(runtime.NumCgoCall())) case "/memory/classes/heap/free:bytes": checkUint64(t, name, samples[i].Value.Uint64(), mstats.HeapIdle-mstats.HeapReleased) case "/memory/classes/heap/released:bytes":