]> Cypherpunks repositories - gostls13.git/commitdiff
runtime/metrics: add the number of Go-to-C calls
authorMichael Anthony Knyszek <mknyszek@google.com>
Thu, 5 May 2022 16:54:44 +0000 (16:54 +0000)
committerMichael Knyszek <mknyszek@google.com>
Fri, 13 May 2022 20:45:09 +0000 (20:45 +0000)
For #47216.

Change-Id: I1c2cd518e6ff510cc3ac8d8f72fd52eadcabc16c
Reviewed-on: https://go-review.googlesource.com/c/go/+/404306
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
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 125539b682158ac644e92da7a83fa873f7473b62..2bff44c46686b402081d35f77aeebc68f9c39646 100644 (file)
@@ -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) {
index 52351772363845c43858819b2edf9d0a351d6481..a33d9a2c35af236c0f9f524ca02c79c2fb5e2699 100644 (file)
@@ -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.",
index 30fdf06a71a684479ac4931efd59d1cf4cc80454..b4d99f72bb5a10ffdb78ce44eabd8d0d2ea77894 100644 (file)
@@ -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.
 
index 6c9ca1b5f0dd1082aab66f4305d3ca191df4748c..8baf0209000731e36402c0407b64c8e7be6314d6 100644 (file)
@@ -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":