MCPcopy
hub / github.com/prometheus/prometheus / newSampleRing

Function newSampleRing

storage/buffer.go:307–326  ·  view source on GitHub ↗

newSampleRing creates a new sampleRing. If you do not know the preferred value type yet, use a size of 0 (in which case the provided typ doesn't matter). On the first add, a buffer of size 16 will be allocated with the preferred type being the type of the first added sample.

(delta int64, size int, typ chunkenc.ValueType)

Source from the content-addressed store, hash-verified

305// matter). On the first add, a buffer of size 16 will be allocated with the
306// preferred type being the type of the first added sample.
307func newSampleRing(delta int64, size int, typ chunkenc.ValueType) *sampleRing {
308 r := &sampleRing{delta: delta}
309 r.reset()
310 if size <= 0 {
311 // Will initialize on first add.
312 return r
313 }
314 switch typ {
315 case chunkenc.ValFloat:
316 r.fBuf = make([]fSample, size)
317 case chunkenc.ValHistogram:
318 r.hBuf = make([]hSample, size)
319 case chunkenc.ValFloatHistogram:
320 r.fhBuf = make([]fhSample, size)
321 default:
322 // Do not initialize anything because the 1st sample will be
323 // added to one of the other bufs anyway.
324 }
325 return r
326}
327
328func (r *sampleRing) reset() {
329 r.l = 0

Callers 5

TestSampleRingFunction · 0.85
TestSampleRingFloatSTFunction · 0.85
TestSampleRingMixedFunction · 0.85
NewBufferIteratorFunction · 0.85

Calls 1

resetMethod · 0.95

Tested by 4

TestSampleRingFunction · 0.68
TestSampleRingFloatSTFunction · 0.68
TestSampleRingMixedFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…