mariobros

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2024 License: MIT Imports: 8 Imported by: 0

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

func Start

func Start(opts Options)

func Yo

func Yo(name string) func()

Types

type GoroutineId

type GoroutineId uint

type OptionModifier

type OptionModifier func(*Options)

type Options

type Options struct {
	Interval time.Duration
	Writer   Writer
}

func NewOptions

func NewOptions(mods ...OptionModifier) Options

type Writer

type Writer func(totalActive uint, activePerName map[string][]GoroutineId)

func KeyValueWriter

func KeyValueWriter(keyPrefix string, write func(map[string]interface{})) Writer

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

func StreamWriter(w io.Writer) Writer

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

Jump to

Keyboard shortcuts

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