package Ġcom . sk sam uel . co hort . heap Ċ Ċ import Ġcom . sun . management . Hot Spot Diagnostic MX Bean Ċ import Ġjava . lang . management . Management Factory Ċ import Ġjava . nio . file . Files Ċ import Ġjava . nio . file . Paths Ċ import Ġkotlin . io . path . delete IfExists Ċ Ċ private Ġconst Ġval ĠH OT SP OT _ BE AN _ NAME Ġ= Ġ" com . sun . management : type = Hot Spot Diagnostic " Ċ Ċ fun Ġget Heap Dump (): ĠResult < ByteArray > Ġ= Ġrun Catch ing Ġ{ ĊĠ Ġval Ġserver Ġ= ĠManagement Factory . get Platform MBean Server () ĊĠ Ġval Ġmx Bean Ġ= ĠManagement Factory . new Platform MX Bean Proxy ( server , ĠH OT SP OT _ BE AN _ NAME , ĠHot Spot Diagnostic MX Bean :: class . java ) ĊĠ Ġval Ġpath Ġ= ĠPaths . get ("/ tmp / heap dump " Ġ+ ĠSystem . currentTimeMillis () Ġ+ Ġ". h prof ") ĊĠ Ġmx Bean . dump Heap ( path . toString (), Ġtrue ) ĊĠ Ġval Ġdump Ġ= ĠFiles . read All Bytes ( path ) ĊĠ Ġpath . delete IfExists () ĊĠ Ġdump Ċ } Ċ