Zum Inhalt springen
_CORE
AI & Agentic Systems Core Information Systems Cloud & Platform Engineering Data Platform & Integration Security & Compliance QA, Testing & Observability IoT, Automation & Robotics Mobile & Digital Banking & Finance Insurance Public Administration Defense & Security Healthcare Energy & Utilities Telco & Media Manufacturing Logistics & E-commerce Retail & Loyalty
Referenzen Technologien Blog Know-how Tools
Über uns Zusammenarbeit Karriere
CS EN DE
Lassen Sie uns sprechen

Go profiling s pprof: praktický průvodce

23. 06. 2024 1 Min. Lesezeit intermediate

Go má skvělé zabudované profiling nástroje. Jak je použít.

Aktivace pprof

import _ “net/http/pprof”
go func() { log.Println(http.ListenAndServe(“:6060”, nil)) }()

CPU profiling

go tool pprof http://localhost:6060/debug/pprof/profile?seconds=30

Memory

go tool pprof http://localhost:6060/debug/pprof/heap

Goroutines

curl http://localhost:6060/debug/pprof/goroutine?debug=1

Flame graphs

go tool pprof -http=:8080 cpu.prof

Benchmarky

func BenchmarkMyFunc(b *testing.B) { for i := 0; i < b.N; i++ { MyFunc() } }
go test -bench=. -benchmem

Optimalizace

  • sync.Pool pro opakované alokace
  • Prealokace slices
  • strings.Builder
  • Buffered channels

Shrnutí

pprof je zabudovaný a výkonný. CPU + heap stačí na 90 % problémů.

goperformanceprofiling
Teilen:

CORE SYSTEMS tým

Stavíme core systémy a AI agenty, které drží provoz. 15 let zkušeností s enterprise IT.