...

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

Documentation: cmd/go/internal/telemetrystats

     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.NewLoader()
    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  	counter.Inc("go/platform/target/port:" + cfg.Goos + "-" + cfg.Goarch)
    45  	switch cfg.Goarch {
    46  	case "386":
    47  		counter.Inc("go/platform/target/go386:" + cfg.GO386)
    48  	case "amd64":
    49  		counter.Inc("go/platform/target/goamd64:" + cfg.GOAMD64)
    50  	case "arm":
    51  		counter.Inc("go/platform/target/goarm:" + cfg.GOARM)
    52  	case "arm64":
    53  		counter.Inc("go/platform/target/goarm64:" + cfg.GOARM64)
    54  	case "mips":
    55  		counter.Inc("go/platform/target/gomips:" + cfg.GOMIPS)
    56  	case "ppc64":
    57  		counter.Inc("go/platform/target/goppc64:" + cfg.GOPPC64)
    58  	case "riscv64":
    59  		counter.Inc("go/platform/target/goriscv64:" + cfg.GORISCV64)
    60  	case "wasm":
    61  		counter.Inc("go/platform/target/gowasm:" + cfg.GOWASM)
    62  	}
    63  
    64  	// Use cfg.Experiment.String instead of cfg.Experiment.Enabled
    65  	// because we only want to count the experiments that differ
    66  	// from the baseline.
    67  	if cfg.Experiment != nil {
    68  		for exp := range strings.SplitSeq(cfg.Experiment.String(), ",") {
    69  			if exp == "" {
    70  				continue
    71  			}
    72  			counter.Inc("go/goexperiment:" + exp)
    73  		}
    74  	}
    75  }
    76  

View as plain text