1
2
3
4
5
6
7 package countertest
8
9 import (
10 "sync"
11 "testing"
12
13 "golang.org/x/telemetry/counter"
14 ic "golang.org/x/telemetry/internal/counter"
15 "golang.org/x/telemetry/internal/telemetry"
16 )
17
18 var (
19 openedMu sync.Mutex
20 opened bool
21 )
22
23
24 const SupportedPlatform = !telemetry.DisabledOnPlatform
25
26 func isOpen() bool {
27 openedMu.Lock()
28 defer openedMu.Unlock()
29 return opened
30 }
31
32
33
34
35
36 func Open(telemetryDir string) {
37 openedMu.Lock()
38 defer openedMu.Unlock()
39 if opened {
40 panic("Open was called more than once")
41 }
42 telemetry.Default = telemetry.NewDir(telemetryDir)
43
44
45
46
47 counter.Open()
48 opened = true
49 }
50
51
52 func ReadCounter(c *counter.Counter) (count uint64, _ error) {
53 return ic.Read(c)
54 }
55
56
57 func ReadStackCounter(c *counter.StackCounter) (stackCounts map[string]uint64, _ error) {
58 return ic.ReadStack(c)
59 }
60
61
62 func ReadFile(name string) (counters, stackCounters map[string]uint64, _ error) {
63 return ic.ReadFile(name)
64 }
65
66 func init() {
67
68 if !testing.Testing() {
69 panic("use of this package is disallowed in non-testing code")
70 }
71 }
72
View as plain text