8 ms·
Memory Profiling: Introduction
- kohlerm 3y agohttp://kohlerm.blogspot.com/2009/02/how-to-really-measure-memory-usage-of.html http://kohlerm.blogspot.com/2009/02/how-to-really-measure-me... do we really still not have a decent memory usage analysis tool for c/ C++ ?
- Groxx 3y agoMAT is useful enough on its own to make me seriously consider Java almost everywhere. So many tricky memory leaks in other languages made completely trivial. Yes, in many languages you can combine a few things plus a core dump and figure leaks out too... but average people actually use MAT because it's largely transparent, and it can operate on running processes. Very few languages can compete with that in practice, much less with reasonable performance.
- spockz 3y agoIs there a tool for the jvm that can track data locality? TFA mentions three for Linux binaries but that won’t do the mapping to Java source if we can combine them with `java -jar` at all.
- kouteiheika 3y ago> do we really still not have a decent memory usage analysis tool for c/ C++ ? Shameless plug: not sure if I'd call it decent, but you might want to check my Bytehound for more in-depth analysis: https://github.com/koute/bytehound https://github.com/koute/bytehound
- kohlerm 3y agoIt is like others relying on tracking memory allocations. Which has it"s place, but to really analyze memory usage you would need to be able to analyze which "objects" are keeping other objects alive (dominator tree in MAT)
- milianw 3y agoIIUC then you might be looking for https://github.com/facebookexperimental/object-introspection https://github.com/facebookexperimental/object-introspection - very new and not yet easily usable outside of the Meta sphere, but goes into that direction, or?
- milianw 3y agoWhat is not decent about heaptrack or similar tools?
- malkia 3y agoSome of our tools do so much allocation that capturing all the information (using MTuner) to disk and later loading require by itself hundreths of GB. Instead I've added random sampling - e.g. if ptr % modulo > level - output it or not. Another factor that slows down is doing a callstack capture. It's not for free at all, like on Windows it has to go through the exception handlers, etc. I think perfetto simply captures the whole stack (need to check again), and then offline decodes it - or something like this. Windows ETW Tracing can also capture the stack, but I guess it'll incur also some penalty - it can't come for free. I also wish there was some kind of standard binary format for emitting alloc/free sequences with callstack/etc.
- kouteiheika 3y ago> Instead I've added random sampling - e.g. if ptr % modulo > level - output it or not. A good alternative that also cuts down on the amount of data significantly is to strip away temporary allocations, say, only emit those allocations which were alive for at least X seconds.
- malkia 3y agoAh good idea! It kind of calls for out-of-process to filter this out, or post-process (maybe there is common tooling around).
- milianw 3y agoHeaptrack can handle millions of allocations per second, and thanks to the deduplication built into the trace file format combined with zstd compression, the overhead is pretty manageable. It's pretty hard to get "hundreds of GB" of data recorded. Another thing: you can always just runtime attach and profile a partial time to reduce the amount of data recorded. Finally: if your tools do so many allocations, maybe you should consider optimizing them...
- malkia 3y agoThanks! Should look into heaptrack - reading that it's linux only, but probably can be adopted for Windows?
- irogers 3y agoSomewhat related, "Data-type profiling for perf": https://lwn.net/Articles/955709/ https://lwn.net/Articles/955709/
- koverstreet 3y agoComing to the kernel: https://lore.kernel.org/linux-mm/f4abca3f1d89d11f31b965e58a397aa6074be9d1.camel@linux.intel.com/T/ https://lore.kernel.org/linux-mm/f4abca3f1d89d11f31b965e58a3...
- GrayShade 3y agoOh, that's really sweet. Small question, what's the difference between (3) and (4)?