Skip to content

Commit

Permalink
Extract Hashtbl stats to GobHashtbl module
Browse files Browse the repository at this point in the history
  • Loading branch information
sim642 committed Feb 23, 2022
1 parent e0faa22 commit fc7f569
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
9 changes: 1 addition & 8 deletions src/framework/cfgTools.ml
Original file line number Diff line number Diff line change
Expand Up @@ -483,14 +483,7 @@ let createCFG (file: file) =
if not (NH.mem reachable_return' (FunctionEntry fd)) then
raise (Not_connect fd);

let module NH2 = Hashtbl.Make (Node) in
let stats (h: 'a NH.t) =
let h': 'a NH2.t = Obj.magic h in
let s = NH2.stats h' in
Format.eprintf "stats: bindings=%d buckets=%d max_length=%d histo=%a load=%f\n" s.num_bindings s.num_buckets s.max_bucket_length (Format.pp_print_list ~pp_sep:(fun f () -> Format.pp_print_char f ',') Format.pp_print_int) (Array.to_list s.bucket_histogram) (float_of_int s.num_bindings /. float_of_int s.num_buckets);
in
stats cfgF;
stats cfgB;
ignore (Pretty.eprintf "%a: cfgF (%a), cfgB (%a)\n" CilType.Fundec.pretty fd GobHashtbl.pretty_statistics (GobHashtbl.magic_stats cfgF) GobHashtbl.pretty_statistics (GobHashtbl.magic_stats cfgB));
FH.replace cfgs fd (cfgF, cfgB);
| _ -> ()
);
Expand Down
7 changes: 7 additions & 0 deletions src/util/gobHashtbl.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
let magic_stats h =
let h: _ Hashtbl.t = Obj.magic h in (* Batteries Hashtables don't expose stats... *)
Hashtbl.stats h

let pretty_statistics () (s: Hashtbl.statistics) =
let load_factor = float_of_int s.num_bindings /. float_of_int s.num_buckets in
Pretty.dprintf "bindings=%d buckets=%d max_length=%d histo=%a load=%f" s.num_bindings s.num_buckets s.max_bucket_length (Pretty.docList (Pretty.dprintf "%d")) (Array.to_list s.bucket_histogram) load_factor

0 comments on commit fc7f569

Please sign in to comment.