Go có hỗ trợ profiling tích hợp sẵn thông qua package net/http/pprof: chỉ cần import _ "net/http/pprof" là server tự expose các endpoint profiling tại /debug/pprof/.
- Để phân tích CPU, dùng
go test -cpuprofile=cpu.profrồi mở bằnggo tool pprof cpu.prof; tương tự với memory profiling dùng flag-memprofile=mem.profđể tìm các hàm allocate nhiều bộ nhớ. - Công cụ pprof hỗ trợ xem flame graph trực quan qua
pprof -http=:8080, giúp nhanh chóng nhận diện hot functions, excessive allocations, và goroutine leaks. - Ngoài ra
go tool tracecho phép xem chi tiết execution trace theo timeline, hữu ích khi debug vấn đề concurrency và latency.