caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Determining memory usage?
@ 2005-02-13  2:29 Erik de Castro Lopo
  2005-02-13  8:31 ` [Caml-list] " Remi Vanicat
  0 siblings, 1 reply; 8+ messages in thread
From: Erik de Castro Lopo @ 2005-02-13  2:29 UTC (permalink / raw)
  To: caml-list

Hi all,

I was wondering if there was a way of finding the maximum memory 
usage of a program compiled with ocamlopt. Preferably I'd like
to print that memory usage out at the end of a run of my program.


TIA,
Erik
-- 
+-----------------------------------------------------------+
  Erik de Castro Lopo  nospam@mega-nerd.com (Yes it's valid)
+-----------------------------------------------------------+
The main confusion about C++ is that its practitioners think
it is simultaneously a  high and low level language when in
reality it is good at neither.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Caml-list] Determining memory usage?
  2005-02-13  2:29 Determining memory usage? Erik de Castro Lopo
@ 2005-02-13  8:31 ` Remi Vanicat
  2005-02-14  1:46   ` Erik de Castro Lopo
  0 siblings, 1 reply; 8+ messages in thread
From: Remi Vanicat @ 2005-02-13  8:31 UTC (permalink / raw)
  To: caml-list

On Sun, 13 Feb 2005 13:29:39 +1100, Erik de Castro Lopo
<ocaml-erikd@mega-nerd.com> wrote:
> Hi all,
> 
> I was wondering if there was a way of finding the maximum memory
> usage of a program compiled with ocamlopt. Preferably I'd like
> to print that memory usage out at the end of a run of my program.
> 

Then you have to look to the Gc module of the stdlib, in particular
the Gc.stat function


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Caml-list] Determining memory usage?
  2005-02-13  8:31 ` [Caml-list] " Remi Vanicat
@ 2005-02-14  1:46   ` Erik de Castro Lopo
  2005-02-14  2:05     ` William Lovas
                       ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Erik de Castro Lopo @ 2005-02-14  1:46 UTC (permalink / raw)
  To: caml-list

On Sun, 13 Feb 2005 09:31:48 +0100
Remi Vanicat <remi.vanicat@gmail.com> wrote:

> Then you have to look to the Gc module of the stdlib, in particular
> the Gc.stat function

Thanks Remi, the heap_words field of the stat record seems to be
what I want. However sicne that field is in words, I'm looking
for a way to figure out the word_size (4 vs 8 bytes) so I can
do a calculation that is correct on 32 and 64 but systems.

Any further clues?

TIA,
Erik
-- 
+-----------------------------------------------------------+
  Erik de Castro Lopo  nospam@mega-nerd.com (Yes it's valid)
+-----------------------------------------------------------+
"life is too long to know C++ well" -- Erik Naggum


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Caml-list] Determining memory usage?
  2005-02-14  1:46   ` Erik de Castro Lopo
@ 2005-02-14  2:05     ` William Lovas
  2005-02-14  7:03       ` Erik de Castro Lopo
  2005-02-14  2:09     ` William D.Neumann
  2005-02-14  2:20     ` Jon Harrop
  2 siblings, 1 reply; 8+ messages in thread
From: William Lovas @ 2005-02-14  2:05 UTC (permalink / raw)
  To: caml-list

On Mon, Feb 14, 2005 at 12:46:50PM +1100, Erik de Castro Lopo wrote:
> Thanks Remi, the heap_words field of the stat record seems to be
> what I want. However sicne that field is in words, I'm looking
> for a way to figure out the word_size (4 vs 8 bytes) so I can
> do a calculation that is correct on 32 and 64 but systems.
> 
> Any further clues?

How about the strikingly appropriately named Sys.word_size? :)

cheers,
William


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Caml-list] Determining memory usage?
  2005-02-14  1:46   ` Erik de Castro Lopo
  2005-02-14  2:05     ` William Lovas
@ 2005-02-14  2:09     ` William D.Neumann
  2005-02-14  2:20     ` Jon Harrop
  2 siblings, 0 replies; 8+ messages in thread
From: William D.Neumann @ 2005-02-14  2:09 UTC (permalink / raw)
  To: Erik de Castro Lopo; +Cc: caml-list

On Feb 13, 2005, at 6:46 PM, Erik de Castro Lopo wrote:

> I'm looking
> for a way to figure out the word_size (4 vs 8 bytes) so I can
> do a calculation that is correct on 32 and 64 but systems.

Sys.word_size

William D. Neumann

"You've got Rita Marlowe in the palm of your hand."
"Palm of my hand?  You haven't seen Rita Marlowe..."

		-- Will Success Spoil Rock Hunter?


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Caml-list] Determining memory usage?
  2005-02-14  1:46   ` Erik de Castro Lopo
  2005-02-14  2:05     ` William Lovas
  2005-02-14  2:09     ` William D.Neumann
