god

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2020 License: MIT Imports: 11 Imported by: 2

README

god

A small tool for simplifying debugging of go applications.

Import the library in your app:

import "github.com/256dpi/god"

Then add the following line as early as possible:

god.Debug()

This will open a pprof and prometheus endpoint on port 6060.

Use the god utility to interact with the endpoint:

god -duration 10

The tool will fetch the CPU profile by default but can also fetch other profiles:

Usage of god:
  -block
    	block profile
  -duration int
    	trace duration (default 5)
  -mem
    	memory profile
  -mutex
    	mutex profile
  -trace
    	trace profile

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

func Debug(alternativePort ...int)

Debug will run a god compatible debug endpoint.

func Metrics

func Metrics()

Metrics will enable the collection and printing of debug metrics.

Example
Metrics()

counter := NewCounter("counter", nil)
counter.Add(1)
counter.Add(2)

timer := NewTimer("timer")
timer.Add(time.Millisecond)
timer.Add(time.Second)

TrackFloat("track", func() float64 { return 2 })

time.Sleep(1500 * time.Millisecond)
Output:

counter: 3 c/s | timer: 1ms - 500.5ms - 1s | track: 2.00

func Track

func Track(name string, fn func() string)

Track will track a string over time.

func TrackFloat added in v0.3.0

func TrackFloat(name string, fn func() float64)

TrackFloat will track a float over time.

Types

type Counter

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

Counter is a simple operations counter.

func NewCounter

func NewCounter(name string, formatter func(total int) string) *Counter

NewCounter will create and return a counter.

func (*Counter) Add

func (c *Counter) Add(n int)

Add will increment the counter.

type Timer

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

Timer is a simple operations timer.

func NewTimer

func NewTimer(name string) *Timer

NewTimer will create and return a timer.

func (*Timer) Add

func (t *Timer) Add(d time.Duration)

Add will add the duration to the timer.

func (*Timer) Measure

func (t *Timer) Measure() func()

Measure can be used to track a function using defer.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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