Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Tool to get size and status of a process's heaps

100 views
Skip to first unread message

Rich Dutton

unread,
Jul 8, 2004, 7:31:45 AM7/8/04
to
Hi,

I have an application with several heaps and would like to be able to
get statistics on each of these as it runs. I believe the right
command for this is !heap, and !heap -s seems to give the kind of
thing I'm after (heap size, size allocated, et cetera), but I'm
wondering if theres a better way to use !heap or a better command or
tool for the task. Specifically, I can't associate the heaps in my
program with the heaps listed by !heap (I was hoping the handles would
match windbg's addresses but this is not the case). I did notice that
the output of !heap does have a Name column, but I have no idea how I
might set this in the code.

Any advice would be appreciated

Rich

Ivan Brugiolo [MSFT]

unread,
Jul 8, 2004, 1:30:17 PM7/8/04
to
What exact kind of statistics would you be looking for ?

If you are looking for the heap creator stack backtrace
you can enable stack backtrace database for your process
c:\debuggers>gflags.exr -i notepad.exe +ust

then, from the output of `!heap -p`

0:004> !heap -p

Active GlobalFlag bits:
hpc - Enable heap parameter checking
ust - Create user mode stack trace database

StackTraceDataBase @ 00090000 of size 00800000 with 000006f8 traces
active heaps:

- 00890000
HEAP_GROWABLE HEAP_TAIL_CHECKING_ENABLED
HEAP_FREE_CHECKING_ENABLED
- 00990000
HEAP_GROWABLE HEAP_TAIL_CHECKING_ENABLED
HEAP_FREE_CHECKING_ENABLED HEAP_CLASS_1
- 009A0000
HEAP_TAIL_CHECKING_ENABLED HEAP_FREE_CHECKING_ENABLED HEAP_CLASS_8
- 00F50000
HEAP_GROWABLE HEAP_TAIL_CHECKING_ENABLED
HEAP_FREE_CHECKING_ENABLED HEAP_CLASS_1
- 00F80000
HEAP_GROWABLE HEAP_TAIL_CHECKING_ENABLED
HEAP_FREE_CHECKING_ENABLED HEAP_CLASS_1
- 00FC0000
HEAP_GROWABLE HEAP_TAIL_CHECKING_ENABLED
HEAP_FREE_CHECKING_ENABLED HEAP_CLASS_1

You can take the heap handle, and the start address and end address of the
stak trace database
and apply the following commands (heap handle 00FC0000 is used as an
example)

0:004> dw 00FC0000+16a l1
00fc016a 0083
0:004> dds poi(00090000+00800000-83*4)
000930d4 00000000
000930d8 00000001
000930dc 00080083
000930e0 77f5714e ntdll!RtlCreateHeap+0x22a
000930e4 77e4de83 kernel32!HeapCreate+0x51
000930e8 7307171b WINSPOOL!bSplLibInit+0x2b
000930ec 7307151b WINSPOOL!DllMain+0x39
000930f0 730714c3 WINSPOOL!_DllMainCRTStartup+0x50
000930f4 77f47dc9 ntdll!LdrpCallInitRoutine+0x14
000930f8 77f54401 ntdll!LdrpRunInitializeRoutines+0x34e
000930fc 77f59cc6 ntdll!LdrpInitializeProcess+0xe23
00093100 0009bfe8

--
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of any included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm


"Rich Dutton" <nottu...@hotmail.com> wrote in message
news:8443ff8b.04070...@posting.google.com...

Reierson@discussions.microsoft.com Kris Reierson

unread,
Jul 12, 2004, 11:45:03 AM7/12/04
to
If you are trying to find out which module/dll owns a particular heap you can use:
" x *!*crtheap*"
this will produce a list of heap handles ( that correlates with the output of !heap ). If the result is "<no type information>" then dd the address:

7803a160 msvcrt!_crtheap = <no type information>
dd 7803a160 l1
7803a160 008b0000

From this you can figure out which module owns a particular heap. This command works best if you have the crt statically linked into each module. If all your modules use the dll version of the crt, they will share the same heap ( unless you manually override it etc etc.)

Finally, this assumes you're using .net to build - some variation of the x command will probably work for vc++ 6.0 and earlier ( I don't remember the exact layout ).

HTH,
Kris

Stephen Kellett

unread,
Jul 13, 2004, 7:06:36 PM7/13/04
to
In message <8443ff8b.04070...@posting.google.com>, Rich
Dutton <nottu...@hotmail.com> writes

>I have an application with several heaps and would like to be able to
>get statistics on each of these as it runs. I believe the right

Memory Validator. 30 day eval.

http://www.softwareverify.com
http://www.softwareverify.com/tutorials.html

Default options don't do Win32 heaps, but changing that is trivial.

Stephen
--
Stephen Kellett
Object Media Limited http://www.objmedia.demon.co.uk
RSI Information: http://www.objmedia.demon.co.uk/rsi.html

0 new messages