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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.