mirror of
https://github.com/c-cube/sidekick.git
synced 2025-12-09 12:45:48 -05:00
feat: use gc alarm to check resources
This commit is contained in:
parent
26b4f677e0
commit
8614d9bb0c
1 changed files with 12 additions and 0 deletions
|
|
@ -90,6 +90,16 @@ let syntax_of_file file =
|
||||||
if CCString.suffix ~suf:".cnf" file then Dimacs
|
if CCString.suffix ~suf:".cnf" file then Dimacs
|
||||||
else Smtlib
|
else Smtlib
|
||||||
|
|
||||||
|
(* Limits alarm *)
|
||||||
|
let check_limits () =
|
||||||
|
let t = Sys.time () in
|
||||||
|
let heap_size = (Gc.quick_stat ()).Gc.heap_words in
|
||||||
|
let s = float heap_size *. float Sys.word_size /. 8. in
|
||||||
|
if t > !time_limit then
|
||||||
|
raise Out_of_time
|
||||||
|
else if s > !size_limit then
|
||||||
|
raise Out_of_space
|
||||||
|
|
||||||
let main () =
|
let main () =
|
||||||
CCFormat.set_color_default true;
|
CCFormat.set_color_default true;
|
||||||
(* Administrative duties *)
|
(* Administrative duties *)
|
||||||
|
|
@ -98,6 +108,7 @@ let main () =
|
||||||
Arg.usage argspec usage;
|
Arg.usage argspec usage;
|
||||||
exit 2
|
exit 2
|
||||||
);
|
);
|
||||||
|
let al = Gc.create_alarm check_limits in
|
||||||
let syn = syntax_of_file !file in
|
let syn = syntax_of_file !file in
|
||||||
Util.setup_gc();
|
Util.setup_gc();
|
||||||
let solver =
|
let solver =
|
||||||
|
|
@ -142,6 +153,7 @@ let main () =
|
||||||
if !p_gc_stat then (
|
if !p_gc_stat then (
|
||||||
Printf.printf "(gc_stats\n%t)\n" Gc.print_stat;
|
Printf.printf "(gc_stats\n%t)\n" Gc.print_stat;
|
||||||
);
|
);
|
||||||
|
Gc.delete_alarm al;
|
||||||
res
|
res
|
||||||
|
|
||||||
let () = match main() with
|
let () = match main() with
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue