Skip to content

Commit 483a913

Browse files
committed
cmd/compile: add support for telemetry
Add cmd/internal/telemetry to cmd/dist's bootstrapDirs so it's built when bootstrapping the compiler. cmd/internal/telemetry is a wrapper arount telemetry functions that stubs out the functions when built in bootstrap mode to avoid dependencies on x/telemetry in bootstrap mode. Call telemetry.Start with an empty config to open the counter file, and increment a counter for when the command is invoked. After flags are parsed, increment a counter for each of the names of the flags that were passed in. The counter names will be compile/flag:<name> so for example we'll have compile/flag:e and compile/flag:E. In FatalfAt, increment a stack counter for internal errors. For #58894 Change-Id: Ia5a8a63aa43b2276641181626cbfbea7e4647faa Reviewed-on: https://go-review.googlesource.com/c/go/+/570679 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Cherry Mui <[email protected]>
1 parent 805f6b3 commit 483a913

File tree

4 files changed

+11
-0
lines changed

4 files changed

+11
-0
lines changed

src/cmd/compile/internal/base/flag.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package base
66

77
import (
88
"cmd/internal/cov/covcmd"
9+
"cmd/internal/telemetry"
910
"encoding/json"
1011
"flag"
1112
"fmt"
@@ -193,6 +194,7 @@ func ParseFlags() {
193194
objabi.AddVersionFlag() // -V
194195
registerFlags()
195196
objabi.Flagparse(usage)
197+
telemetry.CountFlags("compile/flag:", *flag.CommandLine)
196198

197199
if gcd := os.Getenv("GOCOMPILEDEBUG"); gcd != "" {
198200
// This will only override the flags set in gcd;

src/cmd/compile/internal/base/print.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"strings"
1515

1616
"cmd/internal/src"
17+
"cmd/internal/telemetry"
1718
)
1819

1920
// An errorMsg is a queued error message, waiting to be printed.
@@ -194,6 +195,8 @@ func Fatalf(format string, args ...interface{}) {
194195
FatalfAt(Pos, format, args...)
195196
}
196197

198+
var bugStack = telemetry.NewStackCounter("compile/bug", 16) // 16 is arbitrary; used by gopls and crashmonitor
199+
197200
// FatalfAt reports a fatal error - an internal problem - at pos and exits.
198201
// If other errors have already been printed, then FatalfAt just quietly exits.
199202
// (The internal problem may have been caused by incomplete information
@@ -209,6 +212,8 @@ func Fatalf(format string, args ...interface{}) {
209212
func FatalfAt(pos src.XPos, format string, args ...interface{}) {
210213
FlushErrors()
211214

215+
bugStack.Inc()
216+
212217
if Debug.Panic != 0 || numErrors == 0 {
213218
fmt.Printf("%v: internal compiler error: ", FmtPos(pos))
214219
fmt.Printf(format, args...)

src/cmd/compile/internal/gc/main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"cmd/internal/obj"
3131
"cmd/internal/objabi"
3232
"cmd/internal/src"
33+
"cmd/internal/telemetry"
3334
"flag"
3435
"fmt"
3536
"internal/buildcfg"
@@ -58,6 +59,8 @@ func handlePanic() {
5859
// code, and finally writes the compiled package definition to disk.
5960
func Main(archInit func(*ssagen.ArchInfo)) {
6061
base.Timer.Start("fe", "init")
62+
telemetry.Start()
63+
telemetry.Inc("compile/invocations")
6164

6265
defer handlePanic()
6366

src/cmd/dist/buildtool.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ var bootstrapDirs = []string{
5252
"cmd/internal/quoted",
5353
"cmd/internal/src",
5454
"cmd/internal/sys",
55+
"cmd/internal/telemetry",
5556
"cmd/link",
5657
"cmd/link/internal/...",
5758
"compress/flate",

0 commit comments

Comments
 (0)