@ 2005-02-14  2:20     ` Jon Harrop
  2 siblings, 0 replies; 8+ messages in thread
From: Jon Harrop @ 2005-02-14  2:20 UTC (permalink / raw)
  To: caml-list

On Monday 14 February 2005 01:46, Erik de Castro Lopo wrote:
> Remi Vanicat <remi.vanicat@gmail.com> wrote:
> > Then you have to look to the Gc module of the stdlib, in particular
> > the Gc.stat function
>
> Thanks Remi, the heap_words field of the stat record seems to be
> what I want. However sicne that field is in words, I'm looking
> for a way to figure out the word_size (4 vs 8 bytes) so I can
> do a calculation that is correct on 32 and 64 but systems.
>
> Any further clues?

You'll be wanting Sys.word_size:

"Size of one word on the machine currently executing the Caml program, in 
bits: 32 or 64."

:-)

-- 
Dr Jon D Harrop, Flying Frog Consultancy Ltd.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Caml-list] Determining memory usage?
  2005-02-14  2:05     ` William Lovas
@ 2005-02-14  7:03       ` Erik de Castro Lopo
  2005-02-16 15:06         ` Damien Doligez
  0 siblings, 1 reply; 8+ messages in thread
From: Erik de Castro Lopo @ 2005-02-14  7:03 UTC (permalink / raw)
  To: caml-list

On Sun, 13 Feb 2005 21:05:10 -0500
William Lovas <wlovas@stwing.upenn.edu> wrote:

> How about the strikingly appropriately named Sys.word_size? :)

Yep, thats a winner. Thanks.

For the archive, I now have:

   let x = Gc.stat () in
   printf "Memory used : %d kb\n\n" (x.heap_words / (1024 / (Sys.word_size / 8))) ;;

which gives what seems to be a sensible result.

Erik
-- 
+-----------------------------------------------------------+
  Erik de Castro Lopo  nospam@mega-nerd.com (Yes it's valid)
+-----------------------------------------------------------+
"The object-oriented model makes it easy to build up programs by
accretion. What this often means, in practice, is that it provides
a structured way to write spaghetti code." -- Paul Graham


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Caml-list] Determining memory usage?
  2005-02-14  7:03       ` Erik de Castro Lopo
@ 2005-02-16 15:06         ` Damien Doligez
  0 siblings, 0 replies; 8+ messages in thread
From: Damien Doligez @ 2005-02-16 15:06 UTC (permalink / raw)
  To: caml-list

On Feb 14, 2005, at 08:03, Erik de Castro Lopo wrote:

> For the archive, I now have:
>
>    let x = Gc.stat () in
>    printf "Memory used : %d kb\n\n" (x.heap_words / (1024 / 
> (Sys.word_size / 8))) ;;

I think you'll want to use top_heap_words instead of heap_words.

-- Damien


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2005-02-16 15:06 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-02-13  2:29 Determining memory usage? Erik de Castro Lopo
2005-02-13  8:31 ` [Caml-list] " Remi Vanicat
2005-02-14  1:46   ` Erik de Castro Lopo
2005-02-14  2:05     ` William Lovas
2005-02-14  7:03       ` Erik de Castro Lopo
2005-02-16 15:06         ` Damien Doligez
2005-02-14  2:09     ` William D.Neumann
2005-02-14  2:20     ` Jon Harrop

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).