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