1

The documentation for net/http/pprof explains how to create a 30-second CPU profiling session and analyze the outcome.

This allows me to initiate one or more HTTP requests and see the resulting CPU utilization of my web application.

I see a route for generating a heap profile, but since the profiling doesn't occur over something like a 30-second window, I'm unsure conceptually how this interacts with my web application.

How can I "coordinate" the heap profiler so that it corresponds with one or more HTTP requests?

TylerH
  • 20,799
  • 66
  • 75
  • 101
Tantillo
  • 367
  • 1
  • 5
  • 1
    "How can I "coordinate" the heap profiler so that it corresponds with one or more HTTP requests?" You cannot. The easiest thing is to make lots of requests in these 30s, e.g. via some load testing tool. – Volker Apr 14 '20 at 05:10

1 Answers1

3

I don't think you can scope the profiler exactly to a request, but a common methodology is to take multiple, intentionally timed, heap profiles. For example:

  • Take a single profile of your application at an empty state to set a baseline
  • Take a profile (or multiple profiles) while the application is loaded with a request (or multiple requests)
  • Take a profile afterwards

The powerful part of heap profiles is that pprof allows you to "diff" a profile by specifying 2 profiles! a base profile and a secondary profile to compare the base to!

Using this it becomes easy to see the difference in allocated objects or total bytes.

dm03514
  • 54,664
  • 18
  • 108
  • 145