From 411d7a5c9e4e29691e85baa2decf8782a186071b Mon Sep 17 00:00:00 2001 From: Michael Matloob Date: Thu, 14 Mar 2024 17:14:31 -0400 Subject: [PATCH] cmd: vendor in golang.org/x/telemetry@abedc37 This pulls in the changes to remove 1.18 support in counter and countertest, to add counter.CountCommandLineFlags, and to add countertest.SupportedPlatform Commands run: go get golang.org/x/telemetry@abedc37 go mod tidy go mod vendor Change-Id: I5c17c5b3ca38df14883ba43316d59437a737b28b Reviewed-on: https://go-review.googlesource.com/c/go/+/571801 LUCI-TryBot-Result: Go LUCI Reviewed-by: Sam Thanawalla --- src/cmd/go.mod | 2 +- src/cmd/go.sum | 4 +-- .../golang.org/x/telemetry/counter/counter.go | 27 +++++++++++++++-- .../x/telemetry/counter/counter_118.go | 30 ------------------- .../counter/countertest/countertest.go | 5 ++-- .../counter/countertest/countertest_go118.go | 21 ------------- src/cmd/vendor/modules.txt | 2 +- 7 files changed, 31 insertions(+), 60 deletions(-) delete mode 100644 src/cmd/vendor/golang.org/x/telemetry/counter/counter_118.go delete mode 100644 src/cmd/vendor/golang.org/x/telemetry/counter/countertest/countertest_go118.go diff --git a/src/cmd/go.mod b/src/cmd/go.mod index 2ab365a9da..00ad03ccb1 100644 --- a/src/cmd/go.mod +++ b/src/cmd/go.mod @@ -9,7 +9,7 @@ require ( golang.org/x/mod v0.16.0 golang.org/x/sync v0.6.0 golang.org/x/sys v0.18.0 - golang.org/x/telemetry v0.0.0-20240306210657-d5a85b27db3e + golang.org/x/telemetry v0.0.0-20240314204428-abedc375dc97 golang.org/x/term v0.18.0 golang.org/x/tools v0.18.0 ) diff --git a/src/cmd/go.sum b/src/cmd/go.sum index 4917878db2..3b5545f7de 100644 --- a/src/cmd/go.sum +++ b/src/cmd/go.sum @@ -32,8 +32,8 @@ golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/telemetry v0.0.0-20240306210657-d5a85b27db3e h1:PLWTnhLSeWLoHHuUDdzlJeYqRntM+xTyojGjTrFg01c= -golang.org/x/telemetry v0.0.0-20240306210657-d5a85b27db3e/go.mod h1:wQS78u8AjB4H3mN7DPniFYwsXnV9lPziq+He/eA7JIw= +golang.org/x/telemetry v0.0.0-20240314204428-abedc375dc97 h1:8xsFCUjK82nH2OGdUR3elXWEngFLc2SM/IplvhGHFjk= +golang.org/x/telemetry v0.0.0-20240314204428-abedc375dc97/go.mod h1:wQS78u8AjB4H3mN7DPniFYwsXnV9lPziq+He/eA7JIw= golang.org/x/term v0.18.0 h1:FcHjZXDMxI8mM3nwhX9HlKop4C0YQvCVCdwYl2wOtE8= golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58= golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= diff --git a/src/cmd/vendor/golang.org/x/telemetry/counter/counter.go b/src/cmd/vendor/golang.org/x/telemetry/counter/counter.go index e6af9ea6cf..ba1c68889e 100644 --- a/src/cmd/vendor/golang.org/x/telemetry/counter/counter.go +++ b/src/cmd/vendor/golang.org/x/telemetry/counter/counter.go @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//go:build go1.19 - package counter // The implementation of this package and tests are located in @@ -13,6 +11,8 @@ package counter // type aliasing or restructuring the internal/counter package. import ( "flag" + "path" + "runtime/debug" "golang.org/x/telemetry/internal/counter" ) @@ -92,9 +92,30 @@ func Open() { // and increments the counter. The name of the counter is // the concatenation of prefix and the flag name. // -// For instance, CountFlags("gopls:flag-", flag.CommandLine) +// For instance, CountFlags("gopls/flag:", *flag.CommandLine) func CountFlags(prefix string, fs flag.FlagSet) { fs.Visit(func(f *flag.Flag) { New(prefix + f.Name).Inc() }) } + +// CountCommandLineFlags creates a counter for every flag +// that is set in the default flag.CommandLine FlagSet using +// the counter name binaryName+"/flag:"+flagName where +// binaryName is the base name of the Path embedded in the +// binary's build info. If the binary does not have embedded build +// info, the "flag:"+flagName counter will be incremented. +// +// CountCommandLineFlags must be called after flags are parsed +// with flag.Parse. +// +// For instance, if the -S flag is passed to cmd/compile and +// CountCommandLineFlags is called after flags are parsed, +// the "compile/flag:S" counter will be incremented. +func CountCommandLineFlags() { + prefix := "flag:" + if buildInfo, ok := debug.ReadBuildInfo(); ok && buildInfo.Path != "" { + prefix = path.Base(buildInfo.Path) + "/" + prefix + } + CountFlags(prefix, *flag.CommandLine) +} diff --git a/src/cmd/vendor/golang.org/x/telemetry/counter/counter_118.go b/src/cmd/vendor/golang.org/x/telemetry/counter/counter_118.go deleted file mode 100644 index 432e0d7ef8..0000000000 --- a/src/cmd/vendor/golang.org/x/telemetry/counter/counter_118.go +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright 2023 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 !go1.19 - -package counter - -import ( - "flag" -) - -func Add(string, int64) {} -func Inc(string) {} -func Open() {} -func CountFlags(prefix string, fs flag.FlagSet) {} - -type Counter struct{ name string } - -func New(name string) *Counter { return &Counter{name} } -func (c *Counter) Add(n int64) {} -func (c *Counter) Inc() {} -func (c *Counter) Name() string { return c.name } - -type StackCounter struct{ name string } - -func NewStack(name string, _ int) *StackCounter { return &StackCounter{name} } -func (c *StackCounter) Counters() []*Counter { return nil } -func (c *StackCounter) Inc() {} -func (c *StackCounter) Names() []string { return nil } diff --git a/src/cmd/vendor/golang.org/x/telemetry/counter/countertest/countertest.go b/src/cmd/vendor/golang.org/x/telemetry/counter/countertest/countertest.go index b9bec1f825..c2f41f6d77 100644 --- a/src/cmd/vendor/golang.org/x/telemetry/counter/countertest/countertest.go +++ b/src/cmd/vendor/golang.org/x/telemetry/counter/countertest/countertest.go @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//go:build go1.19 - // countertest provides testing utilities for counters. // This package cannot be used except for testing. package countertest @@ -22,6 +20,9 @@ var ( opened bool ) +// SupportedPlatform reports if this platform supports Open() +const SupportedPlatform = !telemetry.DisabledOnPlatform + func isOpen() bool { openedMu.Lock() defer openedMu.Unlock() diff --git a/src/cmd/vendor/golang.org/x/telemetry/counter/countertest/countertest_go118.go b/src/cmd/vendor/golang.org/x/telemetry/counter/countertest/countertest_go118.go deleted file mode 100644 index d9eaecc729..0000000000 --- a/src/cmd/vendor/golang.org/x/telemetry/counter/countertest/countertest_go118.go +++ /dev/null @@ -1,21 +0,0 @@ -// 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 !go1.19 - -package countertest - -import "golang.org/x/telemetry/counter" - -func Open(telemetryDir string) {} - -func ReadCounter(c *counter.Counter) (count uint64, _ error) { - return 0, nil -} - -func ReadStackCounter(c *counter.StackCounter) (stackCounts map[string]uint64, _ error) { - return nil, nil -} - -func ReadFile(name string) (map[string]uint64, map[string]uint64, error) { return nil, nil, nil } diff --git a/src/cmd/vendor/modules.txt b/src/cmd/vendor/modules.txt index a62ce7a360..549a3fdc7f 100644 --- a/src/cmd/vendor/modules.txt +++ b/src/cmd/vendor/modules.txt @@ -45,7 +45,7 @@ golang.org/x/sync/semaphore golang.org/x/sys/plan9 golang.org/x/sys/unix golang.org/x/sys/windows -# golang.org/x/telemetry v0.0.0-20240306210657-d5a85b27db3e +# golang.org/x/telemetry v0.0.0-20240314204428-abedc375dc97 ## explicit; go 1.20 golang.org/x/telemetry golang.org/x/telemetry/counter -- 2.50.0