From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id D5036BBAF for ; Fri, 12 Nov 2010 22:54:40 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AioCAAtG3UzRVaE0kGdsb2JhbACUVo13CBUBAQEBCQkMBxEDH6RJiWCCGIUdLohZAQEDBYVFBIpXg3I X-IronPort-AV: E=Sophos;i="4.59,189,1288566000"; d="scan'208";a="78502099" Received: from mail-fx0-f52.google.com ([209.85.161.52]) by mail2-smtp-roc.national.inria.fr with ESMTP; 12 Nov 2010 22:54:40 +0100 Received: by fxm15 with SMTP id 15so1397789fxm.39 for ; Fri, 12 Nov 2010 13:54:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:date:from:to:subject :message-id:in-reply-to:references:x-mailer:mime-version :content-type:content-transfer-encoding; bh=kXIELJ2S0DJr/LCuBAERUuBTjty8lQrOlHtJKiz8DQs=; b=pqI415VT2m6ermssiAfqoSf5Qewob6t+BgqAMzZVQ/70OPaRkyunLv3oJmyBPbZ8Pc 6lfDPFqGursn7Pbf360oPSIgiGJHjRizMN5YRfaI8y1gpdOnb/eXOUugiCzgBrEOCxnf EDOYDo7bdfSr44FkpMrWKfGJoeNxGeHVeFeU8= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:from:to:subject:message-id:in-reply-to:references:x-mailer :mime-version:content-type:content-transfer-encoding; b=SCX4IHN6BD7AZ7lo8RRJlI9DNm0iizC6F0/EJxk7iW0yPwFKmYx8oYZluVd5/Ajruj WgDMPOrvKc0emEbgJJtmE/oMc6NAI5V5LCkxigRpHaNRNGB9sVWdVoQk89ZOhVvK9m/W psdvKgiwt7HuRViGZVxyJ9M413VbDsBrS+3Ns= Received: by 10.223.125.132 with SMTP id y4mr2005879far.148.1289598879172; Fri, 12 Nov 2010 13:54:39 -0800 (PST) Received: from lemon.local (0-166-133-95.pool.ukrtel.net [95.133.166.0]) by mx.google.com with ESMTPS id r24sm186577fax.3.2010.11.12.13.54.35 (version=TLSv1/SSLv3 cipher=RC4-MD5); Fri, 12 Nov 2010 13:54:37 -0800 (PST) Date: Fri, 12 Nov 2010 23:54:30 +0200 From: ygrek To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Average cost of the OCaml GC Message-Id: <20101112235430.288f415b.ygrekheretix@gmail.com> In-Reply-To: References: <87bp5w1b47.fsf@frosties.localnet> <8739r78vsq.fsf@frosties.localnet> X-Mailer: Sylpheed 3.0.2 (GTK+ 2.20.1; i486-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; ocaml:01 printf:01 sprintf:01 sprintf:01 compactions:01 compactions:01 eprintf:01 ocamlfind:01 ocamlopt:01 -linkpkg:01 -package:01 zhao:98 wrote:01 upenn:01 heap:01 On Fri, 12 Nov 2010 12:27:40 -0500 Jianzhou Zhao wrote: > Do we still have other methods to debug such problems? Is it possible > to know when and where GC runs, say, the number of times GC works > after a particular usr-defined function? If this is possible, I was > wondering if we can see which function in my code behave wrong. Below is straghtforward "GC diffing" code which helps me to pinpoint excessive GC (like the ExtLib.String.nsplit in example). $ cat a.ml open Printf open Gc let bytes_string_f f = (* oh ugly *) let a = abs_float f in if a < 1024. then sprintf "%dB" (int_of_float f) else if a < 1024. *. 1024. then sprintf "%dKB" (int_of_float (f /. 1024.)) else if a < 1024. *. 1024. *. 1024. then sprintf "%.1fMB" (f /. 1024. /. 1024.) else sprintf "%.1fGB" (f /. 1024. /. 1024. /. 1024.) let bytes_string x = bytes_string_f (float_of_int x) let caml_words_f f = bytes_string_f (f *. (float_of_int (Sys.word_size / 8))) let caml_words x = caml_words_f (float_of_int x) let gc_diff st1 st2 = let allocated st = st.minor_words +. st.major_words -. st.promoted_words in let a = allocated st2 -. allocated st1 in let minor = st2.minor_collections - st1.minor_collections in let major = st2.major_collections - st1.major_collections in let compact = st2.compactions - st1. compactions in let heap = st2.heap_words - st1.heap_words in sprintf "allocated %10s, heap %10s, collection %d %d %d" (caml_words_f a) (caml_words heap) compact major minor let gc_show name f x = let st = Gc.quick_stat () in Std.finally (fun () -> let st2 = Gc.quick_stat () in eprintf "GC DIFF %s : %s\n" name (gc_diff st st2)) f x let () = let _ = gc_show "split" (ExtLib.String.nsplit (String.make 10000 'a')) "a" in gc_show "compact" Gc.compact () $ ocamlfind ocamlopt -linkpkg -package extlib a.ml -o a $ ./a GC DIFF split : allocated 48.1MB, heap 48.0MB, collection 0 21 373 GC DIFF compact : allocated 240B, heap -48.0MB, collection 1 2 0 -- ygrek http://ygrek.org.ua