Skip to content

Commit 99fc317

Browse files
committed
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>
1 parent 23f760f commit 99fc317

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/cmd/go/main.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,14 @@ func invoke(cmd *base.Command, args []string) {
252252
} else {
253253
base.SetFromGOFLAGS(&cmd.Flag)
254254
cmd.Flag.Parse(args[1:])
255-
telemetry.CountFlags("go/flag:"+strings.ReplaceAll(cfg.CmdName, " ", "-")+"-", cmd.Flag)
255+
prefix := "go/flag:" + strings.ReplaceAll(cfg.CmdName, " ", "-") + "-"
256+
cmd.Flag.Visit(func(f *flag.Flag) {
257+
counterName := prefix + f.Name
258+
if f.Name == "buildmode" { // Special case: there is a limited set of buildmode values
259+
counterName += "-" + f.Value.String()
260+
}
261+
telemetry.Inc(counterName)
262+
})
256263
args = cmd.Flag.Args()
257264
}
258265

0 commit comments

Comments
 (0)