Documentation
¶
Overview ¶
Package mariobros is useful for monitoring Goroutine *leaks* from your code (get it? leaks?).
To use it, call mariobros.Start early in your process. mariobros.Start(mariobros.NewOptions()) should work fine locally, but you may want to supply a custom writer if you want the reports in your logs.
Then wherever you start a Goroutine, call Mariobros.Yo with a unique identifier for the operation, like 'level1.area4.lavapit'. Then defer the callback returned from that function, like:
go func() { mario := mariobros.Yo("level1.area4.lavapit") defer mario() // Do more stuff... }
Every 5 seconds (or whatever is configured), mariobros will report on the active goroutines.
You can configure mariobros when you call Start. NewOptions by default writes to stdout, and will read an integer value from the MARIOBROS envvar if specified (ie, use MARIOBROS=1 to poll every second). You can specify your own overrides.
If Mariobros is not active, calls to Yo noop and the timer that prints does not run. It's important to call Mariobros.Start() early, or import mariobros/autoload.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type GoroutineId ¶
type GoroutineId uint
type OptionModifier ¶
type OptionModifier func(*Options)
type Options ¶
func NewOptions ¶
func NewOptions(mods ...OptionModifier) Options
type Writer ¶
type Writer func(totalActive uint, activePerName map[string][]GoroutineId)
func KeyValueWriter ¶
KeyValueWriter is helpful when you want to log a structured message. For example:
mariobros.Start(mariobros.NewOptions(func(o *mariobros.Options) { o.Writer = mariobros.KeyValueWriter("mariobros_", func(m map[string]interface{}) { logger.WithFields(m).Info("mariobros") }) }))
func StreamWriter ¶
StreamWriter is used when you want to write mariobros output to a stream. The output you get is like:
active goroutines (1): my.job: 1, 5 other.job: 6, 7