Skip to content

Commit

Permalink
do not return telemetry unless initialized (#180)
Browse files Browse the repository at this point in the history
  • Loading branch information
brycekahle authored May 7, 2024
1 parent 096c9ce commit 630a8e2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion perfmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
4 changes: 3 additions & 1 deletion ringbuffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 630a8e2

Please sign in to comment.