aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/internal
diff options
context:
space:
mode:
authorMichael Matloob <matloob@golang.org>2024-06-13 12:38:20 -0400
committerMichael Matloob <matloob@golang.org>2024-06-13 19:19:47 +0000
commitdbe03e4831206d7311e4423c3a988fc48beda2bd (patch)
treea417b2026482689a40634b18a13ed786cc6147d3 /src/cmd/internal
parent956f8a67dd7319bad60c015d982f0b2e95b9f382 (diff)
downloadgo-dbe03e4831206d7311e4423c3a988fc48beda2bd.tar.xz
cmd/go: call telemetry.MaybeChild at start of go command
Call the new telemetry.MaybeChild function at the start of the go command so that the child process logic can be run immediately without running toolchain selection if this is the child process. The Start function in the telemetry shim package has been renamed to OpenCounters to make it clear that that's its only function. The StartWithUpload function in the telemetry shim package has been renamed to MaybeParent because that's its actual effective behavior in cmd/go, the only place it's called: it won't run as the child because MaybeChild has already been called and would have run as the child if the program was the telemetry child, and it won't open counters because telemetry.Start has been called. Checks are added that those functions are always called before so that the function name and comment are accurate. It might make sense to add a true telemetry.MaybeParent function that doesn't try to start the child or open counters to make things a little simpler. Change-Id: Ie81e2418af85cef18ec41f75db66365f6597b8b1 Reviewed-on: https://go-review.googlesource.com/c/go/+/592535 Reviewed-by: Robert Findley <rfindley@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'src/cmd/internal')
-rw-r--r--src/cmd/internal/telemetry/telemetry.go32
-rw-r--r--src/cmd/internal/telemetry/telemetry_bootstrap.go5
2 files changed, 28 insertions, 9 deletions
diff --git a/src/cmd/internal/telemetry/telemetry.go b/src/cmd/internal/telemetry/telemetry.go
index f11d80d19f..b0c864a1a9 100644
--- a/src/cmd/internal/telemetry/telemetry.go
+++ b/src/cmd/internal/telemetry/telemetry.go
@@ -19,25 +19,43 @@ import (
"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)
diff --git a/src/cmd/internal/telemetry/telemetry_bootstrap.go b/src/cmd/internal/telemetry/telemetry_bootstrap.go
index 1740bdb701..05c0ee1c56 100644
--- a/src/cmd/internal/telemetry/telemetry_bootstrap.go
+++ b/src/cmd/internal/telemetry/telemetry_bootstrap.go
@@ -12,8 +12,9 @@ type dummyCounter struct{}
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{} }