Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Sylvain Le Gall <sylvain@le-gall.net>
To: caml-list@inria.fr
Subject: Re: memory profiling
Date: Tue, 5 May 2009 14:39:21 +0000 (UTC)	[thread overview]
Message-ID: <slrnh00jsp.e8q.sylvain@gallu.homelinux.org> (raw)
In-Reply-To: <BB046CA812535C45BD0029AA9D04BA79063ECF28@KL-SRV57.lmsintl.com>

Hello,

On 05-05-2009, Christoph Bauer <christoph.bauer@lmsintl.com> wrote:
> Hi,
>
> what is the best option to do memory profiling with ocaml?
> Is there a patch of ocaml-memprof for 3.11.0? What about
> objsize?
>

I use a more simple approach (though I have used objsize to estimate
some datastructure size, but only in the toplevel): GC allocation rate.

You can override a little ocaml-benchmark to measure the allocation rate
of the GC. This gives you a pretty good understanding on the fact you
are allocating too much or not.

Regards,
Sylvain Le Gall

ps: here is a part of my benchmarkExt.ml file


(** Benchmark extension
    @author Sylvain Le Gall
  *)

open Benchmark;;

type t =
    {
      benchmark: Benchmark.t;
      memory_used: float;
    }
;;

let gc_wrap f x =
  (* Extend sample to add GC stat *)
  let add_gc_stat memory_used samples =
    List.map 
      (fun (name, lst) ->
         name,
         List.map 
           (fun bt -> 
              { 
                benchmark = bt; 
                memory_used = memory_used;
              }
           )
           lst
      )
      samples
  in

  (* Call throughput1 and add GC stat *)
  let () = 
    print_string "Cleaning memory before benchmark"; print_newline ();    
    Gc.full_major ()
  in
  let allocated_before = 
    Gc.allocated_bytes ()
  in
  let samples =
    f x
  in
  let () = 
    print_string "Cleaning memory after benchmark"; print_newline ();
    Gc.full_major ()
  in
  let memory_used = 
    ((Gc.allocated_bytes ()) -. allocated_before) 
  in
    add_gc_stat memory_used samples
;;

let throughput1
      ?min_count ?style
      ?fwidth    ?fdigits
      ?repeat    ?name
      seconds 
      f x =
 
  (* Benchmark throughput1 as it should be called *) 
  gc_wrap 
    (throughput1
       ?min_count ?style
       ?fwidth    ?fdigits
       ?repeat    ?name
       seconds f) x
;;

let throughputN 
      ?min_count ?style
      ?fwidth    ?fdigits
      ?repeat    
      seconds name_f_args =
  List.flatten
    (List.map
       (fun (name, f, args) ->
         throughput1 
           ?min_count ?style
           ?fwidth    ?fdigits
           ?repeat    ~name:name
           seconds f args)
       name_f_args)
;;

let latency1 
      ?min_cpu ?style 
      ?fwidth  ?fdigits 
      ?repeat  n 
      ?name    f x =
  gc_wrap 
    (latency1
      ?min_cpu ?style 
      ?fwidth  ?fdigits 
      ?repeat  n 
      ?name    f) x
;;

let latencyN 
      ?min_cpu ?style 
      ?fwidth  ?fdigits 
      ?repeat  
      n name_f_args =
  List.flatten
    (List.map
       (fun (name, f, args) ->
         latency1 
           ?min_cpu   ?style
           ?fwidth    ?fdigits
           ?repeat    ~name:name
           n          f args)
       name_f_args)
;;


  parent reply	other threads:[~2009-05-05 14:39 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-05 12:14 Christoph Bauer
2009-05-05 12:45 ` [Caml-list] " dmitry grebeniuk
2010-01-09 13:25   ` Jon Harrop
2010-01-09 12:40     ` Richard Jones
2009-05-05 14:39 ` Sylvain Le Gall [this message]
2009-05-05 15:17   ` [Caml-list] " Jon Harrop

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=slrnh00jsp.e8q.sylvain@gallu.homelinux.org \
    --to=sylvain@le-gall.net \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox