From 75f6f9c0b004228b5a2a6f4c6a7a9719321e29bd Mon Sep 17 00:00:00 2001 From: "Hana (Hyang-Ah) Kim" Date: Tue, 25 Jul 2023 17:55:04 -0400 Subject: [PATCH] gopls/internal/bug: add gopls/bug telemetry counter This counter (tentatively named 'gopls/bug') will track and report the number of `report` calls. Since bug.Report* can be called in a type loop, we increment the stack counter only where this is the first exemplar, and after getting out of the critical section. Change-Id: I42ee385bd69bc148454a82c98f7d623d5c803907 Reviewed-on: https://go-review.googlesource.com/c/tools/+/513100 Reviewed-by: Robert Findley Run-TryBot: Hyang-Ah Hana Kim Reviewed-by: Jamal Carvalho TryBot-Result: Gopher Robot Auto-Submit: Hyang-Ah Hana Kim --- gopls/internal/bug/bug.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/gopls/internal/bug/bug.go b/gopls/internal/bug/bug.go index f72948bec87..7331ba8c85c 100644 --- a/gopls/internal/bug/bug.go +++ b/gopls/internal/bug/bug.go @@ -18,6 +18,8 @@ import ( "sort" "sync" "time" + + "golang.org/x/telemetry/counter" ) // PanicOnBugs controls whether to panic when bugs are reported. @@ -63,6 +65,8 @@ func Report(description string) { report(description) } +var bugReport = counter.NewStack("gopls/bug", 16) + func report(description string) { _, file, line, ok := runtime.Caller(2) // all exported reporting functions call report directly @@ -84,17 +88,22 @@ func report(description string) { AtTime: time.Now(), } + newBug := false mu.Lock() if _, ok := exemplars[key]; !ok { if exemplars == nil { exemplars = make(map[string]Bug) } exemplars[key] = bug // capture one exemplar per key + newBug = true } hh := handlers handlers = nil mu.Unlock() + if newBug { + bugReport.Inc() + } // Call the handlers outside the critical section since a // handler may itself fail and call bug.Report. Since handlers // are one-shot, the inner call should be trivial.