Documentation ¶
Overview ¶
Package pprof serves via its HTTP server runtime profiling data in the format expected by the pprof visualization tool.
The package is typically only imported for the side effect of registering its HTTP handlers. The handled paths all begin with /debug/pprof/.
To use pprof, link this package into your program:
import _ "net/http/pprof"
If your application is not already running an http server, you need to start one. Add "net/http" and "log" to your imports and the following code to your main function:
go func() { log.Println(http.ListenAndServe("localhost:6060", nil)) }()
If you are not using DefaultServeMux, you will have to register handlers with the mux you are using.
Then use the pprof tool to look at the heap profile:
go tool pprof http://localhost:6060/debug/pprof/heap
Or to look at a 30-second CPU profile:
go tool pprof http://localhost:6060/debug/pprof/profile?seconds=30
Or to look at the goroutine blocking profile, after calling runtime.SetBlockProfileRate in your program:
go tool pprof http://localhost:6060/debug/pprof/block
Or to collect a 5-second execution trace:
wget http://localhost:6060/debug/pprof/trace?seconds=5
Or to look at the holders of contended mutexes, after calling runtime.SetMutexProfileFraction in your program:
go tool pprof http://localhost:6060/debug/pprof/mutex
To view all available profiles, open http://localhost:6060/debug/pprof/ in your browser.
For a study of the facility in action, visit
https://blog.golang.org/2011/06/profiling-go-programs.html
Index ¶
- func CanBindPort(port int) (bool, error)
- func CheckPacketPortAvailable(host string, port int) error
- func CheckPortAvailable(host string, port int) error
- func Cmdline(w http.ResponseWriter, r *http.Request)
- func ConfigureSyslog(serviceName string) error
- func ContainsString(arr []string, v string) bool
- func DNSUnreverseAddr(s string) net.IP
- func ErrorIsAddrInUse(err error) bool
- func FileExists(fn string) bool
- func FuncName() string
- func GetInterfaceByIP(ip string) string
- func GetSubnet(ifaceName string) string
- func GetValidNetInterfaces() ([]net.Interface, error)
- func Handler(name string) http.Handler
- func HaveAdminRights() (bool, error)
- func Index(w http.ResponseWriter, r *http.Request)
- func InitTLSCiphers() []uint16
- func IsFreeBSD() bool
- func IsOpenWrt() bool
- func LoadSystemRootCAs() *x509.CertPool
- func MinInt(a, b int) int
- func PProfRegisterWebHandlers(mux *http.ServeMux)
- func Profile(w http.ResponseWriter, r *http.Request)
- func RunCommand(command string, arguments ...string) (int, string, error)
- func SendProcessSignal(pid int, sig syscall.Signal) error
- func SetRlimit(val uint)
- func SplitNext(str *string, splitBy byte) string
- func Symbol(w http.ResponseWriter, r *http.Request)
- func Trace(w http.ResponseWriter, r *http.Request)
- type AutoHosts
- func (a *AutoHosts) Close()
- func (a *AutoHosts) Init(hostsFn string)
- func (a *AutoHosts) List() map[string]string
- func (a *AutoHosts) Process(host string, qtype uint16) []net.IP
- func (a *AutoHosts) ProcessReverse(addr string, qtype uint16) string
- func (a *AutoHosts) SetOnChanged(onChanged onChangedT)
- func (a *AutoHosts) Start()
- type NetInterface
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CanBindPort ¶ added in v0.103.0
CanBindPort - checks if we can bind to this port or not
func CheckPacketPortAvailable ¶
CheckPacketPortAvailable - check if UDP port is available
func CheckPortAvailable ¶
CheckPortAvailable - check if TCP port is available
func Cmdline ¶ added in v0.102.0
func Cmdline(w http.ResponseWriter, r *http.Request)
Cmdline responds with the running program's command line, with arguments separated by NUL bytes. The package initialization registers it as /debug/pprof/cmdline.
func ConfigureSyslog ¶
ConfigureSyslog reroutes standard logger output to syslog
func ContainsString ¶ added in v0.103.0
ContainsString checks if "v" is in the array "arr"
func DNSUnreverseAddr ¶ added in v0.103.0
DNSUnreverseAddr - convert reversed ARPA address to a normal IP address
func ErrorIsAddrInUse ¶
ErrorIsAddrInUse - check if error is "address already in use"
func GetInterfaceByIP ¶
GetInterfaceByIP - Get interface name by its IP address.
func GetSubnet ¶
GetSubnet - Get IP address with netmask for the specified interface Returns an empty string if it fails to find it
func GetValidNetInterfaces ¶
GetValidNetInterfaces returns interfaces that are eligible for DNS and/or DHCP invalid interface is a ppp interface or the one that doesn't allow broadcasts
func HaveAdminRights ¶
Check if the current user has root (administrator) rights
func Index ¶ added in v0.102.0
func Index(w http.ResponseWriter, r *http.Request)
Index responds with the pprof-formatted profile named by the request. For example, "/debug/pprof/heap" serves the "heap" profile. Index responds to a request for "/debug/pprof/" with an HTML page listing the available profiles.
func InitTLSCiphers ¶ added in v0.102.0
func InitTLSCiphers() []uint16
InitTLSCiphers - the same as initDefaultCipherSuites() from src/crypto/tls/common.go
but with the difference that we don't use so many other default ciphers.
func LoadSystemRootCAs ¶ added in v0.102.0
LoadSystemRootCAs - load root CAs from the system Return the x509 certificate pool object Return nil if nothing has been found.
This means that Go.crypto will use its default algorithm to find system root CA list.
func PProfRegisterWebHandlers ¶ added in v0.102.0
PProfRegisterWebHandlers - register HTTP handlers for pprof
func Profile ¶ added in v0.102.0
func Profile(w http.ResponseWriter, r *http.Request)
Profile responds with the pprof-formatted cpu profile. Profiling lasts for duration specified in seconds GET parameter, or for 30 seconds if not specified. The package initialization registers it as /debug/pprof/profile.
func RunCommand ¶
runCommand runs shell command
func SendProcessSignal ¶ added in v0.102.0
SendProcessSignal - send signal to a process
func SetRlimit ¶
func SetRlimit(val uint)
Set user-specified limit of how many fd's we can use https://github.com/AdguardTeam/AdGuardHome/issues/659
func SplitNext ¶
SplitNext - split string by a byte and return the first chunk Skip empty chunks Whitespace is trimmed
Types ¶
type AutoHosts ¶ added in v0.102.0
type AutoHosts struct {
// contains filtered or unexported fields
}
AutoHosts - automatic DNS records
func (*AutoHosts) Init ¶ added in v0.102.0
Init - initialize hostsFn: Override default name for the hosts-file (optional)
func (*AutoHosts) Process ¶ added in v0.102.0
Process - get the list of IP addresses for the hostname Return nil if not found
func (*AutoHosts) ProcessReverse ¶ added in v0.102.0
ProcessReverse - process PTR request Return "" if not found or an error occurred
func (*AutoHosts) SetOnChanged ¶ added in v0.102.0
func (a *AutoHosts) SetOnChanged(onChanged onChangedT)
SetOnChanged - set callback function that will be called when the data is changed
type NetInterface ¶
type NetInterface struct { Name string // Network interface name MTU int // MTU HardwareAddr string // Hardware address Addresses []string // Array with the network interface addresses Subnets []string // Array with CIDR addresses of this network interface Flags string // Network interface flags (up, broadcast, etc) }
NetInterface represents a list of network interfaces
func GetValidNetInterfacesForWeb ¶
func GetValidNetInterfacesForWeb() ([]NetInterface, error)
GetValidNetInterfacesForWeb returns interfaces that are eligible for DNS and WEB only we do not return link-local addresses here