1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2019,2020 DaiLambda, Inc. <contact@dailambda.jp> *)(* *)(* Permission is hereby granted, free of charge, to any person obtaining a *)(* copy of this software and associated documentation files (the "Software"),*)(* to deal in the Software without restriction, including without limitation *)(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *)(* and/or sell copies of the Software, and to permit persons to whom the *)(* Software is furnished to do so, subject to the following conditions: *)(* *)(* The above copyright notice and this permission notice shall be included *)(* in all copies or substantial portions of the Software. *)(* *)(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*)(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *)(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *)(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*)(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *)(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *)(* DEALINGS IN THE SOFTWARE. *)(* *)(*****************************************************************************)(* Mutable stat *)typet={mutableloaded_nodes:int;mutablewritten_leaves:int;mutablewritten_empty_buds:int;mutablewritten_buds:int;mutablewritten_internals:int;mutablewritten_extenders:int;mutablewritten_big_extenders:int;mutablewritten_links:int;mutablewritten_leaf_sizes:(int,int)Hashtbl.t(* actual leaves written to disk *);mutablecommitted_leaf_sizes:(int,int)Hashtbl.t(* including hashcons'ed leaves *)}letcreate()={loaded_nodes=0;written_leaves=0;written_empty_buds=0;written_buds=0;written_internals=0;written_extenders=0;written_big_extenders=0;written_links=0;written_leaf_sizes=Hashtbl.create0;committed_leaf_sizes=Hashtbl.create0}letppppft=letffmt=Format.fprintfppffmtinf"Loaded nodes : %d@."t.loaded_nodes;f"Written leaves : %d@."t.written_leaves;f"Written empty buds : %d@."t.written_empty_buds;f"Written buds : %d@."t.written_buds;f"Written internals : %d@."t.written_internals;f"Written extenders : %d@."t.written_extenders;f"Written big extenders : %d@."t.written_big_extenders;f"Written links : %d@."t.written_links;f"Written leaf data:@.";letxs=List.sortcompare@@Hashtbl.fold(funkvst->(k,v)::st)t.written_leaf_sizes[]inList.iter(fun(sz,n)->letn'=Hashtbl.findt.committed_leaf_sizesszinifn<>n'thenf"%d : %d (hashcons: x%.2f, saved %.2fMB) @."szn(floatn'/.floatn)(float(sz*(n'-n))/.1000000.0)elsef"%d : %d@."szn)xsletincr_loaded_nodest=t.loaded_nodes<-t.loaded_nodes+1letincr_written_leavest=t.written_leaves<-t.written_leaves+1letincr_written_empty_budst=t.written_empty_buds<-t.written_empty_buds+1letincr_written_budst=t.written_buds<-t.written_buds+1letincr_written_internalst=t.written_internals<-t.written_internals+1letincr_written_extenderst=t.written_extenders<-t.written_extenders+1letincr_written_big_extenderst=t.written_big_extenders<-t.written_big_extenders+1letincr_written_linkst=t.written_links<-t.written_links+1letincr_written_leaf_sizests=lettbl=t.written_leaf_sizesinmatchHashtbl.find_opttblswith|None->Hashtbl.addtbls1|Somex->Hashtbl.replacetbls(x+1)letincr_committed_leaf_sizests=lettbl=t.committed_leaf_sizesinmatchHashtbl.find_opttblswith|None->Hashtbl.addtbls1|Somex->Hashtbl.replacetbls(x+1)