mirror of
https://github.com/golang/go
synced 2024-11-15 05:40:32 -07:00
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 <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
This commit is contained in:
parent
805f6b3f5d
commit
483a913a55
@ -6,6 +6,7 @@ package base
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"cmd/internal/cov/covcmd"
|
"cmd/internal/cov/covcmd"
|
||||||
|
"cmd/internal/telemetry"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -193,6 +194,7 @@ func ParseFlags() {
|
|||||||
objabi.AddVersionFlag() // -V
|
objabi.AddVersionFlag() // -V
|
||||||
registerFlags()
|
registerFlags()
|
||||||
objabi.Flagparse(usage)
|
objabi.Flagparse(usage)
|
||||||
|
telemetry.CountFlags("compile/flag:", *flag.CommandLine)
|
||||||
|
|
||||||
if gcd := os.Getenv("GOCOMPILEDEBUG"); gcd != "" {
|
if gcd := os.Getenv("GOCOMPILEDEBUG"); gcd != "" {
|
||||||
// This will only override the flags set in gcd;
|
// This will only override the flags set in gcd;
|
||||||
|
@ -14,6 +14,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"cmd/internal/src"
|
"cmd/internal/src"
|
||||||
|
"cmd/internal/telemetry"
|
||||||
)
|
)
|
||||||
|
|
||||||
// An errorMsg is a queued error message, waiting to be printed.
|
// An errorMsg is a queued error message, waiting to be printed.
|
||||||
@ -194,6 +195,8 @@ func Fatalf(format string, args ...interface{}) {
|
|||||||
FatalfAt(Pos, format, args...)
|
FatalfAt(Pos, format, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var bugStack = telemetry.NewStackCounter("compile/bug", 16) // 16 is arbitrary; used by gopls and crashmonitor
|
||||||
|
|
||||||
// FatalfAt reports a fatal error - an internal problem - at pos and exits.
|
// FatalfAt reports a fatal error - an internal problem - at pos and exits.
|
||||||
// If other errors have already been printed, then FatalfAt just quietly exits.
|
// If other errors have already been printed, then FatalfAt just quietly exits.
|
||||||
// (The internal problem may have been caused by incomplete information
|
// (The internal problem may have been caused by incomplete information
|
||||||
@ -209,6 +212,8 @@ func Fatalf(format string, args ...interface{}) {
|
|||||||
func FatalfAt(pos src.XPos, format string, args ...interface{}) {
|
func FatalfAt(pos src.XPos, format string, args ...interface{}) {
|
||||||
FlushErrors()
|
FlushErrors()
|
||||||
|
|
||||||
|
bugStack.Inc()
|
||||||
|
|
||||||
if Debug.Panic != 0 || numErrors == 0 {
|
if Debug.Panic != 0 || numErrors == 0 {
|
||||||
fmt.Printf("%v: internal compiler error: ", FmtPos(pos))
|
fmt.Printf("%v: internal compiler error: ", FmtPos(pos))
|
||||||
fmt.Printf(format, args...)
|
fmt.Printf(format, args...)
|
||||||
|
@ -30,6 +30,7 @@ import (
|
|||||||
"cmd/internal/obj"
|
"cmd/internal/obj"
|
||||||
"cmd/internal/objabi"
|
"cmd/internal/objabi"
|
||||||
"cmd/internal/src"
|
"cmd/internal/src"
|
||||||
|
"cmd/internal/telemetry"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"internal/buildcfg"
|
"internal/buildcfg"
|
||||||
@ -58,6 +59,8 @@ func handlePanic() {
|
|||||||
// code, and finally writes the compiled package definition to disk.
|
// code, and finally writes the compiled package definition to disk.
|
||||||
func Main(archInit func(*ssagen.ArchInfo)) {
|
func Main(archInit func(*ssagen.ArchInfo)) {
|
||||||
base.Timer.Start("fe", "init")
|
base.Timer.Start("fe", "init")
|
||||||
|
telemetry.Start()
|
||||||
|
telemetry.Inc("compile/invocations")
|
||||||
|
|
||||||
defer handlePanic()
|
defer handlePanic()
|
||||||
|
|
||||||
|
1
src/cmd/dist/buildtool.go
vendored
1
src/cmd/dist/buildtool.go
vendored
@ -52,6 +52,7 @@ var bootstrapDirs = []string{
|
|||||||
"cmd/internal/quoted",
|
"cmd/internal/quoted",
|
||||||
"cmd/internal/src",
|
"cmd/internal/src",
|
||||||
"cmd/internal/sys",
|
"cmd/internal/sys",
|
||||||
|
"cmd/internal/telemetry",
|
||||||
"cmd/link",
|
"cmd/link",
|
||||||
"cmd/link/internal/...",
|
"cmd/link/internal/...",
|
||||||
"compress/flate",
|
"compress/flate",
|
||||||
|
Loading…
Reference in New Issue
Block a user