felixge / fgprof

🚀 fgprof is a sampling Go profiler that allows you to analyze On-CPU as well as Off-CPU (e.g. I/O) time together.
MIT License
2.81k stars 88 forks source link

what about memory? #28

Open ahdyt opened 4 months ago

ahdyt commented 4 months ago

Hi there, first of all, thank you for this good package, it helps me profling cpu better than have to run go tool pprof multiple times. I was just wondering if this will also support memory/heap profiling?

cristaloleg commented 4 months ago

What is wrong with the standard memory profiler?

ahdyt commented 4 months ago

The standard memory profiler only catch the last stack/gc/action, for an item that is already GCed it's not showed. I would like to keep every action and if it's GCed the diagram shows GCed.

Illustration:

  1. gops pprof-heap
  2. visit url /
  3. visit url /high-computation
  4. visit url /example
  5. dump to svg

The svg file only shows the last visit url /example memory usage, rather than capturing entire actions(visit url /, visit url /high-computation, visit url /example).

felixge commented 4 months ago

I'm not planning to add memory profiling to fgprof, but I think what you're looking for is a simple subtraction: alloc profile - heap inuse profile, that would show you the allocations since the start of the process that have since been GC'ed. The heap inuse profile shows you what remains after the most recent GC.

That being said, I don't know why such a profile would be useful.

ahdyt commented 4 months ago

Alright, I will search how to do the substraction of initial alloc and inuse heap.

This kind of profiling maybe good for catching any possibilities of memory leak or GC leftovers, especially in Go map struct.

felixge commented 4 months ago

I don't think you need this kind of analysis for understanding memory leaks. You just need to watch if the heap inuse profile is increasing in size. I've described this in more detail here: https://www.datadoghq.com/blog/go-memory-metrics/