profile

package
v0.0.0-...-ba7cdbd Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2014 License: MPL-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// HeaderName is the header used for transmitting profiling
	// information while profiling a remote application.
	HeaderName = "X-Gondola-Profile"
	// Salt is the salt used for signing the app secret for requesting
	// profiling information.
	Salt = "gnd.la/app/profile.salt"
)
View Source
const On = profileIsOn

Variables

This section is empty.

Functions

func Begin

func Begin()

Begin enables profiling for the current goroutine. This function is idempotent. Any goroutine which calls Begin must also call End to avoid leaking resources.

func End

func End(parent int)

End removes any profiling data for this goroutine. It must called before the goroutine ends for each goroutine which called Begin(). If parent is non-zero, the events in the ending goroutine are added to the goroutine with the given ID.

func HasEvent

func HasEvent() bool

HasEvent returns true iff there's current an ongoing timed event for the current goroutine.

func ID

func ID() int

ID returns the profiling ID for the current goroutine.

func Notef

func Notef(title string, format string, args ...interface{})

Notef adds a note to the current Timed, as started by Start or Startf.

func Profile

func Profile(f func(), name string)

Profile is a shorthand function for calling Start(), executing f and the calling Timed.End() on the resulting Timed.

func Profilef

func Profilef(f func(), title string, name string, format string, args ...interface{})

Profilef is a shorthand function for calling Startf(), executing f and the calling Timed.End() on the resulting Timed.

func Profiling

func Profiling() bool

Profiling returns wheter profiling has been enabled for this goroutine.

func ReadCloser

func ReadCloser(r io.ReadCloser, name string, note string) io.ReadCloser

ReadCloser works like Reader, but wraps an io.ReadCloser.

func Reader

func Reader(r io.Reader, name string, note string) io.Reader

Reader returns an io.Reader which creates a timed profiling event everytime it's read from.

Types

type Event

type Event struct {
	Started time.Time `json:"s"`
	Ended   time.Time `json:"e"`
	Notes   []*Note   `json:"n"`
}

Event represents a finished event when its timing information and any notes it might have attached.

func (*Event) Elapsed

func (e *Event) Elapsed() time.Duration

Ellapsed returns the time the event took.

type Note

type Note struct {
	Title string
	Text  string
}

Note represents a note added to an event.

type Timed

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

Timed represents an ongoing timed event. Use Start or Startf to start a timed event.

func Start

func Start(name string) *Timed

Start starts a timed event. Use Timed.End to terminate the event or Timed.AutoEnd to finish it when the request finishes processing. Note that if profiling is not enabled for the current goroutine, this function does nothing and returns an empty event.

func Startf

func Startf(name string, title string, format string, args ...interface{}) *Timed

Startf is a shorthand function for calling Start and then Timed.Notef on the resulting Ev.

func (*Timed) AutoEnd

func (e *Timed) AutoEnd() *Timed

AutoEnd causes the timed event to be ended when the timings are requested.

func (*Timed) End

func (t *Timed) End()

End ends the timed event.

func (*Timed) Ended

func (t *Timed) Ended() bool

Ended returns wheter the timed event has finished.

func (*Timed) Note

func (t *Timed) Note(title string, text string) *Timed

Note adds a note regarding this timed event (e.g. the SQL query that was executed, the URL that was fetched, etc...).

func (*Timed) Notef

func (t *Timed) Notef(title string, format string, args ...interface{}) *Timed

Notef works like Note(), but accepts a format string.

type Timing

type Timing struct {
	Name   string   `json:"n"`
	Events []*Event `json:"e"`
}

Timing represents a set of events of the same kind.

func Timings

func Timings() []*Timing

Timings returns the available timings for the current goroutine. Note that calling Timings will end any events which have been set to automatically end (with Timed.AutoEnd) so this function should only be called at the end of the request lifecycle.

func (*Timing) Count

func (t *Timing) Count() int

Count returns the number of events contained in this timing.

func (*Timing) Total

func (t *Timing) Total() time.Duration

Total returns the total elapsed time for all the events in this Timing.

Jump to

Keyboard shortcuts

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