Reputation: 8437
Problem:
I have a multi-threaded C++ program, which handles quite some data (a few GB). At some point, my program runs out of main memory, which is something that I want to avoid. Theoretically, this should not happen, since the amount of data that this program analyzes is still much less than my main memory.
Assumed problem root:
My guess is that at some point I am passing all of that data by value to some function or some similar stupid mistake. This than ramps up my memory usage and I run out of main memory.
How can I find the code that causes the problem?
I would like to profile the memory usage of my program on a per-function basis. So the outcome should be something like (where both f
and g
are functions):
f used 10% of total memory used
g used 1% of total memory used
As suggested in this post, I had a look at massif by Valgrind. Looks like an amazing tool, but valgrind --tool=massif ./myProgram
takes forever (even if I reduce the amount of data substantially).
Question:
What tool can I use to find the "bug" in my source code? I am looking for something that does not take forever to run, but still gives me the insight I need. I am also willing to do this programmatically by somehow changing my source code.
Env:
Compiler: Clang 9
OS: RHEL
C++: std=17
Upvotes: 0
Views: 132