MCPcopy
hub / github.com/grafana/k6 / GetBufferedSamples

Method GetBufferedSamples

output/helpers.go:34–50  ·  view source on GitHub ↗

GetBufferedSamples returns the currently buffered metric samples and makes a new internal buffer with some hopefully realistic size. If the internal buffer is empty, it will return nil.

()

Source from the content-addressed store, hash-verified

32// new internal buffer with some hopefully realistic size. If the internal
33// buffer is empty, it will return nil.
34func (sc *SampleBuffer) GetBufferedSamples() []metrics.SampleContainer {
35 sc.Lock()
36 defer sc.Unlock()
37
38 buffered, bufferedLen := sc.buffer, len(sc.buffer)
39 if bufferedLen == 0 {
40 return nil
41 }
42 if bufferedLen > sc.maxLen {
43 sc.maxLen = bufferedLen
44 }
45 // Make the new buffer halfway between the previously allocated size and the
46 // maximum buffer size we've seen so far, to hopefully reduce copying a bit.
47 sc.buffer = make([]metrics.SampleContainer, 0, (bufferedLen+sc.maxLen)/2)
48
49 return buffered
50}
51
52// PeriodicFlusher is a small helper for asynchronously flushing buffered metric
53// samples on regular intervals. The biggest benefit is having a Stop() method

Callers 14

TestSampleBufferBasicsFunction · 0.95
collectSamplesMethod · 0.80
flushMetricsMethod · 0.80
flushMetricsMethod · 0.80
flushMethod · 0.80
flushMetricsMethod · 0.80
flushMetricsMethod · 0.80
flushMetricsMethod · 0.80
flushMetricsMethod · 0.80
AssertSamplesMethod · 0.80

Calls 2

UnlockMethod · 0.80
LockMethod · 0.45

Tested by 3

TestSampleBufferBasicsFunction · 0.76