trace

package
v0.0.0-...-4905c10 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2018 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package trace provides a ring buffer utility to trace events.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MsgsToString

func MsgsToString(msgs []Msg, lineSep, linePrefix string) string

MsgsToString formats a []Msg into a pretty string. lineSep is usually something like "\n". linePrefix is usually something like " ".

Types

type Msg

type Msg struct {
	Title string
	Body  []byte `json:"Body,omitempty"`

	// Repeats will be >1 when there was a "run" of consolidated,
	// repeated trace messages.
	Repeats uint64
}

A Msg is a trace message, which might be repeated.

func ConsolidateByTitle

func ConsolidateByTitle(next *Msg, prev *Msg) *Msg

ConsolidateByTitle implements the MsgConsolidateFunc signature by consolidating trace message when their titles are the same.

type MsgConsolidateFunc

type MsgConsolidateFunc func(next *Msg, prev *Msg) *Msg

MsgConsolidateFunc is the func signature of an optional merge function, allowing for similar trace messages to be consolidated. For example, instead of using 216 individual slots in the ring buffer, in order to save space, the consolidation func can arrange for just a single entry of "216 repeated mutations" to be used instead.

The next and prev Msg parameters may be modified by the consolidate func. The consolidate func should return nil if it performed a consolidation and doesn't want a new entry written.

type RingBuffer

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

A RingBuffer provides a ring buffer to capture trace messages, along with an optional consolidation func that can merge similar, consecutive trace messages.

func NewRingBuffer

func NewRingBuffer(
	capacity int,
	consolidateFunc MsgConsolidateFunc) *RingBuffer

NewRingBuffer returns a RingBuffer initialized with the given capacity and optional consolidateFunc.

func (*RingBuffer) Add

func (trb *RingBuffer) Add(title string, body []byte)

Add appens a trace message to the ring buffer, consolidating trace messages based on the optional consolidation function.

func (*RingBuffer) Cap

func (trb *RingBuffer) Cap() int

Cap returns the capacity of the ring buffer.

func (*RingBuffer) Last

func (trb *RingBuffer) Last() *Msg

Last returns the last trace in the ring buffer.

func (*RingBuffer) Msgs

func (trb *RingBuffer) Msgs() []Msg

Msgs returns a copy of all the trace messages, as an array with the oldest trace message first.

Jump to

Keyboard shortcuts

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