prof

package
v0.0.9 Latest Latest
Warning

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

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

README

prof

Provides very 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)
  profFlag := flag.Bool("prof", false, "turn on targeted profiling")
  ...
  flag.Parse()
  prof.Profiling = *profFlag
  ...
  // surrounding the code of interest:
  pr := prof.Start("name of function")
  ... code
  pr.End()
  ...
  // at end or whenever you've got enough data:
  prof.Report(time.Millisecond) // or time.Second or whatever

Documentation

Overview

package prof provides very 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)
profFlag := flag.Bool("prof", false, "turn on targeted profiling")
...
flag.Parse()
prof.Profiling = *profFlag
...
// surrounding the code of interest:
pr := prof.Start()
... code
pr.End()
...
// at end or whenever you've got enough data:
prof.Report(time.Millisecond) // or time.Second or whatever

Index

Constants

This section is empty.

Variables

View Source
var Prof = Profiler{}
View Source
var Profiling = false

Functions

func Report

func Report(units time.Duration)

Report generates a report of all the profile data collected

func Reset

func Reset()

Reset all data

Types

type Profile

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

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 added in v0.0.3

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, units float64)

func (*Profile) Start

func (p *Profile) Start() *Profile

type Profiler

type Profiler struct {
	Profs 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