diff --git a/perfmap.go b/perfmap.go index c0b68d7..ba061d4 100644 --- a/perfmap.go +++ b/perfmap.go @@ -247,7 +247,9 @@ func (m *PerfMap) BufferSize() int { // Telemetry returns the usage and lost telemetry func (m *PerfMap) Telemetry() (usage []uint64, lost []uint64) { - if m.usageTelemetry == nil || m.lostTelemetry == nil { + m.stateLock.Lock() + defer m.stateLock.Unlock() + if m.state < initialized || m.usageTelemetry == nil || m.lostTelemetry == nil { return nil, nil } usage = make([]uint64, len(m.usageTelemetry)) diff --git a/ringbuffer.go b/ringbuffer.go index 72da217..4b4fab7 100644 --- a/ringbuffer.go +++ b/ringbuffer.go @@ -183,7 +183,9 @@ func (rb *RingBuffer) BufferSize() int { // Telemetry returns the usage telemetry func (rb *RingBuffer) Telemetry() (usage uint64, ok bool) { - if rb.usageTelemetry == nil { + rb.stateLock.Lock() + defer rb.stateLock.Unlock() + if rb.state < initialized || rb.usageTelemetry == nil { return 0, false } // reset to zero, so we return the max value between each collection