1995-11-13 06:25:17 -08:00
|
|
|
(***********************************************************************)
|
|
|
|
(* *)
|
1996-04-30 07:53:58 -07:00
|
|
|
(* Objective Caml *)
|
1995-11-13 06:25:17 -08:00
|
|
|
(* *)
|
|
|
|
(* Damien Doligez and Francois Rouaix, INRIA Rocquencourt *)
|
|
|
|
(* Ported to Caml Special Light by John Malecki and Xavier Leroy *)
|
|
|
|
(* *)
|
1996-04-30 07:53:58 -07:00
|
|
|
(* Copyright 1996 Institut National de Recherche en Informatique et *)
|
1999-11-17 10:59:06 -08:00
|
|
|
(* en Automatique. All rights reserved. This file is distributed *)
|
2001-12-07 05:41:02 -08:00
|
|
|
(* under the terms of the GNU Library General Public License, with *)
|
|
|
|
(* the special exception on linking described in file ../LICENSE. *)
|
1995-11-13 06:25:17 -08:00
|
|
|
(* *)
|
|
|
|
(***********************************************************************)
|
|
|
|
|
|
|
|
(* $Id$ *)
|
|
|
|
|
|
|
|
(* Run-time library for profiled programs *)
|
|
|
|
|
|
|
|
type profiling_counters = (string * (string * int array)) list
|
|
|
|
|
2005-03-24 09:20:54 -08:00
|
|
|
let counters = ref ([] : profiling_counters);;
|
|
|
|
let incr a i = a.(i) <- a.(i) + 1;;
|
1995-11-13 06:25:17 -08:00
|
|
|
|
|
|
|
exception Bad_profile
|
|
|
|
|
|
|
|
let dump_counters () =
|
|
|
|
begin try
|
1996-11-16 07:49:37 -08:00
|
|
|
let ic = open_in_bin "ocamlprof.dump" in
|
1995-11-13 06:25:17 -08:00
|
|
|
let prevl = (input_value ic : profiling_counters) in
|
|
|
|
close_in ic;
|
|
|
|
List.iter2
|
|
|
|
(fun (curname, (curmodes,curcount)) (prevname, (prevmodes,prevcount)) ->
|
|
|
|
if curname <> prevname
|
2000-12-28 05:07:42 -08:00
|
|
|
|| curmodes <> prevmodes
|
|
|
|
|| Array.length curcount <> Array.length prevcount
|
1995-11-13 06:25:17 -08:00
|
|
|
then raise Bad_profile)
|
|
|
|
!counters prevl;
|
|
|
|
List.iter2
|
|
|
|
(fun (curname, (_,curcount)) (prevname, (_,prevcount)) ->
|
|
|
|
for i = 0 to Array.length curcount - 1 do
|
|
|
|
curcount.(i) <- curcount.(i) + prevcount.(i)
|
|
|
|
done)
|
|
|
|
!counters prevl
|
|
|
|
with _ -> ()
|
|
|
|
end;
|
|
|
|
begin try
|
1996-11-16 07:49:37 -08:00
|
|
|
let oc = open_out_bin "ocamlprof.dump" in
|
1995-11-13 06:25:17 -08:00
|
|
|
output_value oc !counters;
|
|
|
|
close_out oc
|
|
|
|
with _ -> ()
|
|
|
|
end
|
|
|
|
|
|
|
|
let _ = at_exit dump_counters
|
|
|
|
|