1 (* Copyright (C) 2004-2005, HELM Team.
3 * This file is part of HELM, an Hypertextual, Electronic
4 * Library of Mathematics, developed at the Computer Science
5 * Department, University of Bologna, Italy.
7 * HELM is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * HELM is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with HELM; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
22 * For details, see the HELM World-Wide-Web page,
23 * http://helm.cs.unibo.it/
28 let conffile = "../../../matita/matita.conf.xml"
30 let _ = CicEnvironment.set_trust (fun _ -> trust);;
31 let _ = Helm_registry.load_from conffile;;
33 let old_total = ref 0.0
34 let new_total = ref 0.0
36 let separator = "============="
38 let perc newt oldt = (newt -. oldt) /. oldt *. 100.0
44 Printf.printf "%s\n" separator;
45 Printf.printf "Total: %.2f\n" !new_total;
46 if !old_total <> 0.0 then
47 Printf.printf "Old: %.2f (%.2f%%)\n" !old_total (perc !new_total !old_total))
50 let timeout = ref false;;
53 Sys.set_signal 14 (* SIGALRM *)
54 (Sys.Signal_handle (fun _ ->
62 with Invalid_argument _ ->
63 prerr_endline "You must supply a file with the list of URIs to check";
66 let ic = open_in urifname
74 let uri = input_line ic in
75 if uri = separator then raise End_of_file;
77 match Str.split (Str.regexp " ") uri with
78 uri::res::time::_ -> uri, Some res, Some (float_of_string time)
79 | [uri;res] -> uri, Some res, None
80 | [ uri ] -> uri, None, None
83 Printf.printf "%s " uri;
85 let uri = UriManager.uri_of_string uri in
86 let obj,_ = CicEnvironment.get_obj CicUniv.empty_ugraph uri in
87 ignore (Unix.alarm deadline);
88 CicTypeChecker.typecheck_obj uri obj;
89 ignore (Unix.alarm 0);
90 CicEnvironment.remove_obj uri;
91 let before = Unix.times () in
92 ignore (Unix.alarm deadline);
93 ignore (CicTypeChecker.typecheck_obj uri obj);
94 ignore (Unix.alarm 0);
95 let memusage = (Gc.stat ()).Gc.live_words * 4 / 1024 / 1024 in
96 if memusage > 500 then
98 prerr_endline ("MEMORIA ALLOCATA: " ^ string_of_int memusage ^ "Mb");
99 CicEnvironment.empty ();
101 let memusage = (Gc.stat ()).Gc.live_words * 4 / 1024 / 1024 in
102 prerr_endline ("DOPO CicEnvironment.empty: " ^ string_of_int memusage ^ "Mb");
104 let after = Unix.times () in
105 let diff = after.Unix.tms_utime +. after.Unix.tms_stime -. before.Unix.tms_utime -. before.Unix.tms_stime in
106 new_total := !new_total +. diff;
107 Printf.printf "
\e[0;32mOK
\e[0m %.2f" diff;
109 None -> Printf.printf "\n"
111 old_total := !old_total +. time;
112 Printf.printf " %.2f%%\n" (perc diff time))
114 | End_of_file as exn -> raise exn
116 let rec skip_break prompt =
120 Printf.printf "
\e[0;31mSKIPPED
\e[0m\n";
124 Printf.eprintf "
\e[0;31mContinue with next URI? [y/_]
\e[0m";
129 (match input_line stdin with
135 Sys.Break -> skip_break false
138 | CicEnvironment.CircularDependency _ ->
139 Printf.printf "
\e[0;31mCIRCULARDEP
\e[0m\n"
141 Printf.printf "
\e[0;31mFAIL
\e[0m\n";
145 CicTypeChecker.TypeCheckerFailure msg ->
146 "TypeCheckerFailure: " ^ Lazy.force msg
147 | CicTypeChecker.AssertFailure msg ->
148 "TypeCheckerAssertion: " ^ Lazy.force msg
149 | _ -> Printexc.to_string exn)