trcringbuf

package
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 17, 2023 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package trcringbuf provides a fixed-size ring buffer for traces.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RingBuffer

type RingBuffer[T any] struct {
	// contains filtered or unexported fields
}

RingBuffer is a fixed-size collection of recent items.

func NewRingBuffer

func NewRingBuffer[T any](cap int) *RingBuffer[T]

NewRingBuffer returns an empty ring buffer of items, pre-allocated with the given capacity.

func (*RingBuffer[T]) Add

func (rb *RingBuffer[T]) Add(val T) (dropped T, ok bool)

Add the value to the ring buffer. If the ring buffer was full and an item was overwritten by this add, return that item and true, otherwise return a zero value item and false.

func (*RingBuffer[T]) Resize

func (rb *RingBuffer[T]) Resize(cap int) (dropped []T)

Resize changes the capacity of the ring buffer to the given value. If the new capacity is smaller than the existing capacity, resize will drop the older items as necessary, and return those dropped items.

func (*RingBuffer[T]) Stats

func (rb *RingBuffer[T]) Stats() (newest, oldest T, count int)

Stats returns the newest and oldest values in the ring buffer, as well as the total number of values stored in the ring buffer.

func (*RingBuffer[T]) Walk

func (rb *RingBuffer[T]) Walk(fn func(T) error) error

Walk calls the given function for each value in the ring buffer, starting with the most recent value, and ending with the oldest value. Walk takes an exclusive lock on the ring buffer, which blocks other calls like Add.

type RingBuffers

type RingBuffers[T any] struct {
	// contains filtered or unexported fields
}

RingBuffers collects individual ring buffers by string key.

func NewRingBuffers

func NewRingBuffers[T any](cap int) *RingBuffers[T]

NewRingBuffers returns an empty set of ring buffers, each of which will have a maximum capacity of the given cap.

func (*RingBuffers[T]) GetAll

func (rbs *RingBuffers[T]) GetAll() map[string]*RingBuffer[T]

GetAll returns all of the ring buffers in the set, grouped by category.

func (*RingBuffers[T]) GetOrCreate

func (rbs *RingBuffers[T]) GetOrCreate(category string) *RingBuffer[T]

GetOrCreate returns a ring buffer corresponding to the given category string. Once a ring buffer is created in this way, it will always exist.

func (*RingBuffers[T]) Resize

func (rbs *RingBuffers[T]) Resize(cap int) (dropped []T)

Resize all of the ring buffers in the set to the new capacity.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL