profiler

package
v0.2.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 26, 2021 License: MPL-2.0 Imports: 14 Imported by: 0

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

View Source
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

func NewProfilerConfig(service string) *Config

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

func (cfg *Config) EnableBlockProfile(rate int)

EnableBlockProfile enables block profile.

Calls runtime.SetBlockProfileRate(rate) to set given rate of block profile.

refer: https://pkg.go.dev/runtime#SetBlockProfileRate

func (*Config) EnableGoRoutineProfile

func (cfg *Config) EnableGoRoutineProfile()

EnableGoRoutineProfile enables goroutine profile collection.

func (*Config) EnableMutexProfile

func (cfg *Config) EnableMutexProfile(rate int)

EnableMutexProfile enables mutex profile.

Calls runtime.SetMutexProfileFraction(rate) to set given mutex profile fraction.

refer: https://pkg.go.dev/runtime#SetMutexProfileFraction

func (*Config) EnableThreadCreateProfile

func (cfg *Config) EnableThreadCreateProfile()

EnableThreadCreateProfile enables threadcreate profile collection.

func (*Config) SetCPUProfileDuration

func (cfg *Config) SetCPUProfileDuration(i int)

SetCPUProfileDuration sets duration in seconds for which cpu profile is collected.

func (*Config) SetInterval

func (cfg *Config) SetInterval(i int)

SetInterval sets interval in seconds between profiles collection.

func (*Config) SetLogger

func (cfg *Config) SetLogger(logf func(format string, v ...interface{}))

SetLogger allows to set custom logger, logger function format func(format string, v ...interface{}) .

func (*Config) SetTargetURL

func (cfg *Config) SetTargetURL(url string)

SetTargetURL sets target url to given string, useful for changing where profiles are sent.

func (*Config) Start

func (cfg *Config) Start()

Start profile collection.

func (*Config) Stop

func (cfg *Config) Stop()

Stop profile collection.

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 .

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL