Help us shape the future of Go! Take the 2026 Go Developer Survey

ttracker

package module
v0.0.0-...-97970da Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2016 License: Apache-2.0 Imports: 1 Imported by: 0

README

Timeout tracker

TTracker is made to find breakdown (by timings) in any parts of your code

Usage example

For example, you have program which is going to request database and then is making complexity calculations. You have to know where you will be catching latency for calls that are more than 100ms

// You have to define default handler for breakdown timeouts
func init() {
	ttracker.DefaultHandler = func(tracker *ttracker.TimeoutTracker) {
		for _, t := range tracker.Timeouts {
			fmt.Println(t.Label, t.Duration, t.Elapsed)
		}
	}
}

func handleRequest() {
    // Start timing tracking process
    t := ttracker.Start("my_tracker", 100*time.Millisecond)

    // ...goto remote storage, for example
    
    t.Track("storage")
    
    // ...make complex calculations
    
    t.Track("calculations")
    
    // Stop timing tracking process
    t.Stop()
}

This code will write to standard output tracker name, tracking label and label timeout for each handleRequest call which more than 100ms Example output will be like this

my_tracker tracker timings:
storage 82.520609ms 82.520609ms
calculations 89.155301ms 171.67591ms

See the source code here

Benchmarks & Tests

$: go test
OK: 4 passed
PASS
ok  	test/tracker	0.042s
$: go test -check.b -check.bmem
PASS: ttracker_test.go:74: TrackerSuite.BenchmarkTracking	 5000000	       596 ns/op	      98 B/op	       0 allocs/op
OK: 1 passed
PASS
ok  	test/tracker	4.162s

License

Apache 2.0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LabelHandler

type LabelHandler func(tracker *TimeoutTracker)
var (
	DefaultHandler LabelHandler
)

type Timeout

type Timeout struct {
	Label    string
	Duration time.Duration
	Elapsed  time.Duration
}

type TimeoutTracker

type TimeoutTracker struct {
	Duration time.Duration
	Handler  LabelHandler
	Name     string
	Timeouts []Timeout
	// contains filtered or unexported fields
}

func NewTimeoutTracker

func NewTimeoutTracker(name string, threshold time.Duration) *TimeoutTracker

func Start

func Start(name string, threshold time.Duration) *TimeoutTracker

func (*TimeoutTracker) Start

func (t *TimeoutTracker) Start() *TimeoutTracker

func (*TimeoutTracker) Stop

func (t *TimeoutTracker) Stop()

func (*TimeoutTracker) Track

func (t *TimeoutTracker) Track(label string)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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