Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Box ¶
type Box struct {
// contains filtered or unexported fields
}
Box holds multiple circular buffers for recording events, one per event type. It also provides a mechanism to swap out active buffers so that a DumpAndReset operation does not block new events.
func NewBox ¶
NewBox creates a new Box based on the provided configuration. It initializes buffers for each supported event type.
func (*Box) DumpAndReset ¶
DumpAndReset swaps out active buffers and logs all events from the old buffers. It sorts events by timestamp and uses zap.Logger to output the details.
func (*Box) Enqueue ¶
Enqueue captures the call stack and enqueues an event for the given event type. The skipCallers parameter allows the caller to skip a number of stack frames.
func (*Box) Reset ¶
func (b *Box) Reset() *[EventTypeCount]*CircularBuffer
Reset replaces the active buffers with new ones and returns the old ones. This ensures DumpAndReset reads from a stable snapshot while new events are recorded.
type CircularBuffer ¶
type CircularBuffer struct {
// contains filtered or unexported fields
}
CircularBuffer implements a lock-free ring buffer for storing events. It uses a single atomic "write" counter to determine which slot to use (modulo capacity). The entire fixed buffer is read in Dump, discarding any zero (unused) events.
func NewCircularBuffer ¶
func NewCircularBuffer(capacity int) *CircularBuffer
NewCircularBuffer creates a new CircularBuffer with the given capacity and maximum stack frames per event.
func (*CircularBuffer) Dump ¶
func (cb *CircularBuffer) Dump() []Event
Dump returns a slice of events in the buffer in chronological order (oldest first).
func (*CircularBuffer) DumpTo ¶
func (cb *CircularBuffer) DumpTo(dst []Event) []Event
DumpTo appends events to the provided 'dst' slice in chronological order (oldest first). It iterates over the entire fixed buffer, acquiring each slot to safely read the event, and discards events that are zero (unused).
func (*CircularBuffer) Enqueue ¶
func (cb *CircularBuffer) Enqueue(event Event)
Enqueue adds a new event into the circular buffer in a lock-free manner. It claims the next slot using the atomic write pointer. If the slot is already acquired by another writer, the event is discarded and the function returns false.
type Config ¶
type Config struct { Enabled bool `help:"enable flight recorder" default:"false"` DBStackFrameCapacity int `help:"capacity of the circular buffer for database stack frame events." default:"1000"` }
Config holds configuration for the Flight Recorder (Box), including separate buffer configurations for each event type.
type Event ¶
Event represents a single recorded event. Timestamp is stored as a uint64 (Unix nanosecond timestamp) to minimize size. Stack is stored as a fixed-size array of uintptr, ensuring constant memory usage.
func (*Event) FormattedStack ¶
FormattedStack converts the fixed-size stack array into a human-readable string.