Memory profilers are essential tools to understand the dynamic behavior of complex modern programs. They help to reveal memory handling details: the wheres, the whens and the whats of memory allocations. Most heap profilers provide sufficient information about which part of the source code is responsible for the memory allocations by showing us the relevant call stacks. The sequence of allocations inform us about their order. Heap profilers for languages with strong reflection capabilities can also show type information on the allocated objects. However, in C++ we have no reflection, allocators used for standard containers erase type information, and complex syntax of special new and delete operators make preprocessor hacks impossible. In this lecture we will report on a type preserving heap profiler for C++ based on the LLVM/Clang tooling library. On top of the usual heap profiler features our allocation entries, including those of template constructs, contain exact type information about the allocated objects. We can extract information on individual memory operations as well as supply aggregated overview. E.g. user can tell how much memory was used of std::vector objects in every point of the run, when, where and how they were allocated and freed. Having such a type information in hand programmers can identify critical classes responsible for memory usage more easily and can perform optimizations based on evidence rather than speculations. The tool is publicly available at: https://github.com/typegrind
Dr. Zoltán Porkoláb is an Associate Professor of Faculty of informatics at Eötvös Loránd University (ELTE), Budapest, Hungary. At the same time, he holds Principal C++ Developer position at Ericsson Hungary Ltd.