Documentation
¶
Overview ¶
Package tracer provides hierarchical call tracing and performance profiling for Go applications.
The tracer supports two modes:
- Discovery mode: Captures function calls to identify code paths for instrumentation
- Profiling mode: Records detailed timing information and builds call hierarchies
Usage:
tracer.Enable()
defer tracer.Disable()
// ... your code with tracer.Enter() calls ...
tracer.PrintWithOptions(tracer.PrintOptions{
RootFunction: "MyFunction",
ShowPercent: true,
ShowAbsolute: true,
})
Index ¶
- func Disable()
- func Enable()
- func EnableDiscovery()
- func Enter(funcName string) func()
- func GetCallHierarchy() string
- func GetDiscoveredPackages() []string
- func IsDiscoveryMode() bool
- func IsEnabled() bool
- func Print()
- func PrintSummary(topN int)
- func PrintSummaryWithOptions(topN int, rootFunctionName string, opts PrintOptions)
- func PrintSummaryWithRoot(topN int, rootFunctionName string)
- func PrintWithOptions(opts PrintOptions)
- type CallNode
- type FunctionStats
- type PrintOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Disable ¶
func Disable()
Disable deactivates the tracer and clears its state. Call this after profiling is complete, typically in a defer statement.
func Enable ¶
func Enable()
Enable activates the tracer in profiling mode. Call this before the code you want to profile, and Disable() when done.
func EnableDiscovery ¶
func EnableDiscovery()
EnableDiscovery activates the tracer in discovery mode. In this mode, the tracer captures function names without detailed timing, useful for identifying which packages need instrumentation.
func Enter ¶
func Enter(funcName string) func()
Enter records entry into a function and returns a function to call on exit. This should be called at the beginning of instrumented functions using defer:
func MyFunction() {
defer tracer.Enter("MyFunction")()
// ... function body ...
}
The function name should include the receiver type for methods:
defer tracer.Enter("(*MyType).MyMethod")()
func GetCallHierarchy ¶
func GetCallHierarchy() string
func GetDiscoveredPackages ¶
func GetDiscoveredPackages() []string
GetDiscoveredPackages returns all unique packages discovered during tracing
func IsDiscoveryMode ¶
func IsDiscoveryMode() bool
IsDiscoveryMode returns true if the tracer is in discovery mode.
func PrintSummary ¶
func PrintSummary(topN int)
func PrintSummaryWithOptions ¶
func PrintSummaryWithOptions(topN int, rootFunctionName string, opts PrintOptions)
PrintSummaryWithOptions prints a performance summary with configurable display options.
func PrintSummaryWithRoot ¶
func PrintWithOptions ¶
func PrintWithOptions(opts PrintOptions)
Types ¶
type CallNode ¶
type CallNode struct {
Name string // Function name (e.g., "(*Type).Method")
StartTime time.Time // When the function was entered
Duration time.Duration // Total time spent in this function
Children []*CallNode // Child function calls
Parent *CallNode // Parent function call
CallCount int // Number of times this function was called (for aggregation)
}
CallNode represents a single function call in the call hierarchy. It tracks timing, parent-child relationships, and call counts for aggregation.
type FunctionStats ¶
FunctionStats holds timing statistics for a function
type PrintOptions ¶
type PrintOptions struct {
RootFunction string // Start printing from this function (empty = use actual root)
ShowPercent bool // Show percentage of time relative to root
ShowAbsolute bool // Show absolute time duration
AggregateLoops bool // Combine multiple calls to same function
MinPercentage float64 // Hide functions below this percentage threshold
}
PrintOptions configures the output format for call hierarchy printing.