cmd/go: add telemetry counters for flag names and subcommand

For #58894,#65586

This is a revert of CL 560655 which was a revert of CL 559519.
CL 559519 was reverted because it was broken on windows/386. But now
CL 562715 pulls in x/telemetry CL 560462 which disables telemetry on
windows/386, fixing that issue.

Change-Id: I094e90c28bca02f2303807d3b008f2ef9d59433c
Reviewed-on: https://go-review.googlesource.com/c/go/+/562735
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Michael Matloob <matloob@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
Michael Matloob 2024-02-08 17:50:44 +00:00
parent c2de2912cb
commit 58fea5dfaf
1 changed files with 4 additions and 0 deletions

View File

@ -97,6 +97,7 @@ func main() {
flag.Usage = base.Usage
flag.Parse()
counter.CountFlags("cmd/go:flag-", *flag.CommandLine)
args := flag.Args()
if len(args) < 1 {
@ -152,6 +153,7 @@ func main() {
cmd, used := lookupCmd(args)
cfg.CmdName = strings.Join(args[:used], " ")
counter.Inc("cmd/go:subcommand-" + strings.ReplaceAll(cfg.CmdName, " ", "-"))
if len(cmd.Commands) > 0 {
if used >= len(args) {
help.PrintUsage(os.Stderr, cmd)
@ -239,6 +241,7 @@ func invoke(cmd *base.Command, args []string) {
} else {
base.SetFromGOFLAGS(&cmd.Flag)
cmd.Flag.Parse(args[1:])
counter.CountFlags("cmd/go/"+cmd.Name()+":flag-", cmd.Flag)
args = cmd.Flag.Args()
}
@ -323,6 +326,7 @@ func handleChdirFlag() {
_, dir, _ = strings.Cut(a, "=")
os.Args = slices.Delete(os.Args, used, used+1)
}
counter.Inc("cmd/go:flag-C")
if err := os.Chdir(dir); err != nil {
base.Fatalf("go: %v", err)