trace

package
v0.0.0-...-d33c2ab Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2020 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Field

type Field struct {
	Key   string
	Value interface{}
}

Field is a key value pair that provides additional details about the trace.

type Trace

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

Trace keeps track of a set of "steps" and allows us to log a specific step if it took longer than its share of the total allowed time

func New

func New(name string, fields ...Field) *Trace

New creates a Trace with the specified name. The name identifies the operation to be traced. The Fields add key value pairs to provide additional details about the trace, such as operation inputs.

func (*Trace) Bytes

func (t *Trace) Bytes() []byte

Bytes returns a byte representation of the trace

func (*Trace) Log

func (t *Trace) Log()

Log is used to dump all the steps in the Trace

func (*Trace) LogIfLong

func (t *Trace) LogIfLong(threshold time.Duration)

LogIfLong is used to dump steps that took longer than its share

func (*Trace) Step

func (t *Trace) Step(msg string, fields ...Field)

Step adds a new step with a specific message. Call this at the end of an execution step to record how long it took. The Fields add key value pairs to provide additional details about the trace step.

Example
t := New("frobber")

time.Sleep(5 * time.Millisecond)
t.Step("reticulated splines") // took 5ms

time.Sleep(10 * time.Millisecond)
t.Step("sequenced particles") // took 10ms

klog.SetOutput(os.Stdout) // change output from stderr to stdout
t.Log()
Output:

func (*Trace) String

func (t *Trace) String() string

String returns a string representation of the trace

func (*Trace) TotalTime

func (t *Trace) TotalTime() time.Duration

TotalTime can be used to figure out how long it took since the Trace was created

Jump to

Keyboard shortcuts

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