From fc7f56900f3497708b246882ba63823b4293121c Mon Sep 17 00:00:00 2001 From: Simmo Saan Date: Wed, 23 Feb 2022 11:44:33 +0200 Subject: [PATCH] Extract Hashtbl stats to GobHashtbl module --- src/framework/cfgTools.ml | 9 +-------- src/util/gobHashtbl.ml | 7 +++++++ 2 files changed, 8 insertions(+), 8 deletions(-) create mode 100644 src/util/gobHashtbl.ml diff --git a/src/framework/cfgTools.ml b/src/framework/cfgTools.ml index e6f174d4ade..bbbf827e99e 100644 --- a/src/framework/cfgTools.ml +++ b/src/framework/cfgTools.ml @@ -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); | _ -> () ); diff --git a/src/util/gobHashtbl.ml b/src/util/gobHashtbl.ml new file mode 100644 index 00000000000..a883484ce8c --- /dev/null +++ b/src/util/gobHashtbl.ml @@ -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