Trung BìnhGolang iconGolang

Profiling Go application thế nào?

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.prof rồi mở bằng go 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 trace cho phép xem chi tiết execution trace theo timeline, hữu ích khi debug vấn đề concurrency và latency.

Xem toàn bộ Golang cùng filter theo level & chủ đề con.

Mở danh sách Golang