Version française
Home     About     Download     Resources     Contact us    
Browse thread
[GC] Evaluate memory use
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: David.Mentre@i...
Subject: [GC] Evaluate memory use
[ short french:

 Comment connaître la consommation mémoire maximum d'un programme OCaml
 ?  ]

Hello all Caml users/hackers,

Is there any way to know the maximum memory used by an OCaml program?
Right now, I'm using Gc.heap_words, but it doesn't seem to be very
accurate. I think because the minor heap words are not counted. Anyway
to fix this? Should I use something like:

    let max_words_total = stats.Gc.minor_words - stats.Gc.promoted_words + stats.Gc.heap_words in


Used code below:

let print_computation_stats elapsed_time =
  let stats = Gc.stat () in
  let max_words_total = stats.Gc.heap_words in
  printf "@\n@[<v 2>##### Statistics #####@\n" ;
  printf "Maximum memory used: %d kBytes@\n" (max_words_total * Sys.word_size
                                             / 8 / 1024) ;
  printf "Processor time used: %f seconds@\n" (Sys.time ()) ;
  printf "Wall clock time used: %f seconds@\n" elapsed_time ;
  printf "@\n" ;
  printf "@]@\n@?"


BTW, is there any simple way to evaluate Wall Clock Time used by an
OCaml program? Right now, I'm using 'Unix.gettimeofday ()'. Is there a
simpler way to do it?

        let start_time = Unix.gettimeofday () in

        let produced_properties = verify properties prog possible_projections in

        let stop_time = Unix.gettimeofday () in

        print_computation_stats (stop_time -. start_time) ;



Best regards,
david
-- 
 David.Mentre@irisa.fr -- http://www.irisa.fr/prive/dmentre/
 Opinions expressed here are only mine.