Junior — Middle
What profiling methods have you used in your work?
sobes.tech AI
Answer from AI
When working with Go for profiling, I usually use the built-in pprof package, which allows collecting and analyzing profiles of CPU, memory, locks, and goroutines.
Main methods:
- CPU profiling: helps understand which functions take the most processor time.
- Heap profiling: identifies memory leaks and objects occupying a lot of memory.
- Block profiling: analyzes locks and waits.
- Goroutine profiling: shows the state of goroutines, helps identify deadlocks or leaks.
Example of starting a CPU profile:
import (
"net/http"
_ "net/http/pprof"
)
func main() {
go func() {
log.Println(http.ListenAndServe("localhost:6060", nil))
}()
// main code
}
After starting, you can connect to http://localhost:6060/debug/pprof/ and download profiles for analysis using go tool pprof.
I also use external tools, such as perf on Linux for system profiling, and visualizers like pprof.io.