measure

package
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2018 License: Apache-2.0 Imports: 5 Imported by: 14

README

Stopwatch

A simple utility able to log measured time periods of various events. To create a new stopwatch, call:

sw := NewStopwatch(name string, log logging.Logger)

Stopwatch object can store a new entry with sw.LogTimeEntry(n interface{}, d time.Duration) where n is a string representation of a measured entity (name of a function, struct or just simple string) and d is time duration. If the name already exists, it will be indexed (for example name#1)

Use sw.Print() to print all measurements and clear stored entries.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type StopWatchEntry

type StopWatchEntry interface {
	LogTimeEntry(d time.Duration)
}

StopWatchEntry provides method to log measured time entries

type Stopwatch

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

Stopwatch keeps all time measurement results

func NewStopwatch

func NewStopwatch(name string, log logging.Logger) *Stopwatch

NewStopwatch creates a new stopwatch object with empty time map

func (*Stopwatch) LogTimeEntryFor added in v1.0.8

func (st *Stopwatch) LogTimeEntryFor(n interface{}) func()

LogTimeEntryFor sets start time and returns func which logs the time entry, usable as single-line defer call: `defer s.LogTimeEntryFor("xyz")()`

func (*Stopwatch) PrintLog

func (st *Stopwatch) PrintLog()

PrintLog all entries from TimeLog and reset it

type TimeLog

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

TimeLog is a wrapper for the measured data for specific name

func GetTimeLog

func GetTimeLog(n interface{}, s *Stopwatch) *TimeLog

GetTimeLog returns a pointer to the TimeLog object related to the provided name (derived from the <n> parameter). If stopwatch is not used, returns nil

func (*TimeLog) LogTimeEntry

func (t *TimeLog) LogTimeEntry(d time.Duration)

LogTimeEntry stores time entry to the TimeLog (the time log itself is stored in the stopwatch sync.Map)

Jump to

Keyboard shortcuts

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