1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859(****************************************************************************)(* *)(* This file is part of MOPSA, a Modular Open Platform for Static Analysis. *)(* *)(* Copyright (C) 2017-2019 The MOPSA Project. *)(* *)(* This program is free software: you can redistribute it and/or modify *)(* it under the terms of the GNU Lesser General Public License as published *)(* by the Free Software Foundation, either version 3 of the License, or *)(* (at your option) any later version. *)(* *)(* This program is distributed in the hope that it will be useful, *)(* but WITHOUT ANY WARRANTY; without even the implied warranty of *)(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *)(* GNU Lesser General Public License for more details. *)(* *)(* You should have received a copy of the GNU Lesser General Public License *)(* along with this program. If not, see <http://www.gnu.org/licenses/>. *)(* *)(****************************************************************************)(** Hook for displaying analysis logs as a tree *)openMopsaopenFormatopenCore.AllmoduleHook=struct(** {2 Hook header} *)(** *************** *)letname="gctest"letinitctx=()leton_before_execroutestmtmanflow=()leton_after_execroutestmtmanflowpost=()leton_before_evalroutesemanticexpmanflow=()leton_after_evalroutesemanticexpmanflowevl=()leton_finishmanflow=letalladdr=ask_and_reduceman.askQ_allocated_addressesflowinletreachaddr=Heap.Recency.Pool.elements@@ask_and_reduceman.askHeap.Recency.Q_alive_addresses_aspsetflowinletlall=List.lengthalladdrinletlreach=List.lengthreachaddrinFormat.printf"[GCTEST] reach/all = %d / %d = %f@.unreachables = @[@.%a@]@."lreachlall(iflall=0then0.elsefloat_of_intlreach/.float_of_intlall)(Format.pp_print_list~pp_sep:(funfmt()->Format.fprintffmt"@.")pp_addr)(List.filter(funa->not@@List.memareachaddr)alladdr);Format.printf"Total gc time : %.3f@.Avg # collected addr: %d@.Max heap size: %d@."!Heap.Recency.gc_time(if!Heap.Recency.gc_nb_collections=0then0else!Heap.Recency.gc_nb_addr_collected/!Heap.Recency.gc_nb_collections)!Heap.Recency.gc_max_heap_sizeendlet()=Core.Hook.register_stateless_hook(moduleHook)