Source file src/cmd/go/internal/telemetrystats/telemetrystats.go

     1  // Copyright 2024 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  //go:build !cmd_go_bootstrap
     6  
     7  package telemetrystats
     8  
     9  import (
    10  	"cmd/go/internal/base"
    11  	"cmd/go/internal/cfg"
    12  	"cmd/go/internal/modload"
    13  	"cmd/internal/telemetry/counter"
    14  	"strings"
    15  )
    16  
    17  func Increment() {
    18  	incrementConfig()
    19  	incrementVersionCounters()
    20  }
    21  
    22  // incrementConfig increments counters for the configuration
    23  // the command is running in.
    24  func incrementConfig() {
    25  	if !modload.WillBeEnabled() {
    26  		counter.Inc("go/mode:gopath")
    27  	} else if workfile := modload.FindGoWork(base.Cwd()); workfile != "" {
    28  		counter.Inc("go/mode:workspace")
    29  	} else {
    30  		counter.Inc("go/mode:module")
    31  	}
    32  	counter.Inc("go/platform/target/goos:" + cfg.Goos)
    33  	counter.Inc("go/platform/target/goarch:" + cfg.Goarch)
    34  	switch cfg.Goarch {
    35  	case "386":
    36  		counter.Inc("go/platform/target/go386:" + cfg.GO386)
    37  	case "amd64":
    38  		counter.Inc("go/platform/target/goamd64:" + cfg.GOAMD64)
    39  	case "arm":
    40  		counter.Inc("go/platform/target/goarm:" + cfg.GOARM)
    41  	case "arm64":
    42  		counter.Inc("go/platform/target/goarm64:" + cfg.GOARM64)
    43  	case "mips":
    44  		counter.Inc("go/platform/target/gomips:" + cfg.GOMIPS)
    45  	case "ppc64":
    46  		counter.Inc("go/platform/target/goppc64:" + cfg.GOPPC64)
    47  	case "riscv64":
    48  		counter.Inc("go/platform/target/goriscv64:" + cfg.GORISCV64)
    49  	case "wasm":
    50  		counter.Inc("go/platform/target/gowasm:" + cfg.GOWASM)
    51  	}
    52  
    53  	// Use cfg.Experiment.String instead of cfg.Experiment.Enabled
    54  	// because we only want to count the experiments that differ
    55  	// from the baseline.
    56  	if cfg.Experiment != nil {
    57  		for exp := range strings.SplitSeq(cfg.Experiment.String(), ",") {
    58  			if exp == "" {
    59  				continue
    60  			}
    61  			counter.Inc("go/goexperiment:" + exp)
    62  		}
    63  	}
    64  }
    65  

View as plain text