MCPcopy
hub / github.com/grafana/tempo / NewCounter

Function NewCounter

pkg/usagestats/stats.go:328–343  ·  view source on GitHub ↗

NewCounter returns a new Counter stats object. If a Counter stats object with the same name already exists it is returned.

(name string)

Source from the content-addressed store, hash-verified

326// NewCounter returns a new Counter stats object.
327// If a Counter stats object with the same name already exists it is returned.
328func NewCounter(name string) *Counter {
329 c := &Counter{
330 total: atomic.NewInt64(0),
331 rate: atomic.NewFloat64(0),
332 resetTime: time.Now(),
333 }
334 existing := expvar.Get(statsPrefix + name)
335 if existing != nil {
336 if c, ok := existing.(*Counter); ok {
337 return c
338 }
339 panic(fmt.Sprintf("%v is set to a non-Counter value", name))
340 }
341 expvar.Publish(statsPrefix+name, c)
342 return c
343}
344
345func (c *Counter) updateRate() {
346 total := c.total.Load()

Callers 5

distributor.goFile · 0.92
Test_BuildReportFunction · 0.85
Test_BuildStatsFunction · 0.85
TestCounterFunction · 0.85
TestPanicsFunction · 0.85

Calls 2

NowMethod · 0.65
GetMethod · 0.65

Tested by 4

Test_BuildReportFunction · 0.68
Test_BuildStatsFunction · 0.68
TestCounterFunction · 0.68
TestPanicsFunction · 0.68