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 ¶
var Profiling = false
Profiling is whether profiling is currently enabled.
var TheProfiler = Profiler{}
TheProfiler is the global instance of Profiler.
Functions ¶
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 ¶
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 ¶
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.