]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: add additional counters for mode and host/target OS and arch
authorMichael Matloob <matloob@golang.org>
Mon, 20 May 2024 14:38:40 +0000 (10:38 -0400)
committerGopher Robot <gobot@golang.org>
Wed, 22 May 2024 21:09:11 +0000 (21:09 +0000)
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 <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Sam Thanawalla <samthanawalla@google.com>
Auto-Submit: Michael Matloob <matloob@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
src/cmd/go/internal/telemetrystats/telemetrystats.go [new file with mode: 0644]
src/cmd/go/internal/telemetrystats/telemetrystats_bootstrap.go [new file with mode: 0644]
src/cmd/go/internal/telemetrystats/version_other.go [new file with mode: 0644]
src/cmd/go/internal/telemetrystats/version_unix.go [new file with mode: 0644]
src/cmd/go/internal/telemetrystats/version_windows.go [new file with mode: 0644]
src/cmd/go/main.go

diff --git a/src/cmd/go/internal/telemetrystats/telemetrystats.go b/src/cmd/go/internal/telemetrystats/telemetrystats.go
new file mode 100644 (file)
index 0000000..610c4a2
--- /dev/null
@@ -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 (file)
index 0000000..1046763
--- /dev/null
@@ -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 (file)
index 0000000..b20294e
--- /dev/null
@@ -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 (file)
index 0000000..952f27e
--- /dev/null
@@ -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 (file)
index 0000000..e6a33e0
--- /dev/null
@@ -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))
+}
index fff817693ada841d789e8ca09fd5c9f61d491876..9d140de21575e133d18bb4fe6146977465f6e110 100644 (file)
@@ -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()
 }