"strings"
"cmd/internal/objfile"
- "cmd/internal/telemetry"
+ "cmd/internal/telemetry/counter"
)
func printUsage(w *os.File) {
func main() {
log.SetFlags(0)
log.SetPrefix("addr2line: ")
- telemetry.OpenCounters()
+ counter.Open()
// pprof expects this behavior when checking for addr2line
if len(os.Args) > 1 && os.Args[1] == "--help" {
flag.Usage = usage
flag.Parse()
- telemetry.Inc("addr2line/invocations")
- telemetry.CountFlags("addr2line/flag:", *flag.CommandLine)
+ counter.Inc("addr2line/invocations")
+ counter.CountFlags("addr2line/flag:", *flag.CommandLine)
if flag.NArg() != 1 {
usage()
}
"cmd/internal/bio"
"cmd/internal/obj"
"cmd/internal/objabi"
- "cmd/internal/telemetry"
+ "cmd/internal/telemetry/counter"
)
func main() {
log.SetFlags(0)
log.SetPrefix("asm: ")
- telemetry.OpenCounters()
+ counter.Open()
buildcfg.Check()
GOARCH := buildcfg.GOARCH
flags.Parse()
- telemetry.Inc("asm/invocations")
- telemetry.CountFlags("asm/flag:", *flag.CommandLine)
+ counter.Inc("asm/invocations")
+ counter.CountFlags("asm/flag:", *flag.CommandLine)
architecture := arch.Set(GOARCH, *flags.Shared || *flags.Dynlink)
if architecture == nil {
"strings"
"cmd/internal/buildid"
- "cmd/internal/telemetry"
+ "cmd/internal/telemetry/counter"
)
func usage() {
func main() {
log.SetPrefix("buildid: ")
log.SetFlags(0)
- telemetry.OpenCounters()
+ counter.Open()
flag.Usage = usage
flag.Parse()
- telemetry.Inc("buildid/invocations")
- telemetry.CountFlags("buildid/flag:", *flag.CommandLine)
+ counter.Inc("buildid/invocations")
+ counter.CountFlags("buildid/flag:", *flag.CommandLine)
if flag.NArg() != 1 {
usage()
}
"cmd/internal/edit"
"cmd/internal/notsha256"
"cmd/internal/objabi"
- "cmd/internal/telemetry"
+ "cmd/internal/telemetry/counter"
)
// A Package collects information about the package we're going to write.
var gccBaseCmd []string
func main() {
- telemetry.OpenCounters()
+ counter.Open()
objabi.AddVersionFlag() // -V
objabi.Flagparse(usage)
- telemetry.Inc("cgo/invocations")
- telemetry.CountFlags("cgo/flag:", *flag.CommandLine)
+ counter.Inc("cgo/invocations")
+ counter.CountFlags("cgo/flag:", *flag.CommandLine)
if *gccgoDefineCgoIncomplete {
if !*gccgo {
import (
"cmd/internal/cov/covcmd"
- "cmd/internal/telemetry"
+ "cmd/internal/telemetry/counter"
"encoding/json"
"flag"
"fmt"
objabi.AddVersionFlag() // -V
registerFlags()
objabi.Flagparse(usage)
- telemetry.CountFlags("compile/flag:", *flag.CommandLine)
+ counter.CountFlags("compile/flag:", *flag.CommandLine)
if gcd := os.Getenv("GOCOMPILEDEBUG"); gcd != "" {
// This will only override the flags set in gcd;
"strings"
"cmd/internal/src"
- "cmd/internal/telemetry"
+ "cmd/internal/telemetry/counter"
)
// An errorMsg is a queued error message, waiting to be printed.
FatalfAt(Pos, format, args...)
}
-var bugStack = telemetry.NewStackCounter("compile/bug", 16) // 16 is arbitrary; used by gopls and crashmonitor
+var bugStack = counter.NewStack("compile/bug", 16) // 16 is arbitrary; used by gopls and crashmonitor
// FatalfAt reports a fatal error - an internal problem - at pos and exits.
// If other errors have already been printed, then FatalfAt just quietly exits.
"cmd/internal/obj"
"cmd/internal/objabi"
"cmd/internal/src"
- "cmd/internal/telemetry"
+ "cmd/internal/telemetry/counter"
"flag"
"fmt"
"internal/buildcfg"
// code, and finally writes the compiled package definition to disk.
func Main(archInit func(*ssagen.ArchInfo)) {
base.Timer.Start("fe", "init")
- telemetry.OpenCounters()
- telemetry.Inc("compile/invocations")
+ counter.Open()
+ counter.Inc("compile/invocations")
defer handlePanic()
import (
"cmd/internal/cov"
"cmd/internal/pkgpattern"
- "cmd/internal/telemetry"
+ "cmd/internal/telemetry/counter"
"flag"
"fmt"
"os"
)
func main() {
- telemetry.OpenCounters()
+ counter.Open()
// First argument should be mode/subcommand.
if len(os.Args) < 2 {
op.Usage("")
}
flag.Parse()
- telemetry.Inc("covdata/invocations")
- telemetry.CountFlags("covdata/flag:", *flag.CommandLine)
+ counter.Inc("covdata/invocations")
+ counter.CountFlags("covdata/flag:", *flag.CommandLine)
// Mode-independent flag setup
dbgtrace(1, "starting mode-independent setup")
"cmd/internal/edit"
"cmd/internal/objabi"
- "cmd/internal/telemetry"
+ "cmd/internal/telemetry/counter"
)
const usageMessage = "" +
)
func main() {
- telemetry.OpenCounters()
+ counter.Open()
objabi.AddVersionFlag()
flag.Usage = usage
objabi.Flagparse(usage)
- telemetry.Inc("cover/invocations")
- telemetry.CountFlags("cover/flag:", *flag.CommandLine)
+ counter.Inc("cover/invocations")
+ counter.CountFlags("cover/flag:", *flag.CommandLine)
// Usage information when no arguments.
if flag.NFlag() == 0 && flag.NArg() == 0 {
"cmd/internal/src",
"cmd/internal/sys",
"cmd/internal/telemetry",
+ "cmd/internal/telemetry/counter",
"cmd/link",
"cmd/link/internal/...",
"compress/flate",
"strings"
"time"
- "cmd/internal/telemetry"
+ "cmd/internal/telemetry/counter"
)
func usage() {
func main() {
log.SetPrefix("distpack: ")
log.SetFlags(0)
- telemetry.OpenCounters()
+ counter.Open()
flag.Usage = usage
flag.Parse()
- telemetry.Inc("distpack/invocations")
- telemetry.CountFlags("distpack/flag:", *flag.CommandLine)
+ counter.Inc("distpack/invocations")
+ counter.CountFlags("distpack/flag:", *flag.CommandLine)
if flag.NArg() != 0 {
usage()
}
"path/filepath"
"strings"
- "cmd/internal/telemetry"
+ "cmd/internal/telemetry/counter"
)
var (
func main() {
log.SetFlags(0)
log.SetPrefix("doc: ")
- telemetry.OpenCounters()
+ counter.Open()
dirsInit()
err := do(os.Stdout, flag.CommandLine, os.Args[1:])
if err != nil {
flagSet.BoolVar(&showSrc, "src", false, "show source code for symbol")
flagSet.BoolVar(&short, "short", false, "one-line representation for each symbol")
flagSet.Parse(args)
- telemetry.Inc("doc/invocations")
- telemetry.CountFlags("doc/flag:", *flag.CommandLine)
+ counter.Inc("doc/invocations")
+ counter.CountFlags("doc/flag:", *flag.CommandLine)
if chdir != "" {
if err := os.Chdir(chdir); err != nil {
return err
"sort"
"strings"
- "cmd/internal/telemetry"
+ "cmd/internal/telemetry/counter"
)
var (
}
func main() {
- telemetry.OpenCounters()
+ counter.Open()
flag.Usage = usage
flag.Parse()
- telemetry.Inc("fix/invocations")
- telemetry.CountFlags("fix/flag:", *flag.CommandLine)
+ counter.Inc("fix/invocations")
+ counter.CountFlags("fix/flag:", *flag.CommandLine)
if !version.IsValid(*goVersion) {
report(fmt.Errorf("invalid -go=%s", *goVersion))
"unicode/utf8"
"cmd/go/internal/base"
- "cmd/internal/telemetry"
+ "cmd/internal/telemetry/counter"
)
-var counterErrorsHelpUnknownTopic = telemetry.NewCounter("go/errors:help-unknown-topic")
+var counterErrorsHelpUnknownTopic = counter.New("go/errors:help-unknown-topic")
// Help implements the 'help' command.
func Help(w io.Writer, args []string) {
"cmd/go/internal/modfetch/codehost"
"cmd/go/internal/par"
"cmd/go/internal/robustio"
- "cmd/internal/telemetry"
+ "cmd/internal/telemetry/counter"
"golang.org/x/mod/module"
"golang.org/x/mod/semver"
statCacheOnce sync.Once
statCacheErr error
- counterErrorsGOMODCACHEEntryRelative = telemetry.NewCounter("go/errors:gomodcache-entry-relative")
+ counterErrorsGOMODCACHEEntryRelative = counter.New("go/errors:gomodcache-entry-relative")
)
// checkCacheDir checks if the directory specified by GOMODCACHE exists. An
"cmd/go/internal/base"
"cmd/go/internal/cfg"
"cmd/go/internal/modload"
- "cmd/internal/telemetry"
+ "cmd/internal/telemetry/counter"
)
func Increment() {
// the command is running in.
func incrementConfig() {
if !modload.WillBeEnabled() {
- telemetry.Inc("go/mode:gopath")
+ counter.Inc("go/mode:gopath")
} else if workfile := modload.FindGoWork(base.Cwd()); workfile != "" {
- telemetry.Inc("go/mode:workspace")
+ counter.Inc("go/mode:workspace")
} else {
- telemetry.Inc("go/mode:module")
+ counter.Inc("go/mode:module")
}
- telemetry.Inc("go/platform/target/goos:" + cfg.Goos)
- telemetry.Inc("go/platform/target/goarch:" + cfg.Goarch)
+ counter.Inc("go/platform/target/goos:" + cfg.Goos)
+ counter.Inc("go/platform/target/goarch:" + cfg.Goarch)
switch cfg.Goarch {
case "386":
- telemetry.Inc("go/platform/target/go386:" + cfg.GO386)
+ counter.Inc("go/platform/target/go386:" + cfg.GO386)
case "amd64":
- telemetry.Inc("go/platform/target/goamd64:" + cfg.GOAMD64)
+ counter.Inc("go/platform/target/goamd64:" + cfg.GOAMD64)
case "arm":
- telemetry.Inc("go/platform/target/goarm:" + cfg.GOARM)
+ counter.Inc("go/platform/target/goarm:" + cfg.GOARM)
case "arm64":
- telemetry.Inc("go/platform/target/goarm64:" + cfg.GOARM64)
+ counter.Inc("go/platform/target/goarm64:" + cfg.GOARM64)
case "mips":
- telemetry.Inc("go/platform/target/gomips:" + cfg.GOMIPS)
+ counter.Inc("go/platform/target/gomips:" + cfg.GOMIPS)
case "ppc64":
- telemetry.Inc("go/platform/target/goppc64:" + cfg.GOPPC64)
+ counter.Inc("go/platform/target/goppc64:" + cfg.GOPPC64)
case "riscv64":
- telemetry.Inc("go/platform/target/goriscv64:" + cfg.GORISCV64)
+ counter.Inc("go/platform/target/goriscv64:" + cfg.GORISCV64)
case "wasm":
- telemetry.Inc("go/platform/target/gowasm:" + cfg.GOWASM)
+ counter.Inc("go/platform/target/gowasm:" + cfg.GOWASM)
}
}
package telemetrystats
-import "cmd/internal/telemetry"
+import "cmd/internal/telemetry/counter"
func incrementVersionCounters() {
- telemetry.Inc("go/platform:version-not-supported")
+ counter.Inc("go/platform:version-not-supported")
}
"runtime"
"strings"
- "cmd/internal/telemetry"
+ "cmd/internal/telemetry/counter"
"golang.org/x/sys/unix"
)
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))
+ counter.Inc(fmt.Sprintf("go/platform/host/%s/version:unknown-uname-error", runtime.GOOS))
return
}
major, minor, ok := majorMinor(convert(v.Release[:]))
major, minor, ok = convert(v.Version[:]), convert(v.Release[:]), true
}
if !ok {
- telemetry.Inc(fmt.Sprintf("go/platform/host/%s/version:unknown-bad-format", runtime.GOOS))
+ counter.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))
+ counter.Inc(fmt.Sprintf("go/platform/host/%s/major-version:%s", runtime.GOOS, major))
+ counter.Inc(fmt.Sprintf("go/platform/host/%s/version:%s-%s", runtime.GOOS, major, minor))
}
func majorMinor(v string) (string, string, bool) {
import (
"fmt"
- "cmd/internal/telemetry"
+ "cmd/internal/telemetry/counter"
"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))
+ counter.Inc(fmt.Sprintf("go/platform/host/windows/major-version:%d", v.MajorVersion))
+ counter.Inc(fmt.Sprintf("go/platform/host/windows/version:%d-%d", v.MajorVersion, v.MinorVersion))
+ counter.Inc(fmt.Sprintf("go/platform/host/windows/build:%d", v.BuildNumber))
}
package tool
import (
- "cmd/internal/telemetry"
+ "cmd/internal/telemetry/counter"
"context"
"encoding/json"
"flag"
func runTool(ctx context.Context, cmd *base.Command, args []string) {
if len(args) == 0 {
- telemetry.Inc("go/subcommand:tool")
+ counter.Inc("go/subcommand:tool")
listTools()
return
}
if impersonateDistList(args[2:]) {
// If it becomes necessary, we could increment an additional counter to indicate
// that we're impersonating dist list if knowing that becomes important?
- telemetry.Inc("go/subcommand:tool-dist")
+ counter.Inc("go/subcommand:tool-dist")
return
}
}
- telemetry.Inc("go/subcommand:tool-unknown")
+ counter.Inc("go/subcommand:tool-unknown")
// Emit the usual error for the missing tool.
_ = base.Tool(toolName)
} else {
// Increment a counter for the tool subcommand with the tool name.
- telemetry.Inc("go/subcommand:tool-" + toolName)
+ counter.Inc("go/subcommand:tool-" + toolName)
}
if toolN {
"cmd/go/internal/modload"
"cmd/go/internal/run"
"cmd/go/internal/work"
- "cmd/internal/telemetry"
+ "cmd/internal/telemetry/counter"
"golang.org/x/mod/module"
)
return out
}
-var counterErrorsInvalidToolchainInFile = telemetry.NewCounter("go/errors:invalid-toolchain-in-file")
+var counterErrorsInvalidToolchainInFile = counter.New("go/errors:invalid-toolchain-in-file")
// Select invokes a different Go toolchain if directed by
// the GOTOOLCHAIN environment variable or the user's configuration
Exec(gotoolchain)
}
-var counterSelectExec = telemetry.NewCounter("go/toolchain/select-exec")
+var counterSelectExec = counter.New("go/toolchain/select-exec")
// TestVersionSwitch is set in the test go binary to the value in $TESTGO_VERSION_SWITCH.
// Valid settings are:
"cmd/go/internal/cfg"
"cmd/go/internal/gover"
"cmd/go/internal/modfetch"
- "cmd/internal/telemetry"
+ "cmd/internal/telemetry/counter"
)
// A Switcher collects errors to be reported and then decides
panic("unreachable")
}
-var counterSwitchExec = telemetry.NewCounter("go/toolchain/switch-exec")
+var counterSwitchExec = counter.New("go/toolchain/switch-exec")
// SwitchOrFatal attempts a toolchain switch based on the information in err
// and otherwise falls back to base.Fatal(err).
"cmd/go/internal/str"
"cmd/internal/buildid"
"cmd/internal/quoted"
- "cmd/internal/telemetry"
+ "cmd/internal/telemetry/counter"
)
// Build IDs
}
var (
- counterCacheHit = telemetry.NewCounter("go/buildcache/hit")
- counterCacheMiss = telemetry.NewCounter("go/buildcache/miss")
+ counterCacheHit = counter.New("go/buildcache/hit")
+ counterCacheMiss = counter.New("go/buildcache/miss")
onceIncStdlibRecompiled sync.Once
- stdlibRecompiled = telemetry.NewCounter("go/buildcache/stdlib-recompiled")
+ stdlibRecompiled = counter.New("go/buildcache/stdlib-recompiled")
)
// useCache tries to satisfy the action a, which has action ID actionHash,
"cmd/go/internal/work"
"cmd/go/internal/workcmd"
"cmd/internal/telemetry"
+ "cmd/internal/telemetry/counter"
)
func init() {
var _ = go11tag
-var counterErrorsGOPATHEntryRelative = telemetry.NewCounter("go/errors:gopath-entry-relative")
+var counterErrorsGOPATHEntryRelative = counter.New("go/errors:gopath-entry-relative")
func main() {
log.SetFlags(0)
- telemetry.MaybeChild() // Run in child mode if this is the telemetry sidecar child process.
- telemetry.OpenCounters() // Open the telemetry counter file so counters can be written to it.
+ telemetry.MaybeChild() // Run in child mode if this is the telemetry sidecar child process.
+ counter.Open() // Open the telemetry counter file so counters can be written to it.
handleChdirFlag()
toolchain.Select()
telemetry.MaybeParent() // Run the upload process. Opening the counter file is idempotent.
flag.Usage = base.Usage
flag.Parse()
- telemetry.Inc("go/invocations")
- telemetry.CountFlags("go/flag:", *flag.CommandLine)
+ counter.Inc("go/invocations")
+ counter.CountFlags("go/flag:", *flag.CommandLine)
args := flag.Args()
if len(args) < 1 {
cfg.CmdName = args[0] // for error messages
if args[0] == "help" {
- telemetry.Inc("go/subcommand:" + strings.Join(append([]string{"help"}, args[1:]...), "-"))
+ counter.Inc("go/subcommand:" + strings.Join(append([]string{"help"}, args[1:]...), "-"))
help.Help(os.Stdout, args[1:])
return
}
}
switch strings.ToLower(cfg.GOROOT) {
case "/usr/local/go": // Location recommended for installation on Linux and Darwin and used by Mac installer.
- telemetry.Inc("go/goroot:usr-local-go")
+ counter.Inc("go/goroot:usr-local-go")
case "/usr/lib/go": // A typical location used by Linux package managers.
- telemetry.Inc("go/goroot:usr-lib-go")
+ counter.Inc("go/goroot:usr-lib-go")
case "/usr/lib/golang": // Another typical location used by Linux package managers.
- telemetry.Inc("go/goroot:usr-lib-golang")
+ counter.Inc("go/goroot:usr-lib-golang")
case `c:\program files\go`: // Location used by Windows installer.
- telemetry.Inc("go/goroot:program-files-go")
+ counter.Inc("go/goroot:program-files-go")
case `c:\program files (x86)\go`: // Location used by 386 Windows installer on amd64 platform.
- telemetry.Inc("go/goroot:program-files-x86-go")
+ counter.Inc("go/goroot:program-files-x86-go")
default:
- telemetry.Inc("go/goroot:other")
+ counter.Inc("go/goroot:other")
}
// Diagnose common mistake: GOPATH==GOROOT.
}
if args[used] == "help" {
// Accept 'go mod help' and 'go mod help foo' for 'go help mod' and 'go help mod foo'.
- telemetry.Inc("go/subcommand:" + strings.ReplaceAll(cfg.CmdName, " ", "-") + "-" + strings.Join(args[used:], "-"))
+ counter.Inc("go/subcommand:" + strings.ReplaceAll(cfg.CmdName, " ", "-") + "-" + strings.Join(args[used:], "-"))
help.Help(os.Stdout, append(slices.Clip(args[:used]), args[used+1:]...))
base.Exit()
}
if cmdName == "" {
cmdName = args[0]
}
- telemetry.Inc("go/subcommand:unknown")
+ counter.Inc("go/subcommand:unknown")
fmt.Fprintf(os.Stderr, "go %s: unknown command\nRun 'go help%s' for usage.\n", cmdName, helpArg)
base.SetExitStatus(2)
base.Exit()
// increment in the tool subcommand's Run function because we need
// to do the flag processing in invoke first.
if cfg.CmdName != "tool" {
- telemetry.Inc("go/subcommand:" + strings.ReplaceAll(cfg.CmdName, " ", "-"))
+ counter.Inc("go/subcommand:" + strings.ReplaceAll(cfg.CmdName, " ", "-"))
}
telemetrystats.Increment()
invoke(cmd, args[used-1:])
base.SetFromGOFLAGS(&cmd.Flag)
cmd.Flag.Parse(args[1:])
flagCounterPrefix := "go/" + strings.ReplaceAll(cfg.CmdName, " ", "-") + "/flag"
- telemetry.CountFlags(flagCounterPrefix+":", cmd.Flag)
- telemetry.CountFlagValue(flagCounterPrefix+"/", cmd.Flag, "buildmode")
+ counter.CountFlags(flagCounterPrefix+":", cmd.Flag)
+ counter.CountFlagValue(flagCounterPrefix+"/", cmd.Flag, "buildmode")
args = cmd.Flag.Args()
}
_, dir, _ = strings.Cut(a, "=")
os.Args = slices.Delete(os.Args, used, used+1)
}
- telemetry.Inc("go/flag:C")
+ counter.Inc("go/flag:C")
if err := os.Chdir(dir); err != nil {
base.Fatalf("go: %v", err)
"strconv"
"strings"
- "cmd/internal/telemetry"
+ "cmd/internal/telemetry/counter"
"golang.org/x/sync/semaphore"
)
}
func gofmtMain(s *sequencer) {
- telemetry.OpenCounters()
+ counter.Open()
flag.Usage = usage
flag.Parse()
- telemetry.Inc("gofmt/invocations")
- telemetry.CountFlags("gofmt/flag:", *flag.CommandLine)
+ counter.Inc("gofmt/invocations")
+ counter.CountFlags("gofmt/flag:", *flag.CommandLine)
if *cpuprofile != "" {
fdSem <- true
--- /dev/null
+// 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 && !compiler_bootstrap
+
+package counter
+
+import (
+ "flag"
+ "os"
+
+ "golang.org/x/telemetry/counter"
+)
+
+var openCalled bool
+
+func OpenCalled() bool { return openCalled }
+
+// Open opens the counter files for writing if telemetry is supported
+// on the current platform (and does nothing otherwise).
+func Open() {
+ openCalled = true
+ counter.OpenDir(os.Getenv("TEST_TELEMETRY_DIR"))
+}
+
+// Inc increments the counter with the given name.
+func Inc(name string) {
+ counter.Inc(name)
+}
+
+// New returns a counter with the given name.
+func New(name string) *counter.Counter {
+ return counter.New(name)
+}
+
+// NewStack returns a new stack counter with the given name and depth.
+func NewStack(name string, depth int) *counter.StackCounter {
+ return counter.NewStack(name, depth)
+}
+
+// CountFlags creates a counter for every flag that is set
+// and increments the counter. The name of the counter is
+// the concatenation of prefix and the flag name.
+func CountFlags(prefix string, flagSet flag.FlagSet) {
+ counter.CountFlags(prefix, flagSet)
+}
+
+// CountFlagValue creates a counter for the flag value
+// if it is set and increments the counter. The name of the
+// counter is the concatenation of prefix, the flagName, ":",
+// and value.String() for the flag's value.
+func CountFlagValue(prefix string, flagSet flag.FlagSet, flagName string) {
+ // TODO(matloob): Maybe pass in a list of flagNames if we end up counting
+ // values for more than one?
+ // TODO(matloob): Add this to x/telemetry?
+ flagSet.Visit(func(f *flag.Flag) {
+ if f.Name == flagName {
+ counter.New(prefix + f.Name + ":" + f.Value.String()).Inc()
+ }
+ })
+}
--- /dev/null
+// 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 || compiler_bootstrap
+
+package counter
+
+import "flag"
+
+type dummyCounter struct{}
+
+func (dc dummyCounter) Inc() {}
+
+func Open() {}
+func Inc(name string) {}
+func New(name string) dummyCounter { return dummyCounter{} }
+func NewStack(name string, depth int) dummyCounter { return dummyCounter{} }
+func CountFlags(name string, flagSet flag.FlagSet) {}
+func CountFlagValue(prefix string, flagSet flag.FlagSet, flagName string) {}
package telemetry
import (
- "flag"
"os"
+ "cmd/internal/telemetry/counter"
+
"golang.org/x/telemetry"
- "golang.org/x/telemetry/counter"
)
var openCountersCalled, maybeChildCalled bool
-// OpenCounters opens the counter files for writing if telemetry is supported
-// on the current platform (and does nothing otherwise).
-func OpenCounters() {
- openCountersCalled = true
- telemetry.Start(telemetry.Config{
- TelemetryDir: os.Getenv("TEST_TELEMETRY_DIR"),
- })
-}
-
// MaybeParent does a once a day check to see if the weekly reports are
// ready to be processed or uploaded, and if so, starts the telemetry child to
// do so. It should only be called by cmd/go, and only after OpenCounters and MaybeChild
// have already been called.
func MaybeParent() {
- if !openCountersCalled || !maybeChildCalled {
+ if !counter.OpenCalled() || !maybeChildCalled {
panic("MaybeParent must be called after OpenCounters and MaybeChild")
}
telemetry.Start(telemetry.Config{
})
}
-// Inc increments the counter with the given name.
-func Inc(name string) {
- counter.Inc(name)
-}
-
-// NewCounter returns a counter with the given name.
-func NewCounter(name string) *counter.Counter {
- return counter.New(name)
-}
-
-// NewStackCounter returns a new stack counter with the given name and depth.
-func NewStackCounter(name string, depth int) *counter.StackCounter {
- return counter.NewStack(name, depth)
-}
-
-// CountFlags creates a counter for every flag that is set
-// and increments the counter. The name of the counter is
-// the concatenation of prefix and the flag name.
-func CountFlags(prefix string, flagSet flag.FlagSet) {
- counter.CountFlags(prefix, flagSet)
-}
-
-// CountFlagValue creates a counter for the flag value
-// if it is set and increments the counter. The name of the
-// counter is the concatenation of prefix, the flagName, ":",
-// and value.String() for the flag's value.
-func CountFlagValue(prefix string, flagSet flag.FlagSet, flagName string) {
- // TODO(matloob): Maybe pass in a list of flagNames if we end up counting
- // values for more than one?
- // TODO(matloob): Add this to x/telemetry?
- flagSet.Visit(func(f *flag.Flag) {
- if f.Name == flagName {
- counter.New(prefix + f.Name + ":" + f.Value.String()).Inc()
- }
- })
-}
-
// Mode returns the current telemetry mode.
//
// The telemetry mode is a global value that controls both the local collection
package telemetry
-import "flag"
-
-type dummyCounter struct{}
-
-func (dc dummyCounter) Inc() {}
-
-func OpenCounters() {}
-func MaybeParent() {}
-func MaybeChild() {}
-func Inc(name string) {}
-func NewCounter(name string) dummyCounter { return dummyCounter{} }
-func NewStackCounter(name string, depth int) dummyCounter { return dummyCounter{} }
-func CountFlags(name string, flagSet flag.FlagSet) {}
-func CountFlagValue(prefix string, flagSet flag.FlagSet, flagName string) {}
-func Mode() string { return "" }
-func SetMode(mode string) error { return nil }
-func Dir() string { return "" }
+func MaybeParent() {}
+func MaybeChild() {}
+func Mode() string { return "" }
+func SetMode(mode string) error { return nil }
+func Dir() string { return "" }
"cmd/internal/objabi"
"cmd/internal/quoted"
"cmd/internal/sys"
- "cmd/internal/telemetry"
+ "cmd/internal/telemetry/counter"
"cmd/link/internal/benchmark"
"flag"
"internal/buildcfg"
func Main(arch *sys.Arch, theArch Arch) {
log.SetPrefix("link: ")
log.SetFlags(0)
- telemetry.OpenCounters()
- telemetry.Inc("link/invocations")
+ counter.Open()
+ counter.Inc("link/invocations")
thearch = theArch
ctxt := linknew(arch)
objabi.Flagfn1("importcfg", "read import configuration from `file`", ctxt.readImportCfg)
objabi.Flagparse(usage)
- telemetry.CountFlags("link/flag:", *flag.CommandLine)
+ counter.CountFlags("link/flag:", *flag.CommandLine)
if ctxt.Debugvlog > 0 {
// dump symbol info on crash
"sort"
"cmd/internal/objfile"
- "cmd/internal/telemetry"
+ "cmd/internal/telemetry/counter"
)
const helpText = `usage: go tool nm [options] file...
func main() {
log.SetFlags(0)
- telemetry.OpenCounters()
+ counter.Open()
flag.Usage = usage
flag.Parse()
- telemetry.Inc("nm/invocations")
- telemetry.CountFlags("nm/flag:", *flag.CommandLine)
+ counter.Inc("nm/invocations")
+ counter.CountFlags("nm/flag:", *flag.CommandLine)
switch *sortOrder {
case "address", "name", "none", "size":
"strings"
"cmd/internal/objfile"
- "cmd/internal/telemetry"
+ "cmd/internal/telemetry/counter"
)
var printCode = flag.Bool("S", false, "print Go code alongside assembly")
func main() {
log.SetFlags(0)
log.SetPrefix("objdump: ")
- telemetry.OpenCounters()
+ counter.Open()
flag.Usage = usage
flag.Parse()
- telemetry.Inc("objdump/invocations")
- telemetry.CountFlags("objdump/flag:", *flag.CommandLine)
+ counter.Inc("objdump/invocations")
+ counter.CountFlags("objdump/flag:", *flag.CommandLine)
if flag.NArg() != 1 && flag.NArg() != 3 {
usage()
}
import (
"cmd/internal/archive"
- "cmd/internal/telemetry"
+ "cmd/internal/telemetry/counter"
"fmt"
"io"
"io/fs"
func main() {
log.SetFlags(0)
log.SetPrefix("pack: ")
- telemetry.OpenCounters()
+ counter.Open()
// need "pack op archive" at least.
if len(os.Args) < 3 {
log.Print("not enough arguments")
usage()
}
setOp(os.Args[1])
- telemetry.Inc("pack/invocations")
- telemetry.Inc("pack/op:" + string(op))
+ counter.Inc("pack/invocations")
+ counter.Inc("pack/op:" + string(op))
var ar *Archive
switch op {
case 'p':
"time"
"cmd/internal/objfile"
- "cmd/internal/telemetry"
+ "cmd/internal/telemetry/counter"
"github.com/google/pprof/driver"
"github.com/google/pprof/profile"
)
func main() {
- telemetry.OpenCounters()
- telemetry.Inc("pprof/invocations")
+ counter.Open()
+ counter.Inc("pprof/invocations")
options := &driver.Options{
Fetch: new(fetcher),
Obj: new(objTool),
UI: newUI(),
}
err := driver.PProf(options)
- telemetry.CountFlags("pprof/flag:", *flag.CommandLine) // pprof will use the flag package as its default
+ counter.CountFlags("pprof/flag:", *flag.CommandLine) // pprof will use the flag package as its default
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(2)
"bufio"
"cmd/internal/objabi"
"cmd/internal/pgo"
- "cmd/internal/telemetry"
+ "cmd/internal/telemetry/counter"
"flag"
"fmt"
"log"
log.SetFlags(0)
log.SetPrefix("preprofile: ")
- telemetry.OpenCounters()
+ counter.Open()
flag.Usage = usage
flag.Parse()
- telemetry.Inc("preprofile/invocations")
- telemetry.CountFlags("preprofile/flag:", *flag.CommandLine)
+ counter.Inc("preprofile/invocations")
+ counter.CountFlags("preprofile/flag:", *flag.CommandLine)
if *input == "" {
log.Print("Input pprof path required (-i)")
usage()
"os/exec"
"os/signal"
- "cmd/internal/telemetry"
+ "cmd/internal/telemetry/counter"
"cmd/internal/test2json"
)
}
func main() {
- telemetry.OpenCounters()
+ counter.Open()
flag.Usage = usage
flag.Parse()
- telemetry.Inc("test2json/invocations")
- telemetry.CountFlags("test2json/flag:", *flag.CommandLine)
+ counter.Inc("test2json/invocations")
+ counter.CountFlags("test2json/flag:", *flag.CommandLine)
var mode test2json.Mode
if *flagT {
import (
"cmd/internal/browser"
- "cmd/internal/telemetry"
+ "cmd/internal/telemetry/counter"
"flag"
"fmt"
"internal/trace"
)
func main() {
- telemetry.OpenCounters()
+ counter.Open()
flag.Usage = func() {
fmt.Fprint(os.Stderr, usageMessage)
os.Exit(2)
}
flag.Parse()
- telemetry.Inc("trace/invocations")
- telemetry.CountFlags("trace/flag:", *flag.CommandLine)
+ counter.Inc("trace/invocations")
+ counter.CountFlags("trace/flag:", *flag.CommandLine)
// Go 1.7 traces embed symbol info and does not require the binary.
// But we optionally accept binary as first arg for Go 1.5 traces.
import (
"cmd/internal/objabi"
- "cmd/internal/telemetry"
+ "cmd/internal/telemetry/counter"
"flag"
"golang.org/x/tools/go/analysis/unitchecker"
)
func main() {
- telemetry.OpenCounters()
+ counter.Open()
objabi.AddVersionFlag()
- telemetry.Inc("vet/invocations")
+ counter.Inc("vet/invocations")
unitchecker.Main(
appends.Analyzer,
asmdecl.Analyzer,
// It's possible that unitchecker will exit early. In
// those cases the flags won't be counted.
- telemetry.CountFlags("vet/flag:", *flag.CommandLine)
+ counter.CountFlags("vet/flag:", *flag.CommandLine)
}