how to determine a programs memory usage at runtime?

John Meacham john at repetae.net
Mon Jun 21 04:13:45 EDT 2004


On Mon, Jun 21, 2004 at 05:58:18PM +1000, Bernard James POPE wrote:
> Is there any way I can find out or estimate the memory size
> of a program while it is executing?
> 
> This may very well be problematic and system specific, but 
> I haven't a clue where to look. Perhaps there is a posix
> interface I am missing? Or a hook into the runtime?
> 
> Why do I want to know this?
> 
> I'm experimenting with interleaving the execution of
> buddha's debugging algorithm with the execution of the
> debuggee. Assume for the moment that the debuggee runs
> in one thread and the debugger runs in another.
> 
> One strategy I want to test is running the debuggee until
> some threshold of memory has been used, suspend the
> debuggee and jump to the debugger, then possibly back again.

see the man page for 'getrusage' which should be quite portable and easy
to write an ffi wrapper around. however, be warned that although the
call is portable, not all systems fill in all fields. linux is
particularly bad in the regard (filling in some, but not all fields),
but BSD and Solaris both give detailed stats. (the omitted information
for linux can be gotten from /proc/self/stat*, not sure why they just
don't put it into the getrusage structure too) 

There might be some RTS calls to query the heap, but someone else is
probably more qualified to comment on that.

        John

-- 
John Meacham - ⑆repetae.net⑆john⑈ 


More information about the Glasgow-haskell-users mailing list