]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: rename flag counters and add buildmode values separately
authorMichael Matloob <matloob@golang.org>
Wed, 1 May 2024 18:17:24 +0000 (14:17 -0400)
committerMichael Matloob <matloob@golang.org>
Wed, 8 May 2024 16:49:53 +0000 (16:49 +0000)
Rename the subcommand flag counter names from
go/flag/<subcommand>/<flagname> to go/<subcommand>/flag/<flagname>.

Also remove the special case that adds counters for buildmode flag
values and instead add an additional counter for the flag values.
The new counter has the form go/<subcommand>/flag/buildmode:<flagvalue>.
We use a new CountFlagValue function that's been added to the
internal/telemetry package to help with this.

Finally add the go/invocations counter

Change-Id: I995b6b0009ba0f58faeb3e2a75f3b137e4136209
Reviewed-on: https://go-review.googlesource.com/c/go/+/583917
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
src/cmd/go/main.go
src/cmd/internal/telemetry/telemetry.go
src/cmd/internal/telemetry/telemetry_bootstrap.go

index 86f3c65a92db91cdd6b4b9c6cbcd25875414fcc7..72656dd9035ca554d2d79a1e5fddefcc804bd96f 100644 (file)
@@ -98,6 +98,7 @@ func main() {
 
        flag.Usage = base.Usage
        flag.Parse()
+       telemetry.Inc("go/invocations")
        telemetry.CountFlags("go/flag:", *flag.CommandLine)
 
        args := flag.Args()
@@ -252,14 +253,9 @@ func invoke(cmd *base.Command, args []string) {
        } else {
                base.SetFromGOFLAGS(&cmd.Flag)
                cmd.Flag.Parse(args[1:])
-               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)
-               })
+               flagCounterPrefix := "go/" + strings.ReplaceAll(cfg.CmdName, " ", "-") + "/flag"
+               telemetry.CountFlags(flagCounterPrefix+":", cmd.Flag)
+               telemetry.CountFlagValue(flagCounterPrefix+"/", cmd.Flag, "buildmode")
                args = cmd.Flag.Args()
        }
 
index d31f0eeff3dc7619cbf79aa96dd73ed1848abedd..2420a077089b606fd59b3c9c01490458ebd4b65a 100644 (file)
@@ -59,3 +59,18 @@ func NewStackCounter(name string, depth int) *counter.StackCounter {
 func CountFlags(prefix string, flagSet flag.FlagSet) {
        counter.CountFlags(prefix, flagSet)
 }
+
+// CountFlagValue creates a counter for the flag value
+// if it is set and increments the counter. The name of the
+// counter is the concatenation of prefix, the flagName, ":",
+// and value.String() for the flag's value.
+func CountFlagValue(prefix string, flagSet flag.FlagSet, flagName string) {
+       // TODO(matloob): Maybe pass in a list of flagNames if we end up counting
+       // values for more than one?
+       // TODO(matloob): Add this to x/telemetry?
+       flagSet.Visit(func(f *flag.Flag) {
+               if f.Name == flagName {
+                       counter.New(prefix + f.Name + ":" + f.Value.String()).Inc()
+               }
+       })
+}
index 2e127bec289dd6fc639db205cc8d3eb8c1cc68bb..01549b6970fee64097793ee3b8d7aa14fb106287 100644 (file)
@@ -12,9 +12,10 @@ type dummyCounter struct{}
 
 func (dc dummyCounter) Inc() {}
 
-func Start()                                              {}
-func StartWithUpload()                                    {}
-func Inc(name string)                                     {}
-func NewCounter(name string) dummyCounter                 { return dummyCounter{} }
-func NewStackCounter(name string, depth int) dummyCounter { return dummyCounter{} }
-func CountFlags(name string, flagSet flag.FlagSet)        {}
+func Start()                                                              {}
+func StartWithUpload()                                                    {}
+func Inc(name string)                                                     {}
+func NewCounter(name string) dummyCounter                                 { return dummyCounter{} }
+func NewStackCounter(name string, depth int) dummyCounter                 { return dummyCounter{} }
+func CountFlags(name string, flagSet flag.FlagSet)                        {}
+func CountFlagValue(prefix string, flagSet flag.FlagSet, flagName string) {}