Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Go Execution Tracer

409 views

Published on

Slides for my talk at Gophercon Brazil 2017 on the Go execution tracer.

Published in: Software
  • Be the first to comment

Go Execution Tracer

  1. 1. Go execution tracer Gophercon Brazil 2017 André Carvalho
  2. 2. $ whoami • Developer @ globo.com / tsuru • Interested in all things performance, tracing and systems programming • @andresantostc • https://andrestc.com
  3. 3. Agenda • The tool basics • What is the Go execution tracer • How to collect trace data • How to analyze trace data • Using the tracer • to improve working code • to investigate a strange behavior
  4. 4. Go execution tracer • Gives insight into the execution of a Go program • What are my goroutines doing when not in CPU? • Instruments the go runtime • Captures events in nanosecond precision • Data is not aggregated/sampled! • Available since go 1.5
  5. 5. Go execution tracer • Events • Goroutines creation/start/end/block/unblock • Network • Syscalls • Memory allocation • Garbage collection
  6. 6. Collecting traces • Three ways to collect traces • trace.Start / trace.Stop • go test -trace=trace.out • debug/pprof/trace handler
  7. 7. Collecting traces • Writes the tracing output to os.Stderr • go run main.go 2> trace.out • go tool trace trace.out
  8. 8. Trace
  9. 9. View Trace 1. Timeline 2. Heap usage 3. goroutines 1 2 3 4 5 4. OS threads 5. Virtual Processors 6. goroutine + events 6
  10. 10. View Trace Selecting a goroutine
  11. 11. View Trace Selecting an event
  12. 12. Tracing web applications https://github.com/andrestc/go-tracing/tree/master/07-web
  13. 13. Using the tracer to improve working code
  14. 14. Mandelbrot CPU intensive calculations to figure out each pixel’s color https://github.com/campoy/ mandelbrot/
  15. 15. Pixel
  16. 16. Sequential
  17. 17. Sequential
  18. 18. One goroutine per pixel
  19. 19. One goroutine per pixel
  20. 20. One goroutine per pixel
  21. 21. One goroutine per column
  22. 22. Debugging a strange test behavior
  23. 23. Planb • github.com/tsuru/planb • reverse proxy based of hipache • One of tsuru’s key components • Used extensively on globo.com
  24. 24. Planb Planb Host: app.cloud.com Backend Backend Backend
  25. 25. Let’s trace it!
  26. 26. https://github.com/golang/go/issues/21204
  27. 27. Workaround https://github.com/tsuru/planb/pull/35
  28. 28. Conclusions • Go execution tracer helps understand concurrency • Complements other tools (eg memory/cpu profile) • Not much documentation available • Opportunity for contributions
  29. 29. Reference • Using the go tracer to speed up fractal rendering • Just for func #22 • Go Execution Tracer (Design Doc)
  30. 30. Slides and notes in english will be available at https://andrestc.com Obrigado!

×