I would like inspect native heap of process to see what native classes are present in memory and what are their size. Its equivalent to sos !dumpheap -stat command. Is it possible to do it on the native side?
I am guessing that the reason you want to inspect native heap is to analyze heap usage and possibly figure out what is the nature of the allocations on the heap and what part of code is responsible for that. If so, the output from umdh tool is the closest I can think of. It is much more verbose than !dumpheap -stat
, but you can get much more from it -- e.g. you can pinpoint exact code that is responsible for allocations by looking at the allocation call stacks.
Normally Umdh is used for memory leak diagnostics. To get breakdown of all allocations in the process you will need to use so called single-dump mode.
Although the output of Umdh won't tell you directly what is the native type being allocated, in most cases you can derive it easily from the allocation call stack. For example, in this snippet from Umdh output there are 0x4a allocations consuming a total of 0x194b0 bytes, and type of allocations are easy to figure out, since std::vector<unsinged short>
are in the call stack, and allocation was done within method RecordData::Deserialize.
+ 194b0 ( 194b0 - 0) 4a allocs BackTraceD0F18F8
+ 4a ( 4a - 0) BackTraceD0F18F8 allocations
ntdll!RtlAllocateHeap+36991
MSVCR120D!_heap_alloc_base+51 (f:\dd\vctools\crt\crtw32\heap\malloc.c, 58)
MSVCR120D!_heap_alloc_dbg_impl+1FF (f:\dd\vctools\crt\crtw32\misc\dbgheap.c, 431)
MSVCR120D!_nh_malloc_dbg_impl+1D (f:\dd\vctools\crt\crtw32\misc\dbgheap.c, 239)
MSVCR120D!_nh_malloc_dbg+2A (f:\dd\vctools\crt\crtw32\misc\dbgheap.c, 302)
MSVCR120D!malloc+19 (f:\dd\vctools\crt\crtw32\misc\dbgmalloc.c, 56)
MSVCR120D!operator new+F (f:\dd\vctools\crt\crtw32\heap\new.cpp, 59)
STestViewer!std::_Allocate<unsigned short>+2F (c:\program files (x86)\microsoft visual studio 12.0\vc\include\xmemory0, 28)
STestViewer!std::allocator<unsigned short>::allocate+19 (c:\program files (x86)\microsoft visual studio 12.0\vc\include\xmemory0, 578)
STestViewer!std::_Wrap_alloc<std::allocator<unsigned short> >::allocate+1A (c:\program files (x86)\microsoft visual studio 12.0\vc\include\xmemory0, 848)
STestViewer!std::vector<unsigned short,std::allocator<unsigned short> >::_Reallocate+57 (c:\program files (x86)\microsoft visual studio 12.0\vc\include\vector, 1588)
STestViewer!std::vector<unsigned short,std::allocator<unsigned short> >::_Reserve+5A (c:\program files (x86)\microsoft visual studio 12.0\vc\include\vector, 1619)
TestViewer!std::vector<unsigned short,std::allocator<unsigned short> >::resize+FC (c:\program files (x86)\microsoft visual studio 12.0\vc\include\vector, 1136)
TestViewer!RecordData::Deserialize+52 (c:\src\stcommonlib\stdmodel.cpp, 174)
TestViewer!SensorDrModel::LoadFromFile+21E (c:\src\stcommonlib\stsmodel.cpp, 50)
In other cases the type of object is not obvious from call stack, but since you have source file name and line number what invoked operator new
, you can establish that by looking at the source code.
To summarize what you get with Umdh: