1010module IdSet = Set. Make (Uid )
1111module IdMap = Map. Make (Uid )
1212
13+ module Uid_pretty = struct
14+ let gen = ref 0
15+ let cache = ref IdMap. empty
16+
17+ let find t =
18+ match IdMap. find t ! cache with
19+ | i -> i
20+ | exception Not_found ->
21+ let i = ! gen in
22+ incr gen ;
23+ cache := IdMap. add t i ! cache ;
24+ i
25+
26+ let to_string = function
27+ | [] -> " _"
28+ | t ->
29+ let i = find t in
30+ if i > = 0 && i < 26
31+ then String. make 1 (Char. chr (Char. code 'A' + i))
32+ else string_of_int i
33+ end
34+
1335type 'a t = 'a Atomic .t * Uid .t
1436
1537type _ Effect.t + =
@@ -190,12 +212,37 @@ type state_cell = {
190212 mutable backtrack : proc_rec list IdMap .t ;
191213}
192214
215+ let group_by fn = function
216+ | [] -> []
217+ | first :: rest ->
218+ let rec go previous previouses = function
219+ | [] -> [previous::previouses]
220+ | x ::xs when fn x previous -> go x (previous::previouses) xs
221+ | x ::xs -> (previous::previouses) :: go x [] xs
222+ in
223+ List. rev (go first [] rest)
224+
225+ let pretty_print h lst =
226+ List. iter
227+ (function
228+ | steps when List. compare_length_with steps 3 < = 0 ->
229+ List. iter (fun step -> Format. fprintf h " %s" (Uid_pretty. to_string step.proc_id)) steps
230+ | (step :: _ ) as steps ->
231+ Format. fprintf h " (%s%i)" (Uid_pretty. to_string step.proc_id) (List. length steps)
232+ | _ -> assert false )
233+ (group_by (fun a b -> a.proc_id = b.proc_id) lst)
234+
235+ let clear_line = " \027 [2K\r "
236+
193237let num_runs = ref 0
194238
195239(* we stash the current state in case a check fails and we need to log it *)
196240let schedule_for_checks = ref []
197241
198242let setup_run func init_schedule =
243+ num_runs := ! num_runs + 1 ;
244+ if ! num_runs mod 1000 == 0 then
245+ Format. printf " %srun: %#i %a %!" clear_line ! num_runs pretty_print ! schedule_for_checks;
199246 processes := IdMap. empty ;
200247 finished_processes := 0 ;
201248 schedule_for_checks := init_schedule;
@@ -204,10 +251,7 @@ let setup_run func init_schedule =
204251 let fiber_f h = continue_with (fiber func) () h in
205252 push_process
206253 { uid; generator = 0 ; next_op = Start ; next_repr = None ; resume_func = fiber_f; finished = false } ;
207- tracing := false ;
208- num_runs := ! num_runs + 1 ;
209- if ! num_runs mod 1000 == 0 then
210- Format. printf " run: %d@." ! num_runs
254+ tracing := false
211255
212256let do_run init_schedule =
213257 let trace = ref [] in
@@ -406,4 +450,4 @@ let trace func =
406450let trace func =
407451 Fun. protect
408452 (fun () -> trace func)
409- ~finally: (fun () -> Format. printf " @.Finished after %i runs.@." ! num_runs)
453+ ~finally: (fun () -> Format. printf " @.Finished after %# i runs.@." ! num_runs)
0 commit comments