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  	// TODO(jitsu): Telemetry for the go/mode counters should eventually be
    26  	// moved to modload.Init()
    27  	s := modload.NewState()
    28  	if !s.WillBeEnabled() {
    29  		counter.Inc("go/mode:gopath")
    30  	} else if workfile := s.FindGoWork(base.Cwd()); workfile != "" {
    31  		counter.Inc("go/mode:workspace")
    32  	} else {
    33  		counter.Inc("go/mode:module")
    34  	}
    35  
    36  	if cfg.BuildContext.CgoEnabled {
    37  		counter.Inc("go/cgo:enabled")
    38  	} else {
    39  		counter.Inc("go/cgo:disabled")
    40  	}
    41  
    42  	counter.Inc("go/platform/target/goos:" + cfg.Goos)
    43  	counter.Inc("go/platform/target/goarch:" + cfg.Goarch)
    44  	switch cfg.Goarch {
    45  	case "386":
    46  		counter.Inc("go/platform/target/go386:" + cfg.GO386)
    47  	case "amd64":
    48  		counter.Inc("go/platform/target/goamd64:" + cfg.GOAMD64)
    49  	case "arm":
    50  		counter.Inc("go/platform/target/goarm:" + cfg.GOARM)
    51  	case "arm64":
    52  		counter.Inc("go/platform/target/goarm64:" + cfg.GOARM64)
    53  	case "mips":
    54  		counter.Inc("go/platform/target/gomips:" + cfg.GOMIPS)
    55  	case "ppc64":
    56  		counter.Inc("go/platform/target/goppc64:" + cfg.GOPPC64)
    57  	case "riscv64":
    58  		counter.Inc("go/platform/target/goriscv64:" + cfg.GORISCV64)
    59  	case "wasm":
    60  		counter.Inc("go/platform/target/gowasm:" + cfg.GOWASM)
    61  	}
    62  
    63  	// Use cfg.Experiment.String instead of cfg.Experiment.Enabled
    64  	// because we only want to count the experiments that differ
    65  	// from the baseline.
    66  	if cfg.Experiment != nil {
    67  		for exp := range strings.SplitSeq(cfg.Experiment.String(), ",") {
    68  			if exp == "" {
    69  				continue
    70  			}
    71  			counter.Inc("go/goexperiment:" + exp)
    72  		}
    73  	}
    74  }
    75  

View as plain text