From: Michael Matloob Date: Mon, 20 May 2024 14:38:40 +0000 (-0400) Subject: cmd/go: add additional counters for mode and host/target OS and arch X-Git-Tag: go1.23rc1~195 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=2b8d9e3997df9835bc33522fab917ab701c174b6;p=gostls13.git cmd/go: add additional counters for mode and host/target OS and arch The following counters are added: (* means we will record the actual value for the counter, but of course the config will limit us to collecting preknown values) go/mode:{gopath,workspace,module} go/platform/{host,target}/{goos,goarch}:* go/platform/target/{ go386,goamd64,goarm,goarm64,gomips,goppc64,goriscv64,gowasm}:* For windows and unix: go/platform/host/*/version:* go/platform/host/*/major-version:*-* For windows: go/platform/host/windows/build:* Change-Id: I3c865afede2382bae103e5b4b9d1aa6b20c123df Reviewed-on: https://go-review.googlesource.com/c/go/+/587115 LUCI-TryBot-Result: Go LUCI Reviewed-by: Sam Thanawalla Auto-Submit: Michael Matloob Reviewed-by: Robert Findley --- diff --git a/src/cmd/go/internal/telemetrystats/telemetrystats.go b/src/cmd/go/internal/telemetrystats/telemetrystats.go new file mode 100644 index 0000000000..610c4a22e8 --- /dev/null +++ b/src/cmd/go/internal/telemetrystats/telemetrystats.go @@ -0,0 +1,51 @@ +// Copyright 2024 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +//go:build !cmd_go_bootstrap + +package telemetrystats + +import ( + "cmd/go/internal/base" + "cmd/go/internal/cfg" + "cmd/go/internal/modload" + "cmd/internal/telemetry" +) + +func Increment() { + incrementConfig() + incrementVersionCounters() +} + +// incrementConfig increments counters for the configuration +// the command is running in. +func incrementConfig() { + if !modload.WillBeEnabled() { + telemetry.Inc("go/mode:gopath") + } else if workfile := modload.FindGoWork(base.Cwd()); workfile != "" { + telemetry.Inc("go/mode:workspace") + } else { + telemetry.Inc("go/mode:module") + } + telemetry.Inc("go/platform/target/goos:" + cfg.Goos) + telemetry.Inc("go/platform/target/goarch:" + cfg.Goarch) + switch cfg.Goarch { + case "386": + telemetry.Inc("go/platform/target/go386:" + cfg.GO386) + case "amd64": + telemetry.Inc("go/platform/target/goamd64:" + cfg.GOAMD64) + case "arm": + telemetry.Inc("go/platform/target/goarm:" + cfg.GOARM) + case "arm64": + telemetry.Inc("go/platform/target/goarm64:" + cfg.GOARM64) + case "mips": + telemetry.Inc("go/platform/target/gomips:" + cfg.GOMIPS) + case "ppc64": + telemetry.Inc("go/platform/target/goppc64:" + cfg.GOPPC64) + case "riscv64": + telemetry.Inc("go/platform/target/goriscv64:" + cfg.GORISCV64) + case "wasm": + telemetry.Inc("go/platform/target/gowasm:" + cfg.GOWASM) + } +} diff --git a/src/cmd/go/internal/telemetrystats/telemetrystats_bootstrap.go b/src/cmd/go/internal/telemetrystats/telemetrystats_bootstrap.go new file mode 100644 index 0000000000..104676382e --- /dev/null +++ b/src/cmd/go/internal/telemetrystats/telemetrystats_bootstrap.go @@ -0,0 +1,9 @@ +// Copyright 2024 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +//go:build cmd_go_bootstrap + +package telemetrystats + +func Increment() {} diff --git a/src/cmd/go/internal/telemetrystats/version_other.go b/src/cmd/go/internal/telemetrystats/version_other.go new file mode 100644 index 0000000000..b20294e223 --- /dev/null +++ b/src/cmd/go/internal/telemetrystats/version_other.go @@ -0,0 +1,13 @@ +// Copyright 2024 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +//go:build !cmd_go_bootstrap && !unix && !windows + +package telemetrystats + +import "cmd/internal/telemetry" + +func incrementVersionCounters() { + telemetry.Inc("go/platform:version-not-supported") +} diff --git a/src/cmd/go/internal/telemetrystats/version_unix.go b/src/cmd/go/internal/telemetrystats/version_unix.go new file mode 100644 index 0000000000..952f27e2b3 --- /dev/null +++ b/src/cmd/go/internal/telemetrystats/version_unix.go @@ -0,0 +1,55 @@ +// Copyright 2024 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +//go:build !cmd_go_bootstrap && unix + +package telemetrystats + +import ( + "bytes" + "fmt" + "runtime" + "strings" + + "cmd/internal/telemetry" + + "golang.org/x/sys/unix" +) + +func incrementVersionCounters() { + convert := func(nullterm []byte) string { + end := bytes.IndexByte(nullterm, 0) + if end < 0 { + end = len(nullterm) + } + return string(nullterm[:end]) + } + + var v unix.Utsname + err := unix.Uname(&v) + if err != nil { + telemetry.Inc(fmt.Sprintf("go/platform/host/%s/version:unknown-uname-error", runtime.GOOS)) + return + } + major, minor, ok := majorMinor(convert(v.Release[:])) + if !ok { + telemetry.Inc(fmt.Sprintf("go/platform/host/%s/version:unknown-bad-format", runtime.GOOS)) + return + } + telemetry.Inc(fmt.Sprintf("go/platform/host/%s/major-version:%s", runtime.GOOS, major)) + telemetry.Inc(fmt.Sprintf("go/platform/host/%s/version:%s-%s", runtime.GOOS, major, minor)) + +} + +func majorMinor(v string) (string, string, bool) { + firstDot := strings.Index(v, ".") + if firstDot < 0 { + return "", "", false + } + major := v[:firstDot] + v = v[firstDot+len("."):] + secondDot := strings.Index(v, ".") + minor := v[:secondDot] + return major, minor, true +} diff --git a/src/cmd/go/internal/telemetrystats/version_windows.go b/src/cmd/go/internal/telemetrystats/version_windows.go new file mode 100644 index 0000000000..e6a33e00cd --- /dev/null +++ b/src/cmd/go/internal/telemetrystats/version_windows.go @@ -0,0 +1,22 @@ +// Copyright 2024 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +//go:build !cmd_go_bootstrap && windows + +package telemetrystats + +import ( + "fmt" + + "cmd/internal/telemetry" + + "golang.org/x/sys/windows" +) + +func incrementVersionCounters() { + v := windows.RtlGetVersion() + telemetry.Inc(fmt.Sprintf("go/platform/host/windows/major-version:%d", v.MajorVersion)) + telemetry.Inc(fmt.Sprintf("go/platform/host/windows/version:%d-%d", v.MajorVersion, v.MinorVersion)) + telemetry.Inc(fmt.Sprintf("go/platform/host/windows/build:%d", v.BuildNumber)) +} diff --git a/src/cmd/go/main.go b/src/cmd/go/main.go index fff817693a..9d140de215 100644 --- a/src/cmd/go/main.go +++ b/src/cmd/go/main.go @@ -35,6 +35,7 @@ import ( "cmd/go/internal/modload" "cmd/go/internal/run" "cmd/go/internal/telemetrycmd" + "cmd/go/internal/telemetrystats" "cmd/go/internal/test" "cmd/go/internal/tool" "cmd/go/internal/toolchain" @@ -206,6 +207,7 @@ func main() { if cfg.CmdName != "tool" { telemetry.Inc("go/subcommand:" + strings.ReplaceAll(cfg.CmdName, " ", "-")) } + telemetrystats.Increment() invoke(cmd, args[used-1:]) base.Exit() }