func main() {
log.SetFlags(0)
log.SetPrefix("addr2line: ")
- telemetry.Start()
+ telemetry.OpenCounters()
// pprof expects this behavior when checking for addr2line
if len(os.Args) > 1 && os.Args[1] == "--help" {
func main() {
log.SetFlags(0)
log.SetPrefix("asm: ")
- telemetry.Start()
+ telemetry.OpenCounters()
buildcfg.Check()
GOARCH := buildcfg.GOARCH
func main() {
log.SetPrefix("buildid: ")
log.SetFlags(0)
- telemetry.Start()
+ telemetry.OpenCounters()
flag.Usage = usage
flag.Parse()
telemetry.Inc("buildid/invocations")
var gccBaseCmd []string
func main() {
- telemetry.Start()
+ telemetry.OpenCounters()
objabi.AddVersionFlag() // -V
objabi.Flagparse(usage)
telemetry.Inc("cgo/invocations")
// code, and finally writes the compiled package definition to disk.
func Main(archInit func(*ssagen.ArchInfo)) {
base.Timer.Start("fe", "init")
- telemetry.Start()
+ telemetry.OpenCounters()
telemetry.Inc("compile/invocations")
defer handlePanic()
)
func main() {
- telemetry.Start()
+ telemetry.OpenCounters()
// First argument should be mode/subcommand.
if len(os.Args) < 2 {
)
func main() {
- telemetry.Start()
+ telemetry.OpenCounters()
objabi.AddVersionFlag()
flag.Usage = usage
func main() {
log.SetPrefix("distpack: ")
log.SetFlags(0)
- telemetry.Start()
+ telemetry.OpenCounters()
flag.Usage = usage
flag.Parse()
telemetry.Inc("distpack/invocations")
func main() {
log.SetFlags(0)
log.SetPrefix("doc: ")
- telemetry.Start()
+ telemetry.OpenCounters()
dirsInit()
err := do(os.Stdout, flag.CommandLine, os.Args[1:])
if err != nil {
}
func main() {
- telemetry.Start()
+ telemetry.OpenCounters()
flag.Usage = usage
flag.Parse()
telemetry.Inc("fix/invocations")
func main() {
log.SetFlags(0)
- telemetry.Start() // 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.
+ telemetry.OpenCounters() // Open the telemetry counter file so counters can be written to it.
handleChdirFlag()
toolchain.Select()
- telemetry.StartWithUpload() // Run the upload process. Opening the counter file is idempotent.
+ telemetry.MaybeParent() // Run the upload process. Opening the counter file is idempotent.
flag.Usage = base.Usage
flag.Parse()
telemetry.Inc("go/invocations")
}
func gofmtMain(s *sequencer) {
- telemetry.Start()
+ telemetry.OpenCounters()
flag.Usage = usage
flag.Parse()
telemetry.Inc("gofmt/invocations")
"golang.org/x/telemetry/counter"
)
-// Start opens the counter files for writing if telemetry is supported
+var openCountersCalled, maybeChildCalled bool
+
+// OpenCounters opens the counter files for writing if telemetry is supported
// on the current platform (and does nothing otherwise).
-func Start() {
+func OpenCounters() {
+ openCountersCalled = true
telemetry.Start(telemetry.Config{
TelemetryDir: os.Getenv("TEST_TELEMETRY_DIR"),
})
}
-// StartWithUpload opens the counter files for writing if telemetry
-// is supported on the current platform and also enables a once a day
-// check to see if the weekly reports are ready to be uploaded.
-// It should only be called by cmd/go
-func StartWithUpload() {
+// 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 {
+ panic("MaybeParent must be called after OpenCounters and MaybeChild")
+ }
telemetry.Start(telemetry.Config{
Upload: true,
TelemetryDir: os.Getenv("TEST_TELEMETRY_DIR"),
})
}
+// MaybeChild executes the telemetry child logic if the calling program is
+// the telemetry child process, and does nothing otherwise. It is meant to be
+// called as the first thing in a program that uses telemetry.OpenCounters but cannot
+// call telemetry.OpenCounters immediately when it starts.
+func MaybeChild() {
+ maybeChildCalled = true
+ telemetry.MaybeChild(telemetry.Config{
+ Upload: true,
+ TelemetryDir: os.Getenv("TEST_TELEMETRY_DIR"),
+ })
+}
+
// Inc increments the counter with the given name.
func Inc(name string) {
counter.Inc(name)
func (dc dummyCounter) Inc() {}
-func Start() {}
-func StartWithUpload() {}
+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 Main(arch *sys.Arch, theArch Arch) {
log.SetPrefix("link: ")
log.SetFlags(0)
- telemetry.Start()
+ telemetry.OpenCounters()
telemetry.Inc("link/invocations")
thearch = theArch
func main() {
log.SetFlags(0)
- telemetry.Start()
+ telemetry.OpenCounters()
flag.Usage = usage
flag.Parse()
telemetry.Inc("nm/invocations")
func main() {
log.SetFlags(0)
log.SetPrefix("objdump: ")
- telemetry.Start()
+ telemetry.OpenCounters()
flag.Usage = usage
flag.Parse()
func main() {
log.SetFlags(0)
log.SetPrefix("pack: ")
- telemetry.Start()
+ telemetry.OpenCounters()
// need "pack op archive" at least.
if len(os.Args) < 3 {
log.Print("not enough arguments")
)
func main() {
- telemetry.Start()
+ telemetry.OpenCounters()
telemetry.Inc("pprof/invocations")
options := &driver.Options{
Fetch: new(fetcher),
log.SetFlags(0)
log.SetPrefix("preprofile: ")
- telemetry.Start()
+ telemetry.OpenCounters()
flag.Usage = usage
flag.Parse()
}
func main() {
- telemetry.Start()
+ telemetry.OpenCounters()
flag.Usage = usage
flag.Parse()
)
func main() {
- telemetry.Start()
+ telemetry.OpenCounters()
flag.Usage = func() {
fmt.Fprint(os.Stderr, usageMessage)
os.Exit(2)
)
func main() {
- telemetry.Start()
+ telemetry.OpenCounters()
objabi.AddVersionFlag()
telemetry.Inc("vet/invocations")