prof

package module
v2.0.0-dev0.0.6 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2024 License: MIT Imports: 8 Imported by: 1

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

View Source
const (
	// Version is the version of this package being used
	Version = "v2.0.0-dev0.0.6"
	// GitCommit is the commit just before the latest version commit
	GitCommit = "52366ed"
	// VersionDate is the date-time of the latest version commit in UTC (in the format 'YYYY-MM-DD HH:MM', which is the Go format '2006-01-02 15:04')
	VersionDate = "2024-01-09 01:20"
)

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.

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