]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: add flag values to counter for buildmode
authorMichael Matloob <matloob@golang.org>
Wed, 1 May 2024 18:17:24 +0000 (14:17 -0400)
committerMichael Matloob <matloob@golang.org>
Fri, 3 May 2024 19:05:42 +0000 (19:05 +0000)
Usually, when we increment counters for flags, the counter only contains
the flag name. For the buildmode flag, we now include the flag value
because there's a limited set of values.

We can't use CountFlags directly anymore since we have different
behavior for buildmode.

Change-Id: I956a1a97d62850df3199b5514ad507ea51355c9f
Reviewed-on: https://go-review.googlesource.com/c/go/+/582896
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Sam Thanawalla <samthanawalla@google.com>
src/cmd/go/main.go

index dc2a8fd49c034fe6dfd88c99d371605ca26cce25..86f3c65a92db91cdd6b4b9c6cbcd25875414fcc7 100644 (file)
@@ -252,7 +252,14 @@ func invoke(cmd *base.Command, args []string) {
        } else {
                base.SetFromGOFLAGS(&cmd.Flag)
                cmd.Flag.Parse(args[1:])
-               telemetry.CountFlags("go/flag:"+strings.ReplaceAll(cfg.CmdName, " ", "-")+"-", cmd.Flag)
+               prefix := "go/flag:" + strings.ReplaceAll(cfg.CmdName, " ", "-") + "-"
+               cmd.Flag.Visit(func(f *flag.Flag) {
+                       counterName := prefix + f.Name
+                       if f.Name == "buildmode" { // Special case: there is a limited set of buildmode values
+                               counterName += "-" + f.Value.String()
+                       }
+                       telemetry.Inc(counterName)
+               })
                args = cmd.Flag.Args()
        }