Documentation
¶
Index ¶
- Variables
- type CPUProfileSession
- type CPUProfiler
- type ConfigProvider
- type GoroutineProfileSession
- type GoroutineProfiler
- type HTTPContext
- type HeapProfileSession
- type HeapProfiler
- type Logger
- type Manager
- func (m *Manager) Close() error
- func (m *Manager) GetStats() ProfilingStats
- func (m *Manager) GetTasks() map[string]ProfilingTask
- func (m *Manager) IsEnabled() bool
- func (m *Manager) RegisterProfiler(profiler Profiler)
- func (m *Manager) ShouldProfile(path, method string) (ProfilingTask, bool)
- func (m *Manager) StartProfiling(ctx context.Context, path string, task ProfilingTask) (ProfileSession, error)
- func (m *Manager) StopProfiling(ctx context.Context, path, method string, task ProfilingTask, ...) (*ProfilingResult, error)
- type Options
- type PathMatcher
- type ProfileSession
- type Profiler
- type ProfilingResult
- type ProfilingStats
- type ProfilingTask
- type Storage
Constants ¶
This section is empty.
Variables ¶
var CommonMethods = []string{"GET", "POST", "PUT", "DELETE"}
CommonMethods defines the methods supported by "*" wildcard
Functions ¶
This section is empty.
Types ¶
type CPUProfileSession ¶
type CPUProfileSession struct {
// contains filtered or unexported fields
}
CPUProfileSession represents a CPU profiling session
func (*CPUProfileSession) GetStartTime ¶
func (s *CPUProfileSession) GetStartTime() time.Time
GetStartTime returns when the session started
func (*CPUProfileSession) IsRunning ¶
func (s *CPUProfileSession) IsRunning() bool
IsRunning returns true if the session is still active
func (*CPUProfileSession) Stop ¶
func (s *CPUProfileSession) Stop() ([]byte, error)
Stop stops the profiling session
type CPUProfiler ¶
type CPUProfiler struct{}
CPUProfiler implements CPU profiling
func (*CPUProfiler) GetProfileType ¶
func (c *CPUProfiler) GetProfileType() string
GetProfileType returns the profiling type
func (*CPUProfiler) StartProfiling ¶
func (c *CPUProfiler) StartProfiling(ctx context.Context, task ProfilingTask) (ProfileSession, error)
StartProfiling starts CPU profiling
type ConfigProvider ¶
type ConfigProvider interface {
// GetTasks returns current profiling tasks
GetTasks(ctx context.Context) ([]ProfilingTask, error)
// Subscribe subscribes to configuration changes
Subscribe(ctx context.Context, callback func([]ProfilingTask)) error
// Close closes the provider and releases resources
Close() error
}
ConfigProvider abstracts configuration source for profiling tasks
type GoroutineProfileSession ¶
type GoroutineProfileSession struct {
// contains filtered or unexported fields
}
GoroutineProfileSession represents a goroutine profiling session
func (*GoroutineProfileSession) GetStartTime ¶
func (s *GoroutineProfileSession) GetStartTime() time.Time
GetStartTime returns when the session started
func (*GoroutineProfileSession) IsRunning ¶
func (s *GoroutineProfileSession) IsRunning() bool
IsRunning returns true if the session is still active
func (*GoroutineProfileSession) Stop ¶
func (s *GoroutineProfileSession) Stop() ([]byte, error)
Stop stops the profiling session and captures goroutine profile
type GoroutineProfiler ¶
type GoroutineProfiler struct{}
GoroutineProfiler implements goroutine profiling
func (*GoroutineProfiler) GetProfileType ¶
func (g *GoroutineProfiler) GetProfileType() string
GetProfileType returns the profiling type
func (*GoroutineProfiler) StartProfiling ¶
func (g *GoroutineProfiler) StartProfiling(ctx context.Context, task ProfilingTask) (ProfileSession, error)
StartProfiling starts goroutine profiling
type HTTPContext ¶
type HTTPContext interface {
// GetPath returns the route template (e.g., "/users/:id")
GetPath() string
// GetMethod returns the HTTP method
GetMethod() string
// GetHeaders returns request headers
GetHeaders() map[string]string
// SetContext sets a key-value pair in context
SetContext(key, value interface{})
// GetContext gets a value from context by key
GetContext(key interface{}) interface{}
// GetRequestPath returns the actual request path
GetRequestPath() string
}
HTTPContext abstracts HTTP request context for different frameworks
type HeapProfileSession ¶
type HeapProfileSession struct {
// contains filtered or unexported fields
}
HeapProfileSession represents a heap profiling session
func (*HeapProfileSession) GetStartTime ¶
func (s *HeapProfileSession) GetStartTime() time.Time
GetStartTime returns when the session started
func (*HeapProfileSession) IsRunning ¶
func (s *HeapProfileSession) IsRunning() bool
IsRunning returns true if the session is still active
func (*HeapProfileSession) Stop ¶
func (s *HeapProfileSession) Stop() ([]byte, error)
Stop stops the profiling session and captures heap profile
type HeapProfiler ¶
type HeapProfiler struct{}
HeapProfiler implements heap/memory profiling
func (*HeapProfiler) GetProfileType ¶
func (h *HeapProfiler) GetProfileType() string
GetProfileType returns the profiling type
func (*HeapProfiler) StartProfiling ¶
func (h *HeapProfiler) StartProfiling(ctx context.Context, task ProfilingTask) (ProfileSession, error)
StartProfiling starts heap profiling
type Logger ¶
type Logger interface {
// Info logs an info message
Info(msg string, fields map[string]interface{})
// Warn logs a warning message
Warn(msg string, fields map[string]interface{})
// Error logs an error message
Error(msg string, fields map[string]interface{})
// Debug logs a debug message
Debug(msg string, fields map[string]interface{})
}
Logger abstracts logging functionality
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager manages profiling sessions and tasks
func NewManager ¶
func NewManager(opts Options, configProvider ConfigProvider, storage Storage, logger Logger, pathMatcher PathMatcher) *Manager
NewManager creates a new profiling manager
func (*Manager) GetStats ¶
func (m *Manager) GetStats() ProfilingStats
GetStats returns current statistics
func (*Manager) GetTasks ¶
func (m *Manager) GetTasks() map[string]ProfilingTask
GetTasks returns current tasks
func (*Manager) RegisterProfiler ¶
RegisterProfiler registers a profiler for a specific type
func (*Manager) ShouldProfile ¶
func (m *Manager) ShouldProfile(path, method string) (ProfilingTask, bool)
ShouldProfile checks if a request should be profiled
func (*Manager) StartProfiling ¶
func (m *Manager) StartProfiling(ctx context.Context, path string, task ProfilingTask) (ProfileSession, error)
StartProfiling starts a profiling session
func (*Manager) StopProfiling ¶
func (m *Manager) StopProfiling(ctx context.Context, path, method string, task ProfilingTask, session ProfileSession) (*ProfilingResult, error)
StopProfiling stops a profiling session and saves the result
type Options ¶
type Options struct {
// MaxConcurrent is the maximum number of concurrent profiling sessions
MaxConcurrent int `yaml:"max_concurrent" json:"max_concurrent"`
// DefaultDuration is the default profiling duration
DefaultDuration time.Duration `yaml:"default_duration" json:"default_duration"`
// CleanupInterval is the interval for cleaning up old profiles
CleanupInterval time.Duration `yaml:"cleanup_interval" json:"cleanup_interval"`
// MaxFileAge is the maximum age for profile files before cleanup
MaxFileAge time.Duration `yaml:"max_file_age" json:"max_file_age"`
// Enabled controls whether profiling is enabled
Enabled bool `yaml:"enabled" json:"enabled"`
// ProfileDir is the directory to store profile files (for file storage)
ProfileDir string `yaml:"profile_dir" json:"profile_dir"`
// DefaultSampleRate is the default sample rate for profiling
DefaultSampleRate int `yaml:"default_sample_rate" json:"default_sample_rate"`
}
Options represents configuration options for the profiling manager
func DefaultOptions ¶
func DefaultOptions() Options
DefaultOptions returns default configuration options
type PathMatcher ¶
type PathMatcher interface {
// Match checks if actual path matches the template
Match(template, actual string) bool
// ExtractParams extracts parameters from actual path using template
ExtractParams(template, actual string) map[string]string
}
PathMatcher abstracts path matching logic
type ProfileSession ¶
type ProfileSession interface {
// Stop stops the profiling session and returns the result
Stop() ([]byte, error)
// GetStartTime returns when the session started
GetStartTime() time.Time
// IsRunning returns true if the session is still active
IsRunning() bool
}
ProfileSession represents an active profiling session
func NewCPUProfileSession ¶
func NewCPUProfileSession(ctx context.Context, task ProfilingTask) (ProfileSession, error)
NewCPUProfileSession creates a new CPU profiling session
func NewGoroutineProfileSession ¶
func NewGoroutineProfileSession(ctx context.Context, task ProfilingTask) (ProfileSession, error)
NewGoroutineProfileSession creates a new goroutine profiling session
func NewHeapProfileSession ¶
func NewHeapProfileSession(ctx context.Context, task ProfilingTask) (ProfileSession, error)
NewHeapProfileSession creates a new heap profiling session
type Profiler ¶
type Profiler interface {
// StartProfiling starts profiling with given configuration
StartProfiling(ctx context.Context, task ProfilingTask) (ProfileSession, error)
// GetProfileType returns the type of profiling this profiler handles
GetProfileType() string
}
Profiler abstracts different types of profiling
func NewGoroutineProfiler ¶
func NewGoroutineProfiler() Profiler
NewGoroutineProfiler creates a new goroutine profiler
type ProfilingResult ¶
type ProfilingResult struct {
Path string `json:"path"`
StartTime time.Time `json:"start_time"`
Duration time.Duration `json:"duration"`
Filename string `json:"filename"`
FileSize int64 `json:"file_size"`
ProfileType string `json:"profile_type"`
Success bool `json:"success"`
Error string `json:"error,omitempty"`
}
ProfilingResult represents the result of a profiling session
type ProfilingStats ¶
type ProfilingStats struct {
TotalRequests int64 `json:"total_requests"`
ProfiledCount int64 `json:"profiled_count"`
FailedCount int64 `json:"failed_count"`
ActiveProfiles int64 `json:"active_profiles"`
LastUpdate time.Time `json:"last_update"`
}
ProfilingStats represents profiling statistics
type ProfilingTask ¶
type ProfilingTask struct {
Path string `yaml:"path" json:"path"`
Method string `yaml:"method" json:"method"` // Single HTTP method or "*" for common methods
Methods []string `yaml:"methods" json:"methods"` // Multiple HTTP methods array
ExpiresAt time.Time `yaml:"expires_at" json:"expires_at"`
Duration int `yaml:"duration" json:"duration"` // Max profiling duration in seconds
SampleRate int `yaml:"sample_rate" json:"sample_rate"` // Sample every N requests
ProfileType string `yaml:"profile_type" json:"profile_type"` // cpu, heap, goroutine, etc.
}
ProfilingTask represents a profiling task configuration
func (*ProfilingTask) GetEffectiveMethods ¶
func (task *ProfilingTask) GetEffectiveMethods() []string
GetEffectiveMethods returns all methods that this task would match
func (*ProfilingTask) ShouldMatchMethod ¶
func (task *ProfilingTask) ShouldMatchMethod(requestMethod string) bool
ShouldMatchMethod checks if a request method matches the task configuration
type Storage ¶
type Storage interface {
// Save saves profile data to storage
Save(ctx context.Context, filename string, data []byte) error
// List lists files matching the given pattern
List(ctx context.Context, pattern string) ([]string, error)
// Delete deletes a file from storage
Delete(ctx context.Context, filename string) error
// Clean removes files older than maxAge
Clean(ctx context.Context, maxAge time.Duration) error
}
Storage abstracts storage backend for profile files