| 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 |
counter.Open() |
| 44 |
opened = true |
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
func ReadCounter(c *counter.Counter) (count uint64, _ error) { |
| 49 |
return ic.Read(c) |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
func ReadStackCounter(c *counter.StackCounter) (stackCounts map[string]uint64, _ error) { |
| 54 |
return ic.ReadStack(c) |
| 55 |
} |
| 56 |
|
| 57 |
|
| 58 |
func ReadFile(name string) (counters, stackCounters map[string]uint64, _ error) { |
| 59 |
return ic.ReadFile(name) |
| 60 |
} |