1
0
mirror of https://github.com/golang/go synced 2024-11-15 05:40:32 -07:00

cmd/go: add flag values to counter for buildmode

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>
This commit is contained in:
Michael Matloob 2024-05-01 14:17:24 -04:00
parent 23f760fd58
commit 99fc317948

View File

@ -252,7 +252,14 @@ func invoke(cmd *base.Command, args []string) {
} else { } else {
base.SetFromGOFLAGS(&cmd.Flag) base.SetFromGOFLAGS(&cmd.Flag)
cmd.Flag.Parse(args[1:]) 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() args = cmd.Flag.Args()
} }