rust-jemalloc-pprof icon indicating copy to clipboard operation
rust-jemalloc-pprof copied to clipboard

Support parsing existing jemalloc profile /proc/id/maps section

Open Rjected opened this issue 1 year ago • 3 comments

Right now parse_jeheap uses MAPPINGS to populate mapping information: https://github.com/polarsignals/rust-jemalloc-pprof/blob/07bc78af6487af7b31d057e02d5fabd46a024c5f/pure/src/lib.rs#L318-L322

When using parse_jeheap on an existing file, this still collects mappings for the running process: https://github.com/polarsignals/rust-jemalloc-pprof/blob/07bc78af6487af7b31d057e02d5fabd46a024c5f/pure/src/linux.rs#L44-L152

When profiling is enabled and disabled inline, this makes sense. However, for an existing jemalloc profile, this is counter-intuitive, because the returned mappings are not actually generated from the heap file.

For example, if this method is run on an existing heap file, the returned mappings will be different each time, and do not actually match what exists in the file.

It would be great to support parsing the /proc/id/maps output from the .heap file.

Rjected avatar Apr 08 '24 18:04 Rjected

Can you explain the use case a bit? Are you looking to extract the profile from outside of the process? What would you expect the API to look like?

cc @umanwizard

brancz avatar Apr 09 '24 08:04 brancz

If I understand correctly, @Rjected wants to use the library to parse unrelated jeheap files from other processes and transform them to pprof, which requires a way to provide the mappings. I think we can support this, I'll look into it later this week (Friday)

umanwizard avatar Apr 09 '24 13:04 umanwizard

If I understand correctly, @Rjected wants to use the library to parse unrelated jeheap files from other processes and transform them to pprof, which requires a way to provide the mappings. I think we can support this, I'll look into it later this week (Friday)

Yep that's exactly it! although I'm attempting to analyze them in the firefox profiler instead of pprof, like this: https://share.firefox.dev/3PIeyE6

Rjected avatar Apr 09 '24 13:04 Rjected

I did some thinking on what would be required to support this (for linux only for now):

  • proc maps parsing, from a Lines struct - could be done in the rsprocmaps crate
  • parsing of the elf note header for the population of the debug id. I'm not sure how comfortable I am parsing ELF headers by hand, so I would use a crate for this

Rjected avatar May 20 '24 19:05 Rjected

Hi @Rjected ,

Sorry for the long delay on this. In the latest version, you can pass the mappings of your choice to parse_jeheap.

umanwizard avatar Jul 03 '24 15:07 umanwizard