profile

package module
v0.0.0-...-8e4a484 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2016 License: MIT Imports: 8 Imported by: 0

README

swat GoDoc Build Status

A general-purpose tool for debugging and analyzing programs, in development and production. Example:

package main

import (
    "os/syscall"
    "os"
    "time"
    "github.com/WatchBeam/swat"
)

func main() {
    s := swat.Start(
        swat.DumpGoroutine().
            OnSignal(syscall.SIGUSR1).
            ToWriter(os.Stdout),
        swat.DumpHeap().
            After(5*time.Minute).
            Every(time.Second).
            For(60*time.Second).
            ToFile("record.csv"),
    )
    defer s.End()

    // do the necessary!
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action interface {
	// Start should verify conditions, returning an error if
	// necessary, then start listening asynchronously.
	Start() error
	// End should signal the action to stop, and block until it does.
	End()
}

An "action" is the basic unit of Swat. It is started and should listen for events, until End is called.

type BaseAction

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

The base action is used to generate all the actions in Swat.

func DumpBlocking

func DumpBlocking() *BaseAction

Returns an action that dumps stack traces that led to blocking on synchronization primitives.

func DumpGoroutine

func DumpGoroutine() *BaseAction

Returns an action that dumps all running goroutines, like you'd get from a panic.

func DumpHeap

func DumpHeap() *BaseAction

Returns an action that dumps a sample of all head allocations.

func DumpPProfLookup

func DumpPProfLookup(name string, debug int) *BaseAction

Returns an action that dumps a pprof lookup, with the given name and debug constant.

func DumpThreadCreate

func DumpThreadCreate() *BaseAction

Returns an action that dumps stack traces that led to the creation of new OS threads.

func NewAction

func NewAction(fn func(io.Writer) error) *BaseAction

Creates and returns a new generic action. Currently there are two ways of triggering actions: by using a Scheduler and/or Signaller.

The Scheduler is activated by calling After, Every, At, For, or Until, and is used for running tasks after durations or on intervals.

The Signaller is activated by calling OnSignal, and will trigger an action to be run when a process gets a POSIX signal.

The output of the action can be sent to a writer. You can specify a writer using ToWriter, and there's a shortcut for specifying a file output using ToFile.

func (*BaseAction) After

func (b *BaseAction) After(after time.Duration) *BaseAction

`After` starts something after a given duration. Cannot be used with `At`. Omitting `After` and `At` cause the scheduler to start the task immediately

func (*BaseAction) At

func (b *BaseAction) At(at time.Time) *BaseAction

`At` starts something at a given time. Cannot be used with `After`. Omitting `After` and `At` cause the scheduler to start the task immediately.

func (*BaseAction) End

func (b *BaseAction) End()

Implements Action.End

func (*BaseAction) Every

func (b *BaseAction) Every(every time.Duration) *BaseAction

Specifies the time between runs, after the start time (specified by `After` or `At`) has passed. Omitting `Every` causes the action to be run just once.

func (*BaseAction) For

func (b *BaseAction) For(length time.Duration) *BaseAction

`For` specifies how long `Every` runs. annot be used with `Until`. Omitting both `For` and `Every` cause the event to run for an infinite time.

func (*BaseAction) OnSignal

func (b *BaseAction) OnSignal(signals ...os.Signal) *BaseAction

Used to run an action when an OS signal is received.

func (*BaseAction) Start

func (b *BaseAction) Start() error

Implements Action.Start

func (*BaseAction) ToFile

func (b *BaseAction) ToFile(f string) *BaseAction

Writes the output of the action to the writer.

func (*BaseAction) ToWriter

func (b *BaseAction) ToWriter(w io.Writer) *BaseAction

Writes the output of the action to the writer.

func (*BaseAction) Until

func (b *BaseAction) Until(until time.Time) *BaseAction

`Unil` specifies a time at which `Every` stops. Cannot be used with `For`. Omitting both `For` and `Every` cause the event to run for an infinite time.

type Swat

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

func Start

func Start(actions ...Action) (*Swat, error)

Creates a Swat with the given actions, and boots them all automatically.

func (*Swat) Boot

func (s *Swat) Boot(actions []Action) error

Starts all associated actions. If an action's Start method returns an error, then no actions are run.

func (*Swat) End

func (s *Swat) End()

Closes and waits for all actions to end.

Jump to

Keyboard shortcuts

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