Senior
Millised profiili tööriistad on Go-s olemas?
sobes.tech AI
Vastus AI-lt
In Go, for profiling applications, the net/http/pprof package is used, which allows collecting data on CPU, memory, locks, and goroutines. It can be attached to an HTTP server, and then profiles can be obtained via the standard interface.
There is also the go tool pprof utility for analyzing collected profiles.
Example of attaching pprof in code:
import (
"net/http"
_ "net/http/pprof"
)
func main() {
go func() {
http.ListenAndServe(":6060", nil) // Profiling is available at http://localhost:6060/debug/pprof/
}()
// main application code
}
To analyze CPU profile:
go tool pprof http://localhost:6060/debug/pprof/profile?seconds=30
Additionally, there are third-party tools like the pprof visualizer, go-torch for flamegraphs, and integrations with monitoring systems (Prometheus, Grafana).