god

package module
v0.4.4 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2022 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 all available profiles, run the pprof servers and open a custom frontend from which all profiles can be accessed.

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init added in v0.4.1

func Init(opts Options)

Init will run a god compatible debug endpoint.

Example
// init
Init(Options{})

// block events
go func() {
	for {
		<-time.After(time.Millisecond)
	}
}()

// mutex events
var m sync.Mutex
for i := 0; i < 2; i++ {
	go func() {
		for {
			m.Lock()
			time.Sleep(time.Millisecond)
			m.Unlock()
		}
	}()
}

fmt.Println("Hello")

select {}
Output:

Hello

func Register added in v0.4.1

func Register(name string, m Metric)

Register will register the provided metric.

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.

func TrackInt added in v0.4.1

func TrackInt(name string, fn func() int64)

TrackInt will track an integer 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.

func (*Counter) Collect added in v0.4.1

func (c *Counter) Collect() string

Collect implements the Metric interface.

type Metric added in v0.4.1

type Metric interface {
	// Collect is called every second to retrieve the current value.
	Collect() string
}

Metric represents a periodically collected metric.

type Options added in v0.4.1

type Options struct {
	// The port to run the debug interface on.
	//
	// Default: 6060.
	Port int

	// The memory profile rate.
	//
	// Default: 1024.
	MemoryProfileRate int

	// The mutex profile fraction.
	//
	// Default: 1.
	MutexProfileFraction int

	// The block profile rate.
	//
	// Default: 1.
	BlockProfileRate int

	// Custom handler for the status endpoint.
	//
	// Default: "OK" writer.
	StatusHandler http.HandlerFunc

	// Custom handler for the metrics endpoint.
	MetricsHandler http.HandlerFunc
}

Options define the available debugging options.

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) Collect added in v0.4.1

func (t *Timer) Collect() string

Collect implements the Metric interface.

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