util

package
v0.104.0 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2020 License: GPL-3.0 Imports: 30 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func CanBindPort added in v0.103.0

func CanBindPort(port int) (bool, error)

CanBindPort - checks if we can bind to this port or not

func CheckPacketPortAvailable

func CheckPacketPortAvailable(host string, port int) error

CheckPacketPortAvailable - check if UDP port is available

func CheckPortAvailable

func CheckPortAvailable(host string, port int) error

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

func ConfigureSyslog(serviceName string) error

ConfigureSyslog reroutes standard logger output to syslog

func ContainsString added in v0.103.0

func ContainsString(arr []string, v string) bool

ContainsString checks if "v" is in the array "arr"

func DNSUnreverseAddr added in v0.103.0

func DNSUnreverseAddr(s string) net.IP

DNSUnreverseAddr - convert reversed ARPA address to a normal IP address

func ErrorIsAddrInUse

func ErrorIsAddrInUse(err error) bool

ErrorIsAddrInUse - check if error is "address already in use"

func FileExists

func FileExists(fn string) bool

fileExists returns TRUE if file exists

func FuncName

func FuncName() string

func GetInterfaceByIP

func GetInterfaceByIP(ip string) string

GetInterfaceByIP - Get interface name by its IP address.

func GetSubnet

func GetSubnet(ifaceName string) string

GetSubnet - Get IP address with netmask for the specified interface Returns an empty string if it fails to find it

func GetValidNetInterfaces

func GetValidNetInterfaces() ([]net.Interface, error)

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 Handler added in v0.102.0

func Handler(name string) http.Handler

Handler returns an HTTP handler that serves the named profile.

func HaveAdminRights

func HaveAdminRights() (bool, error)

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 IsFreeBSD added in v0.103.0

func IsFreeBSD() bool

IsFreeBSD checks if OS is FreeBSD

func IsOpenWrt added in v0.102.0

func IsOpenWrt() bool

IsOpenWrt checks if OS is OpenWRT

func LoadSystemRootCAs added in v0.102.0

func LoadSystemRootCAs() *x509.CertPool

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.

https://github.com/AdguardTeam/AdGuardHome/issues/1311

func MinInt added in v0.102.0

func MinInt(a, b int) int

MinInt - return the minimum value

func PProfRegisterWebHandlers added in v0.102.0

func PProfRegisterWebHandlers(mux *http.ServeMux)

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

func RunCommand(command string, arguments ...string) (int, string, error)

runCommand runs shell command

func SendProcessSignal added in v0.102.0

func SendProcessSignal(pid int, sig syscall.Signal) error

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

func SplitNext(str *string, splitBy byte) string

SplitNext - split string by a byte and return the first chunk Skip empty chunks Whitespace is trimmed

func Symbol added in v0.102.0

func Symbol(w http.ResponseWriter, r *http.Request)

Symbol looks up the program counters listed in the request, responding with a table mapping program counters to function names. The package initialization registers it as /debug/pprof/symbol.

func Trace added in v0.102.0

func Trace(w http.ResponseWriter, r *http.Request)

Trace responds with the execution trace in binary form. Tracing lasts for duration specified in seconds GET parameter, or for 1 second if not specified. The package initialization registers it as /debug/pprof/trace.

Types

type AutoHosts added in v0.102.0

type AutoHosts struct {
	// contains filtered or unexported fields
}

AutoHosts - automatic DNS records

func (*AutoHosts) Close added in v0.102.0

func (a *AutoHosts) Close()

Close - close module

func (*AutoHosts) Init added in v0.102.0

func (a *AutoHosts) Init(hostsFn string)

Init - initialize hostsFn: Override default name for the hosts-file (optional)

func (*AutoHosts) List added in v0.102.0

func (a *AutoHosts) List() map[string]string

List - get "IP -> hostname" table. Thread-safe.

func (*AutoHosts) Process added in v0.102.0

func (a *AutoHosts) Process(host string, qtype uint16) []net.IP

Process - get the list of IP addresses for the hostname Return nil if not found

func (*AutoHosts) ProcessReverse added in v0.102.0

func (a *AutoHosts) ProcessReverse(addr string, qtype uint16) string

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

func (*AutoHosts) Start added in v0.102.0

func (a *AutoHosts) Start()

Start - start module

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

Jump to

Keyboard shortcuts

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