-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbstats.ml
More file actions
122 lines (93 loc) · 3.95 KB
/
bstats.ml
File metadata and controls
122 lines (93 loc) · 3.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
(* Poling: Proof Of Linearizability Generator
* Poling is built on top of CAVE and shares the same license with CAVE
* See LICENSE.txt for license.
* Contact: He Zhu, Department of Computer Science, Purdue University
* Email: zhu103@purdue.edu
*)
(*
*
* Copyright (c) 2001 by
* George C. Necula necula@cs.berkeley.edu
* Scott McPeak smcpeak@cs.berkeley.edu
* Wes Weimer weimer@cs.berkeley.edu
*
* All rights reserved. Permission to use, copy, modify and distribute
* this software for research purposes only is hereby granted,
* provided that the following conditions are met:
* 1. XSRedistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the authors may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* DISCLAIMER:
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*)
(* A hierarchy of timings *)
type t = { name : string;
mutable time : float;
mutable sub : t list}
(* Create the top level *)
let top = { name = "TOTAL";
time = 0.0;
sub = []; }
(* The stack of current path through
* the hierarchy. The first is the
* leaf. *)
let current : t list ref = ref [top]
let reset () = top.sub <- []
let print chn msg =
(* Total up *)
top.time <- List.fold_left (fun sum f -> sum +. f.time) 0.0 top.sub;
let rec prTree ind node =
Printf.fprintf chn "%s%-20s %6.3f s\n"
(String.make ind ' ') node.name node.time ;
List.iter (prTree (ind + 2)) node.sub
in
Printf.fprintf chn "%s" msg;
List.iter (prTree 0) [ top ]
let time str f arg =
(* Find the right stat *)
let stat : t =
let curr = match !current with h :: _ -> h | _ -> assert false in
let rec loop = function
h :: _ when h.name = str -> h
| _ :: rest -> loop rest
| [] ->
let nw = {name = str; time = 0.0; sub = []} in
curr.sub <- nw :: curr.sub;
nw
in
loop curr.sub
in
let oldcurrent = !current in
current := stat :: oldcurrent;
let start = (Unix.times ()).Unix.tms_utime in
let _ = if str == "interp" then Printf.printf "interp start = %6.3f\n" start in
let res =
try (f arg) with
x -> (let finish = Unix.times () in
let diff = finish.Unix.tms_utime -. start in
let _ = if str == "interp" then Printf.printf "interp elapsed = %6.3f\n" diff in
stat.time <- stat.time +. (diff);
current := oldcurrent;
raise x) (* Pop the current stat *)
in
let finish = Unix.times () in
let diff = finish.Unix.tms_utime -. start in
let _ = if str == "interp" then Printf.printf "interp elapsed = %6.3f\n" diff in
stat.time <- stat.time +. (diff);
current := oldcurrent;
res