VMMap Allocation Profiling and Leak Detection

August 27, 2011

4 comments

We have already seen VMMap as a tool for inspecting memory utilization and the layout of a process’ virtual address space.

The latest VMMap version (rush to download!) ships with a memory allocation profiler for VirtualAlloc() and HeapAlloc() calls. Additionally, the tool can display the allocating call stack for every heap block.

Sounds interesting? Here’s how to use it. You launch VMMap, and instead of inspecting an existing process, you tell it to launch and trace another process. (It uses Microsoft Detours to hook allocation APIs and log the information.)

image

Now you exercise your leaking application. The Timeline window gives you a good understanding of what type of memory is leaking:

image

The orange areas here are heap allocations, which are growing while everything else is fairly steady. When you’re convinced that there’s a leak, go to the detail view and start clicking suspicious heap areas. The “Heap Allocations” button at the bottom of the screen will become enabled, and clicking it provides a summary of allocations:

image

And now for each allocation you can obtain the stack trace:

image

Another approach is to click the “Trace” button, sort the output by bytes allocated, and start looking for suspicious call stacks:

image

I hope VMMap will be as useful to you as it is to me—and with memory allocation profiling, twice as useful.

Add comment
facebook linkedin twitter email

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*

4 comments

  1. OfekApril 24, 2012 ב 11:33 AM

    I can’t seem to get VMMap to use symbols for my own modules (BatteryMeter in your example above). I modified the symbol path dialog entry, and still no good. Did you succeed in viewing your own allocating function?

    Reply
  2. Sasha GoldshteinApril 28, 2012 ב 3:01 PM

    @Ofek: Yep, it works for me. Is there any chance that you’re using FPO or an FPO-enabled CRT?

    Reply
  3. linkMarch 29, 2017 ב 6:22 PM

    When I use vmmap to profile my application,the vmmap crash for memory over 2G user space memory。Did you have 64bit vmmap? Or can you help me to avoid vmmap crashing? 3Q

    Reply
    1. Sasha Goldshtein
      Sasha GoldshteinMarch 30, 2017 ב 2:40 PM

      I haven’t seen anything like this. Are you using a recent version of VMMap? What’s supposed to happen when you attach VMMap to a 64-bit process, is that it extracts and spawns vmmap64.exe (included as a resource in the VMMap binary).

      Reply