RudjiGames / MTuner

MTuner is a C/C++ memory profiler and memory leak finder for Windows, PlayStation 4 and 3, Android and other platforms
BSD 2-Clause "Simplified" License
2.63k stars 145 forks source link

merging of stack frames not always successful #34

Closed milianw closed 6 years ago

milianw commented 6 years ago

Take this example code:

#include <string>

void myfunc()
{
    for (int i = 0; i < 100000; ++i) {
        std::string s1("this is a very very long string this is a very long string this is a very long string");
        std::string s2("another one: this is a very very long string this is a very long string this is a very long string");
    }
}

int main()
{
    myfunc();
    return 0;
}

Compile it with cl.exe /Zi test.cpp and trace it with MTuner. Then inspect the stack tree and notice how seemingly equivalent stack frames are not merged. Maybe it's because the instruction pointer address is used for the merging, instead of the user-visible symbol name?

non-unique

milostosic commented 6 years ago

Yes, that's exactly the case. I agree it's not pretty but the motivation was performance - profiling applications that have tens of millions of allocations tends to result in slow population of stack tree and related structures if symbol resolution is involved. I'll think about this one...

milianw commented 6 years ago

The merging can happen at analysis time, and the resolution of the instruction pointer address to symbol name can be cached. Furthermore, properly merging can actually result in a reduction in overhead since the tree will be smaller, which can bring considerable memory reductions (I've seen this in heaptrack).

milostosic commented 6 years ago

I was wrong here... return address isn't used but a 'symbol ID' which is just a symbol offset. Just fixed symbol ID enumeration so this should be working in the next release.