Haskell API for memory useage

Hi, Haskell has getCPUTime to get the amount of CPU Time that has been consumed, but has no equivalent for memory use. I would like to get something similar to -RTS -t, but from a Haskell program. I'm not overly fussed about what memory statistic I get, as long as it is something that corresponds in some way to the amount of memory that has been used - cells, heap size, live heap etc are all fine. So, I'm after something like: getMemoryUse :: IO Integer Is there anything I can use to do this? Thanks Neil

ndmitchell:
Hi,
Haskell has getCPUTime to get the amount of CPU Time that has been consumed, but has no equivalent for memory use. I would like to get something similar to -RTS -t, but from a Haskell program. I'm not overly fussed about what memory statistic I get, as long as it is something that corresponds in some way to the amount of memory that has been used - cells, heap size, live heap etc are all fine.
So, I'm after something like: getMemoryUse :: IO Integer
Is there anything I can use to do this?
This stuff is surprisingly tricky for some reason. Have a look at the gtop (C?) lib (there's also a perl binding used for the shootout). I'm not sure why shells in general don't provide a 'memory' combinator, considering we have 'time'. -- Don

Hi Donald,
This stuff is surprisingly tricky for some reason. Have a look at the gtop (C?) lib (there's also a perl binding used for the shootout).
I'm not sure why shells in general don't provide a 'memory' combinator, considering we have 'time'.
I don't want to do this in the shell, but if I did "-RTS -t" already dumps it to a file and I can get the answer from there. The example I want is: do x <- getCPUTime compute y <- getCPUTime z <- getMemoryUse print "Your computation took {y-x}ms and {z}kb" Thanks Neil

I once write a little thing called HighWaterMark: http://www.cs.mu.oz.au/~bjpop/code.html It is GHC specific, and it doesn't count memory allocated by foreign stuff (ie C stack etc). I haven't tried it out on a modern GHC, so there is probably some bit rot. Cheers, Bernie.
-----Original Message----- From: glasgow-haskell-users-bounces@haskell.org [mailto:glasgow- haskell-users-bounces@haskell.org] On Behalf Of Neil Mitchell Sent: 10 March 2007 13:49 To: GHC Users Subject: Haskell API for memory useage
Hi,
Haskell has getCPUTime to get the amount of CPU Time that has been consumed, but has no equivalent for memory use. I would like to get something similar to -RTS -t, but from a Haskell program. I'm not overly fussed about what memory statistic I get, as long as it is something that corresponds in some way to the amount of memory that has been used - cells, heap size, live heap etc are all fine.
So, I'm after something like: getMemoryUse :: IO Integer
Is there anything I can use to do this?
Thanks
Neil _______________________________________________ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users

Hi Bernie,
I once write a little thing called HighWaterMark:
http://www.cs.mu.oz.au/~bjpop/code.html
It is GHC specific, and it doesn't count memory allocated by foreign stuff (ie C stack etc).
That's great, a few more things and it would be perfect: * darcs repo * cabal based * working with GHC 6.6 (if it doesn't already) * portable to hugs, just returning Nothing on hugs and Just Integer on GHC is perfect Thanks Neil
participants (3)
-
Bernie Pope
-
dons@cse.unsw.edu.au
-
Neil Mitchell