1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374(*
* Copyright (C) 2016-present David Scott <dave.scott@docker.com>
* Copyright (c) 2011-present Anil Madhavapeddy <anil@recoil.org>
* Copyright (c) 2013-present Thomas Gazagnaire <thomas@gazagnaire.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*)typewrite_error=[`Closed]letpp_write_errorppf=function|`Closed->Fmt.pfppf"attempted to write to a closed flow"type'aor_eof=[`Dataof'a|`Eof]letpp_or_eofdppf=function|`Dataa->dppfa|`Eof->Fmt.stringppf"End-of-file"moduletypeS=sigtypeerrorvalpp_error:errorFmt.ttypenonrecwrite_error=private[>write_error]valpp_write_error:write_errorFmt.ttypeflowvalread:flow->(Cstruct.tor_eof,error)resultLwt.tvalwrite:flow->Cstruct.t->(unit,write_error)resultLwt.tvalwritev:flow->Cstruct.tlist->(unit,write_error)resultLwt.tvalclose:flow->unitLwt.tendtypestats={read_bytes:int64;read_ops:int64;write_bytes:int64;write_ops:int64;duration:int64;}letkib=1024Llet(**)=Int64.mulletmib=kib**1024Lletgib=mib**1024Llettib=gib**1024Lletsuffix=[kib,"KiB";mib,"MiB";gib,"GiB";tib,"TiB";]letadd_suffixx=List.fold_left(funacc(y,label)->ifInt64.divxy>0LthenPrintf.sprintf"%.1f %s"Int64.((to_floatx)/.(to_floaty))labelelseacc)(Printf.sprintf"%Ld bytes"x)suffixletpp_statsppfs=Fmt.pfppf"%s bytes at %s/nanosec and %Lu IOPS/nanosec"(add_suffixs.read_bytes)(add_suffixInt64.(divs.read_bytess.duration))(Int64.divs.read_opss.duration)