Skip to content

Commit

Permalink
cmd/go: add telemetry counters for flag names and subcommand
Browse files Browse the repository at this point in the history
For #58894

Change-Id: I6b5d5b14be9858f5855eeac0110aa44e762cee03
Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-longtest
Reviewed-on: https://go-review.googlesource.com/c/go/+/559519
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
  • Loading branch information
matloob authored and pull[bot] committed Mar 7, 2024
1 parent fd36fcc commit 1347760
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/cmd/go/main.go
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
}

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 1347760

Please sign in to comment.