profile

package
v0.3.5 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2024 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Overview

Package profile provides basic but effective profiling of targeted functions or code sections, which can often be more informative than generic cpu profiling.

Here's how you use it:

// somewhere near start of program (e.g., using flag package)
profileFlag := flag.Bool("profile", false, "turn on targeted profiling")
...
flag.Parse()
profile.Profiling = *profileFlag
...
// surrounding the code of interest:
pr := profile.Start()
... code
pr.End()
...
// at the end or whenever you've got enough data:
profile.Report(time.Millisecond) // or time.Second or whatever

Index

Constants

This section is empty.

Variables

View Source
var Profiling = false

Profiling is whether profiling is currently enabled.

View Source
var TheProfiler = Profiler{}

TheProfiler is the global instance of Profiler.

Functions

func Report

func Report(units time.Duration)

Report generates a report of all the profile data collected.

func Reset

func Reset()

Reset resets all of the profiling data.

Types

type Profile

type Profile struct {
	Name   string
	Total  time.Duration
	N      int64
	Avg    float64
	St     time.Time
	Timing bool
}

Profile represents one profiled function.

func Start

func Start(info ...string) *Profile

Start starts profiling and returns a Profile struct that must have Profile.End called on it when done timing. It will be nil if not the first to start timing on this function; it assumes nested inner / outer loop structure for calls to the same method. It uses the short, package-qualified name of the calling function as the name of the profile struct. Extra information can be passed to Start, which will be added at the end of the name in a dash-delimited format. See StartName for a version that supports a custom name.

func StartName

func StartName(name string, info ...string) *Profile

StartName starts profiling and returns a Profile struct that must have Profile.End called on it when done timing. It will be nil if not the first to start timing on this function; it assumes nested inner / outer loop structure for calls to the same method. It uses the given name as the name of the profile struct. Extra information can be passed to StartName, which will be added at the end of the name in a dash-delimited format. See Start for a version that automatically determines the name from the name of the calling function.

func (*Profile) End

func (p *Profile) End()

func (*Profile) Report

func (p *Profile) Report(tot float64, units time.Duration)

func (*Profile) Start

func (p *Profile) Start() *Profile

type Profiler

type Profiler struct {
	Profiles map[string]*Profile
	// contains filtered or unexported fields
}

Profiler manages a map of profiled functions.

func (*Profiler) Report

func (p *Profiler) Report(units time.Duration)

Report generates a report of all the profile data collected

func (*Profiler) Reset

func (p *Profiler) Reset()

func (*Profiler) Start

func (p *Profiler) Start(name string) *Profile

Start starts profiling and returns a Profile struct that must have .End() called on it when done timing

Jump to

Keyboard shortcuts

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