From 630a8e29c3518500746bce30f578e03120c28c36 Mon Sep 17 00:00:00 2001 From: Bryce Kahle Date: Tue, 7 May 2024 08:30:35 -0700 Subject: [PATCH] do not return telemetry unless initialized (#180) --- perfmap.go | 4 +++- ringbuffer.go | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) 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