123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172(*****************************************************************************
Copyright 2022 Savonet team
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 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 General Public License for more details, fully stated in the COPYING
file at the root of the liquidsoap distribution.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*****************************************************************************)typet={total_virtual_memory:int;total_physical_memory:int;total_used_virtual_memory:int;total_used_physical_memory:int;process_virtual_memory:int;process_physical_memory:int;}externalinfo:unit->t="ocaml_mem_usage_mem_usage"letbyte_units=["B";"kB";"MB";"GB";"TB";"PB";"EB";"ZB";"YB"]letbibyte_units=["B";"kiB";"MiB";"GiB";"TiB";"PiB";"EiB";"ZiB";"YiB"]letbit_units=["b";"kbit";"Mbit";"Gbit";"Tbit";"Pbit";"Ebit";"Zbit";"Ybit"]letbibit_units=["b";"kibit";"Mibit";"Gibit";"Tibit";"Pibit";"Eibit";"Zibit";"Yibit"]letprettify_bytes?(float_printer=Printf.sprintf"%.02f")?(signed=false)?(bits=false)?(binary=false)bytes=letunits=match(bits,binary)with|true,true->bibit_units|true,false->bit_units|false,true->bibyte_units|false,false->byte_unitsinletprefix,bytes=ifbytes<0then("-",-bytes)else((ifsignedthen"+"else""),bytes)inifbytes=0thenPrintf.sprintf"%s0 %s"prefix(List.hdunits)else(letexponent=Float.floor(ifbinarythenlog(floatbytes)/.log1024.elselog10(floatbytes)/.3.)inletunit_index=ifList.lengthunits-1<int_of_floatexponentthenList.lengthunits-1elseint_of_floatexponentinletbytes=floatbytes/.Float.pow(ifbinarythen1024.else1000.)exponentinPrintf.sprintf"%s%s %s"prefix(float_printerbytes)(List.nthunitsunit_index))