Documentation ¶
Overview ¶
Package profiler enables collecting supported profiles types by golang and sends them to SnappyFlowAPM for further visualization and analysis.
supported profiles: cpu, heap, block, mutex, goroutine, allocs, threadcreate
cpu and heap profiles are enabled always other types can be enabled as required.
Index ¶
- Constants
- type Config
- func (cfg *Config) DisableProfiles()
- func (cfg *Config) DisableRuntimeMetrics()
- func (cfg *Config) EnableAllProfiles()
- func (cfg *Config) EnableBlockProfile(rate int)
- func (cfg *Config) EnableGoRoutineProfile()
- func (cfg *Config) EnableMutexProfile(rate int)
- func (cfg *Config) EnableThreadCreateProfile()
- func (cfg *Config) SetCPUProfileDuration(i int)
- func (cfg *Config) SetInterval(i int)
- func (cfg *Config) SetLogger(logf func(format string, v ...interface{}))
- func (cfg *Config) SetTargetURL(url string)
- func (cfg *Config) Start()
- func (cfg *Config) Stop()
- func (cfg *Config) WriteProfileToFile()
Constants ¶
const ( // DefaultCPUProfileDuration is the default cpu profile duration in seconds. DefaultCPUProfileDuration = 10 * time.Second // DefaultProfileInterval is the default intervals at which profiles are collected. DefaultProfileInterval = 60 * time.Second // DefaultMutexProfileFraction // refer https://pkg.go.dev/runtime#SetMutexProfileFraction DefaultMutexProfileFraction = 100 // DefaultBlockProfileRate // refer https://pkg.go.dev/runtime#SetBlockProfileRate DefaultBlockProfileRate = 10000 // DefaultProfilesAge is the time to preserve old profile files. DefaultProfilesAge = 900 * time.Second // DefaultAgentURL default url to send profiles to agent. DefaultAgentURL = "http://127.0.0.1:8588" // DefaultClusterForwarderURL default url to send profiles to agent. DefaultClusterForwarderURL = "http://forwarder.sfagent.svc" // DefaultProfilesDir is the default directory where profiles are stored while writing to file. DefaultProfilesDir = "./profiles" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
Config for profiling.
func NewProfilerConfig ¶
NewProfilerConfig returns profiler config.
Accepts service name as argument, service name is required for identification.
func (*Config) DisableProfiles ¶ added in v0.1.2
func (cfg *Config) DisableProfiles()
DisableProfiles disables all profile collection.
func (*Config) DisableRuntimeMetrics ¶ added in v0.1.2
func (cfg *Config) DisableRuntimeMetrics()
DisableRuntimeMetrics disables runtime metric collection.
func (*Config) EnableAllProfiles ¶
func (cfg *Config) EnableAllProfiles()
EnableAllProfiles enables all currently supported profiles collection.
Enables cpu, heap, block, mutex, goroutine, threadcreate profiles collection.
sets block profile rate to DefaultBlockProfileRate
sets mutex profile fraction to DefaultMutexProfileFraction
func (*Config) EnableBlockProfile ¶
EnableBlockProfile enables block profile.
Calls runtime.SetBlockProfileRate(rate) to set given rate of block profile.
func (*Config) EnableGoRoutineProfile ¶
func (cfg *Config) EnableGoRoutineProfile()
EnableGoRoutineProfile enables goroutine profile collection.
func (*Config) EnableMutexProfile ¶
EnableMutexProfile enables mutex profile.
Calls runtime.SetMutexProfileFraction(rate) to set given mutex profile fraction.
func (*Config) EnableThreadCreateProfile ¶
func (cfg *Config) EnableThreadCreateProfile()
EnableThreadCreateProfile enables threadcreate profile collection.
func (*Config) SetCPUProfileDuration ¶
SetCPUProfileDuration sets duration in seconds for which cpu profile is collected.
func (*Config) SetInterval ¶
SetInterval sets interval in seconds between profiles collection.
func (*Config) SetLogger ¶
SetLogger allows to set custom logger, logger function format func(format string, v ...interface{}) .
func (*Config) SetTargetURL ¶
SetTargetURL sets target url to given string, useful for changing where profiles are sent.
func (*Config) WriteProfileToFile ¶
func (cfg *Config) WriteProfileToFile()
WriteProfileToFile writes all collected profiles to file to DefaultProfilesDir directory, with file name formatted as service_timestamp_pid.profiletype .