counter.go 632 B

1234567891011121314151617181920212223242526272829303132333435
  1. package mock
  2. import (
  3. "github.com/ydb-platform/ydb/library/go/core/metrics"
  4. "go.uber.org/atomic"
  5. )
  6. var _ metrics.Counter = (*Counter)(nil)
  7. // Counter tracks monotonically increasing value.
  8. type Counter struct {
  9. Name string
  10. Tags map[string]string
  11. Value *atomic.Int64
  12. }
  13. // Inc increments counter by 1.
  14. func (c *Counter) Inc() {
  15. c.Add(1)
  16. }
  17. // Add adds delta to the counter. Delta must be >=0.
  18. func (c *Counter) Add(delta int64) {
  19. c.Value.Add(delta)
  20. }
  21. var _ metrics.FuncCounter = (*FuncCounter)(nil)
  22. type FuncCounter struct {
  23. function func() int64
  24. }
  25. func (c FuncCounter) Function() func() int64 {
  26. return c.function
  27. }