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

Function NewStatistics

pkg/usagestats/stats.go:234–252  ·  view source on GitHub ↗

NewStatistics returns a new Statistics object. Statistics object is thread-safe and compute statistics on the fly based on sample recorded. Available statistics are: - min - max - avg - count - stddev - stdvar If a Statistics object with the same name already exists it is returned.

(name string)

Source from the content-addressed store, hash-verified

232// - stdvar
233// If a Statistics object with the same name already exists it is returned.
234func NewStatistics(name string) *Statistics {
235 s := &Statistics{
236 min: atomic.NewFloat64(math.Inf(0)),
237 max: atomic.NewFloat64(math.Inf(-1)),
238 count: atomic.NewInt64(0),
239 avg: atomic.NewFloat64(0),
240 mean: atomic.NewFloat64(0),
241 value: atomic.NewFloat64(0),
242 }
243 existing := expvar.Get(statsPrefix + name)
244 if existing != nil {
245 if s, ok := existing.(*Statistics); ok {
246 return s
247 }
248 panic(fmt.Sprintf("%v is set to a non-Statistics value", name))
249 }
250 expvar.Publish(statsPrefix+name, s)
251 return s
252}
253
254func (s *Statistics) String() string {
255 b, _ := json.Marshal(s.Value())

Callers 4

Test_BuildReportFunction · 0.85
Test_BuildStatsFunction · 0.85
TestStatisticFunction · 0.85
TestPanicsFunction · 0.85

Calls 1

GetMethod · 0.65

Tested by 4

Test_BuildReportFunction · 0.68
Test_BuildStatsFunction · 0.68
TestStatisticFunction · 0.68
TestPanicsFunction · 0.68