Skip to content

Commit ea7ee83

Browse files
Merge pull request #1642 from goblint/priv_prec_compare_stats
More useful stats output by `privPrecCompare`
2 parents cc4a935 + 09eaee2 commit ea7ee83

File tree

1 file changed

+46
-2
lines changed

1 file changed

+46
-2
lines changed

src/util/precCompare.ml

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,12 @@ struct
103103

104104
module CompareDump = MakeHashtbl (Key) (Dom) (RH)
105105

106+
let comparisons = ref []
107+
106108
let compare_dumps ({name = name1; results = lvh1}: result) ({name = name2; results = lvh2}: result) =
107-
CompareDump.compare ~verbose:true ~name1 lvh1 ~name2 lvh2
109+
let (c, d) = CompareDump.compare ~verbose:true ~name1 lvh1 ~name2 lvh2 in
110+
comparisons := (name1, name2, c, d) :: !comparisons;
111+
(c, d)
108112

109113
let count_locations (dumps: result list) =
110114
let module LH = Hashtbl.Make (CilType.Location) in
@@ -118,6 +122,45 @@ struct
118122
) dumps;
119123
(LH.length locations, RH.length location_vars)
120124

125+
let group () =
126+
let new_bucket_id = ref 0 in
127+
let equality_buckets = Hashtbl.create 113 in
128+
let sorted = List.sort (fun (n1, _, _, _) (n2, _, _, _) -> String.compare n1 n2) !comparisons in
129+
List.iter (fun (name1, name2, (c:Comparison.t), _) ->
130+
(if not (Hashtbl.mem equality_buckets name1) then
131+
(* Make its own bucket if it does not appear yet *)
132+
(let bucket_id = !new_bucket_id in
133+
incr new_bucket_id;
134+
Hashtbl.add equality_buckets name1 bucket_id));
135+
if c.more_precise = 0 && c.less_precise = 0 && c.incomparable = 0 then
136+
Hashtbl.replace equality_buckets name2 (Hashtbl.find equality_buckets name1)
137+
else
138+
()
139+
) sorted;
140+
let bindings = Hashtbl.bindings equality_buckets in
141+
let buckets = List.group (fun (_, b) (_, b') -> compare b b') bindings in
142+
List.iter (fun bucket ->
143+
Logs.result "Bucket %d:" (snd (List.hd bucket));
144+
List.iter (fun (name, _) -> Logs.result " %s" name) bucket
145+
) buckets;
146+
let comparison_produced = Hashtbl.create 113 in
147+
List.iter (fun (name1, name2, c,d) ->
148+
let bucket1 = Hashtbl.find equality_buckets name1 in
149+
let bucket2 = Hashtbl.find equality_buckets name2 in
150+
if bucket1 = bucket2 then
151+
()
152+
else
153+
begin
154+
let comp_tumple = (min bucket1 bucket2, max bucket1 bucket2) in
155+
if not @@ Hashtbl.mem comparison_produced comp_tumple then
156+
begin
157+
Hashtbl.add comparison_produced comp_tumple ();
158+
Logs.result "Comparison between bucket %d and %d: %t" (fst comp_tumple) (snd comp_tumple) (fun () -> d);
159+
end
160+
end
161+
) sorted;
162+
()
163+
121164
let main () =
122165
Util.init ();
123166
let filenames = List.tl (Array.to_list Sys.argv) in
@@ -131,5 +174,6 @@ struct
131174
|> List.map (uncurry compare_dumps)
132175
|> List.iter (fun (_, msg) -> Logs.result "%t" (fun () -> msg));
133176
Logs.newline ();
134-
Logs.result "Total locations: %d\nTotal %s: %d" locations_count (Key.name ()) location_vars_count
177+
Logs.result "Total locations: %d\nTotal %s: %d" locations_count (Key.name ()) location_vars_count;
178+
group ()
135179
end

0 commit comments

Comments
 (0)