Documentation
¶
Index ¶
- func RegisterSQLDriver(name string, driver driver.Driver, profiler *Profiler)
- type Bottleneck
- type FlameGraph
- type FlameGraphNode
- type HTTPCallMetric
- type HotSpot
- type Metrics
- type ProfileType
- type ProfileWriter
- type Profiler
- func (p *Profiler) ClearMetrics()
- func (p *Profiler) EndProfiling(ctx context.Context) *Metrics
- func (p *Profiler) GetAllMetrics() []*Metrics
- func (p *Profiler) GetMetrics(requestID string) (*Metrics, bool)
- func (p *Profiler) RecordFunction(ctx context.Context, name string, fn func() error) error
- func (p *Profiler) RecordHTTPCall(ctx context.Context, method, url string, duration time.Duration, status int, ...)
- func (p *Profiler) RecordSQLQuery(ctx context.Context, query string, duration time.Duration, rows int, err error)
- func (p *Profiler) SetEnabled(enabled bool)
- func (p *Profiler) SetProfileType(pt ProfileType)
- func (p *Profiler) SetThreshold(threshold time.Duration)
- func (p *Profiler) SetTracer(ctx context.Context, tracer interface{})
- func (p *Profiler) StartProfiling(ctx context.Context, requestID string) context.Context
- type SQLHook
- type SQLQueryMetric
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Bottleneck ¶
type Bottleneck struct {
Type string `json:"type"` // "cpu", "memory", "io", "database", "http"
Description string `json:"description"`
Impact float64 `json:"impact"` // 0-1 scale of impact
Duration time.Duration `json:"duration"`
Suggestion string `json:"suggestion"`
}
Bottleneck represents a performance bottleneck
type FlameGraph ¶
type FlameGraph struct {
Root *FlameGraphNode `json:"root"`
TotalTime int64 `json:"total_time"`
SampleCount int64 `json:"sample_count"`
}
FlameGraph generates flame graph data from CPU profile
func GenerateFlameGraph ¶
func GenerateFlameGraph(profileData []byte) (*FlameGraph, error)
GenerateFlameGraph generates a flame graph from CPU profile data
func (*FlameGraph) ConvertToD3Format ¶
func (fg *FlameGraph) ConvertToD3Format() map[string]interface{}
ConvertToD3Format converts the flame graph to D3.js compatible format
func (*FlameGraph) GenerateTextFlameGraph ¶
func (fg *FlameGraph) GenerateTextFlameGraph() string
GenerateTextFlameGraph generates a text-based flame graph (folded stack format)
func (*FlameGraph) GetHotSpots ¶
func (fg *FlameGraph) GetHotSpots(threshold float64) []HotSpot
GetHotSpots identifies the hottest code paths
type FlameGraphNode ¶
type FlameGraphNode struct {
Name string `json:"name"`
Value int64 `json:"value"` // Time spent in nanoseconds
Children []*FlameGraphNode `json:"children"`
}
FlameGraphNode represents a node in the flame graph
type HTTPCallMetric ¶
type HTTPCallMetric struct {
Method string `json:"method"`
URL string `json:"url"`
Duration time.Duration `json:"duration"`
Status int `json:"status"`
Size int64 `json:"size"`
}
HTTPCallMetric represents metrics for an HTTP call
type HotSpot ¶
type HotSpot struct {
Path []string `json:"path"`
Name string `json:"name"`
Time int64 `json:"time"`
Percentage float64 `json:"percentage"`
}
HotSpot represents a performance hot spot
type Metrics ¶
type Metrics struct {
RequestID string `json:"request_id"`
StartTime time.Time `json:"start_time"`
EndTime time.Time `json:"end_time"`
Duration time.Duration `json:"duration"`
CPUTime time.Duration `json:"cpu_time"`
MemoryAlloc uint64 `json:"memory_alloc"`
MemoryTotalAlloc uint64 `json:"memory_total_alloc"`
NumGoroutines int `json:"num_goroutines"`
NumGC uint32 `json:"num_gc"`
GCPauseTotal time.Duration `json:"gc_pause_total"`
FunctionTimings map[string]time.Duration `json:"function_timings,omitempty"`
SQLQueries []SQLQueryMetric `json:"sql_queries,omitempty"`
HTTPCalls []HTTPCallMetric `json:"http_calls,omitempty"`
Bottlenecks []Bottleneck `json:"bottlenecks,omitempty"`
CPUProfile []byte `json:"-"` // Raw CPU profile data
HeapProfile []byte `json:"-"` // Raw heap profile data
}
Metrics contains performance metrics for a request
type ProfileType ¶
type ProfileType uint32
ProfileType represents the type of profiling to perform
const ( // ProfileNone disables all profiling ProfileNone ProfileType = 0 // ProfileCPU enables CPU profiling ProfileCPU ProfileType = 1 << iota // ProfileMemory enables memory profiling ProfileMemory // ProfileGoroutine enables goroutine tracking ProfileGoroutine // ProfileBlocking enables blocking profiling ProfileBlocking // ProfileAll enables all profiling types ProfileAll = ProfileCPU | ProfileMemory | ProfileGoroutine | ProfileBlocking )
type ProfileWriter ¶
type ProfileWriter struct {
// contains filtered or unexported fields
}
ProfileWriter captures CPU profiles
type Profiler ¶
type Profiler struct {
// contains filtered or unexported fields
}
Profiler handles performance profiling for requests
func NewProfiler ¶
NewProfiler creates a new profiler instance
func (*Profiler) ClearMetrics ¶
func (p *Profiler) ClearMetrics()
ClearMetrics clears all stored metrics
func (*Profiler) EndProfiling ¶
EndProfiling ends profiling for a request
func (*Profiler) GetAllMetrics ¶
GetAllMetrics retrieves all stored metrics
func (*Profiler) GetMetrics ¶
GetMetrics retrieves metrics for a request
func (*Profiler) RecordFunction ¶
RecordFunction records the timing of a function
func (*Profiler) RecordHTTPCall ¶
func (p *Profiler) RecordHTTPCall(ctx context.Context, method, url string, duration time.Duration, status int, size int64)
RecordHTTPCall records metrics for an HTTP call
func (*Profiler) RecordSQLQuery ¶
func (p *Profiler) RecordSQLQuery(ctx context.Context, query string, duration time.Duration, rows int, err error)
RecordSQLQuery records metrics for a SQL query
func (*Profiler) SetEnabled ¶
SetEnabled enables or disables profiling
func (*Profiler) SetProfileType ¶
func (p *Profiler) SetProfileType(pt ProfileType)
SetProfileType sets the types of profiling to perform
func (*Profiler) SetThreshold ¶
SetThreshold sets the minimum duration to trigger profiling