Profiling

When we wish to take a look at the speed of our program, the best technique we can employ is profiling. Profiling automatically samples your running application while it is executing; and then we can compute that data, such as the running time of a particular function, into a statistical summary called a profile.

Go supports three different types of profiling:

  • CPU: Identifies the tasks which require the most CPU time
  • Heap: Identifies the statements responsible for allocating the most memory
  • Blocking: Identifies the operations responsible for blocking Go routines for the longest time

If we would like to enable profiling on our application, we can do one of two things:

  • Add import "net/http/pprof" to your startup file
  • Manually start ...

Get Building Microservices with Go now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.