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 <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Sam Thanawalla <samthanawalla@google.com>
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
)
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=
// 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
// type aliasing or restructuring the internal/counter package.
import (
"flag"
+ "path"
+ "runtime/debug"
"golang.org/x/telemetry/internal/counter"
)
// 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)
+}
+++ /dev/null
-// 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 }
// 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
opened bool
)
+// SupportedPlatform reports if this platform supports Open()
+const SupportedPlatform = !telemetry.DisabledOnPlatform
+
func isOpen() bool {
openedMu.Lock()
defer openedMu.Unlock()
+++ /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 !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 }
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