简体   繁体   中英

How to check heap allocation while step debugging through the application?

I need to review the memory consumption of a certain part of a program. At this point I don't care about leaks but simply about when the program allocates which objects in heap. I can trace the allocation back to certain methods but now I need to zoom in closer. Ideally I would like to step debug the code to reach the critical section and for every further step get an update on what memory has been allocated and where.

I tried using valgrind --massif in different ways. The closest I got was using vgdb and forcing a snapshot before and after the section I'm interested in and then comparing those manually in massif-visualizer. However I seem to be unable to set thresholds or ignore methods in a way that a small allocation (<1mB) is visible since the programm allocates a few hundred mB during startup.

I also tried gperftools heapprofiler but didn't get much further.

(I also tried heaptrack but so far failed to compile the gui tools)

I feel like I'm missing something here and make things more complicated than they have to be. How can I check heap allocation while step debugging through my application?

CentOS7 3.10, gcc 4.8.5

Update: This is a recurring task and I cannot always recompile the sw. I'm looking for a general solution that can be efficiently repeated with when analyzing "strange" memory consumption. Commercial tools would be ok as well as long as they def. get the job done.

If you're having trouble with external tools, you could also do rough profiling in code.

You can override the static new operator per-class. This would allow you to log/print typenames, sizes etc, and carry out initial filtering - with your 1MiB limit for example. Alternatively you can globally override the new operator to catch all allocations.

If you use standard library containers, custom allocators are also an option for tracking, if more involved.

Once allocations are under your control, you should be able to enable/disable logging once at your critical section.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM