ring

package
v0.0.0-...-6aee3ff Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2020 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Ring

type Ring struct {
	// contains filtered or unexported fields
}

Ring is a ring buffer that stores *pb.Trace

func NewRing

func NewRing(n int) *Ring

NewRing creates a ring buffer. For efficiency, the internal buffer length will be a bitmask of ones + 1. The most significant bit position of this bitmask will be same position of the most significant bit position of 'n'. E.g.:

NewRing(254) -> internal buffer length: 256
NewRing(255) -> internal buffer length: 256
NewRing(256) -> internal buffer length: 512

func (*Ring) Cap

func (r *Ring) Cap() uint64

Cap returns the total capacity of the ring buffer, similar to builtin `cap()`.

func (*Ring) LastWrite

func (r *Ring) LastWrite() uint64

LastWrite returns the last element written. Note: If Write(*pb.Trace) is being executed concurrently with Read(uint64) please use LastWriteParallel instead.

func (*Ring) LastWriteParallel

func (r *Ring) LastWriteParallel() uint64

LastWriteParallel returns the last element written.

func (*Ring) Len

func (r *Ring) Len() uint64

Len returns the number of elements in the ring buffer, similar to builtin `len()`.

func (*Ring) ReadFrom

func (r *Ring) ReadFrom(ctx context.Context, read uint64) <-chan *pb.Trace

ReadFrom continues to read from the given position until the context is canceled.

func (*Ring) Write

func (r *Ring) Write(entry *pb.Trace)

Write writes the given event into the ring buffer in the next available writing block. The entry must not be nil, otherwise readFrom will block when reading back this event.

type RingReader

type RingReader struct {
	// contains filtered or unexported fields
}

RingReader is a reader for a Ring container.

func NewRingReader

func NewRingReader(ring *Ring, start uint64) *RingReader

NewRingReader creates a new RingReader that starts reading the ring at the position given by start.

func (*RingReader) Next

func (r *RingReader) Next() *pb.Trace

Next reads the event at the current position and increment the read position. When no more event can be read, Next returns nil.

func (*RingReader) NextFollow

func (r *RingReader) NextFollow(ctx context.Context) *pb.Trace

NextFollow reads the event at the current position and increment the read position by one. If there are no more event to read, NextFollow blocks until the next event is added to the ring or the context is canceled.

func (*RingReader) Previous

func (r *RingReader) Previous() *pb.Trace

Previous reads the event at the current position and decrement the read position. When no more event can be read, Previous returns nil.

Jump to

Keyboard shortcuts

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