Skip to content

Commit 8cf65e8

Browse files
committed
prettier trace
1 parent 5375983 commit 8cf65e8

File tree

1 file changed

+27
-23
lines changed

1 file changed

+27
-23
lines changed

src/tracedAtomic.ml

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,6 @@ let atomic_op_equal a b = match a, b with
4444
| CompareAndSwap _, CompareAndSwap _ -> true
4545
| _ -> a = b
4646

47-
let atomic_op_str x =
48-
match x with
49-
| Start -> "start"
50-
| Make -> "make"
51-
| Get -> "get"
52-
| Set -> "set"
53-
| Exchange -> "exchange"
54-
| FetchAndAdd -> "fetch_and_add"
55-
| Spawn -> "spawn"
56-
| CompareAndSwap cas ->
57-
begin match !cas with
58-
| Unknown -> "compare_and_swap?"
59-
| Success -> "compare_and_swap"
60-
| Failed -> "compare_and_no_swap"
61-
end
62-
6347
let tracing = ref false
6448

6549
let finished_processes = ref 0
@@ -201,11 +185,32 @@ type state_cell = {
201185
module Step = struct
202186
type t = proc_rec
203187
let compare a b = Uid.compare a.proc_id b.proc_id
188+
189+
let atomic_op_str op arg =
190+
let arg = match op, arg with
191+
| _, None -> "?"
192+
| Spawn, Some domain_id -> Uid.pretty domain_id
193+
| _, Some ptr -> Uid.to_string ptr
194+
in
195+
match op with
196+
| Start -> "start"
197+
| Spawn -> "spawn() = " ^ arg
198+
| Make -> "make() = " ^ arg
199+
| Get -> "get(" ^ arg ^ ")"
200+
| Set -> "set(" ^ arg ^ ")"
201+
| Exchange -> "exchange(" ^ arg ^ ")"
202+
| FetchAndAdd -> "fetch_and_add(" ^ arg ^ ")"
203+
| CompareAndSwap cas ->
204+
begin match !cas with
205+
| Unknown -> "compare_and_swap(" ^ arg ^ ")"
206+
| Success -> "compare_and_swap(" ^ arg ^ ")"
207+
| Failed -> "compare_and_no_swap(" ^ arg ^ ")"
208+
end
209+
204210
let to_string t =
205-
Printf.sprintf "%s %s(%s)"
211+
Printf.sprintf "%s %s"
206212
(Uid.pretty t.proc_id)
207-
(atomic_op_str t.op)
208-
(Option.value (Option.map Uid.to_string t.obj_ptr) ~default:"")
213+
(atomic_op_str t.op t.obj_ptr)
209214
end
210215

211216
module T = Trie.Make (Step)
@@ -252,10 +257,9 @@ let print_stats trie =
252257
Format.printf "%!"
253258

254259
let print_trace () =
255-
List.iter (fun { proc_id ; op ; obj_ptr } ->
256-
let last_run_ptr = Option.map Uid.to_string obj_ptr |> Option.value ~default:"" in
257-
Format.printf " Process %s: %s %s@." (Uid.pretty proc_id) (atomic_op_str op) last_run_ptr
258-
) (List.rev !schedule_for_checks)
260+
List.iter
261+
(fun step -> Format.printf " %s@." (Step.to_string step))
262+
(List.rev !schedule_for_checks)
259263

260264

261265
let setup_run func init_schedule trie =

0 commit comments

Comments
 (0)