Skip to content

Commit 9bd6e27

Browse files
committed
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 <[email protected]> Reviewed-by: David Chase <[email protected]> Run-TryBot: Michael Knyszek <[email protected]>
1 parent 364ced6 commit 9bd6e27

File tree

4 files changed

+17
-0
lines changed

4 files changed

+17
-0
lines changed

src/runtime/metrics.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ func initMetrics() {
6565

6666
timeHistBuckets = timeHistogramMetricsBuckets()
6767
metrics = map[string]metricData{
68+
"/cgo/go-to-c-calls:calls": {
69+
compute: func(_ *statAggregate, out *metricValue) {
70+
out.kind = metricKindUint64
71+
out.scalar = uint64(NumCgoCall())
72+
},
73+
},
6874
"/gc/cycles/automatic:gc-cycles": {
6975
deps: makeStatDepSet(sysStatsDep),
7076
compute: func(in *statAggregate, out *metricValue) {

src/runtime/metrics/description.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ type Description struct {
5151
// The English language descriptions below must be kept in sync with the
5252
// descriptions of each metric in doc.go.
5353
var allDesc = []Description{
54+
{
55+
Name: "/cgo/go-to-c-calls:calls",
56+
Description: "Count of calls made from Go to C by the current process.",
57+
Kind: KindUint64,
58+
Cumulative: true,
59+
},
5460
{
5561
Name: "/gc/cycles/automatic:gc-cycles",
5662
Description: "Count of completed GC cycles generated by the Go runtime.",

src/runtime/metrics/doc.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ classes of floating-point values: NaN, infinity.
5151
5252
Below is the full list of supported metrics, ordered lexicographically.
5353
54+
/cgo/go-to-c-calls:calls
55+
Count of calls made from Go to C by the current process.
56+
5457
/gc/cycles/automatic:gc-cycles
5558
Count of completed GC cycles generated by the Go runtime.
5659

src/runtime/metrics_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ func TestReadMetrics(t *testing.T) {
4646
var mallocs, frees uint64
4747
for i := range samples {
4848
switch name := samples[i].Name; name {
49+
case "/cgo/go-to-c-calls:calls":
50+
checkUint64(t, name, samples[i].Value.Uint64(), uint64(runtime.NumCgoCall()))
4951
case "/memory/classes/heap/free:bytes":
5052
checkUint64(t, name, samples[i].Value.Uint64(), mstats.HeapIdle-mstats.HeapReleased)
5153
case "/memory/classes/heap/released:bytes":

0 commit comments

Comments
 (0)