My working unpac space for OCaml projects in development
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge opam/patches/mtime

+1680
+4
vendor/opam/mtime/.gitignore
··· 1 + _b0 2 + _build 3 + tmp 4 + *.install
+5
vendor/opam/mtime/.merlin
··· 1 + PKG b0.kit 2 + S src 3 + S src-clock 4 + S test 5 + B _b0/**
+1
vendor/opam/mtime/.ocp-indent
··· 1 + strict_with=always,match_clause=4,strict_else=never
+79
vendor/opam/mtime/B0.ml
··· 1 + open B0_kit.V000 2 + open Result.Syntax 3 + 4 + (* OCaml library names *) 5 + 6 + let b0_std = B0_ocaml.libname "b0.std" 7 + let compiler_libs_toplevel = B0_ocaml.libname "compiler-libs.toplevel" 8 + 9 + let mtime = B0_ocaml.libname "mtime" 10 + let mtime_clock = B0_ocaml.libname "mtime.clock" 11 + let mtime_clock_os = B0_ocaml.libname "mtime.clock.os" 12 + let mtime_top = B0_ocaml.libname "mtime.top" 13 + 14 + (* Libraries *) 15 + 16 + let mtime_lib = 17 + let srcs = [`Dir ~/"src"; `X ~/"src/mtime_top_init.ml"] in 18 + B0_ocaml.lib mtime ~srcs 19 + 20 + let mtime_clock_lib = 21 + let srcs = [`Dir ~/"src/clock"] in 22 + B0_ocaml.lib mtime_clock ~srcs ~requires:[mtime] ~exports:[mtime] 23 + 24 + let mtime_clock_os_lib = 25 + B0_ocaml.deprecated_lib ~exports:[mtime_clock] mtime_clock_os 26 + 27 + let mtime_top = 28 + let srcs = [`Dir ~/"src/top"] in 29 + B0_ocaml.lib mtime_top ~srcs ~requires:[mtime; compiler_libs_toplevel] 30 + 31 + (* Tests *) 32 + 33 + let test_mtime = 34 + let requires = [b0_std; mtime] in 35 + B0_ocaml.test ~/"test/test_mtime.ml" ~requires ~doc:"Mtime tests" 36 + 37 + let test_mtime_clock = 38 + let requires = [b0_std; mtime; mtime_clock] in 39 + B0_ocaml.test ~/"test/test_mtime_clock.ml" ~requires ~doc:"Mtime_clock tests" 40 + 41 + let min_clock = 42 + let doc = "Minimal clock example" in 43 + let requires = [mtime; mtime_clock] in 44 + B0_ocaml.test ~/"test/min_clock.ml" ~run:false ~requires ~doc 45 + 46 + let min_clock_jsoo = 47 + let doc = "Minimal clock example in JavaScript" in 48 + let srcs = Fpath.[`File (v "test/min_clock.ml") ] in 49 + let meta = B0_meta.(empty |> tag test) in 50 + let requires = [mtime; mtime_clock] in 51 + B0_jsoo.html_page "min-clock-jsoo" ~srcs ~requires ~meta ~doc 52 + 53 + (* Packs *) 54 + 55 + let default = 56 + let meta = 57 + B0_meta.empty 58 + |> ~~ B0_meta.authors ["The mtime programmers"] 59 + |> ~~ B0_meta.maintainers ["Daniel Bünzli <daniel.buenzl i@erratique.ch>"] 60 + |> ~~ B0_meta.homepage "https://erratique.ch/software/mtime" 61 + |> ~~ B0_meta.online_doc "https://erratique.ch/software/mtime/doc/" 62 + |> ~~ B0_meta.licenses ["ISC"] 63 + |> ~~ B0_meta.repo "git+https://erratique.ch/repos/mtime.git" 64 + |> ~~ B0_meta.issues "https://github.com/dbuenzli/mtime/issues" 65 + |> ~~ B0_meta.description_tags 66 + ["time"; "monotonic"; "system"; "org:erratique"] 67 + |> B0_meta.add B0_opam.depends 68 + [ "ocaml", {|>= "4.08.0"|}; 69 + "ocamlfind", {|build|}; 70 + "ocamlbuild", {|build & != "0.9.0"|}; 71 + "topkg", {|build & >= "1.1.0"|}; 72 + ] 73 + |> B0_meta.add B0_opam.build 74 + {|[["ocaml" "pkg/pkg.ml" "build" "--dev-pkg" "%{dev}%"]]|} 75 + |> B0_meta.tag B0_opam.tag 76 + |> B0_meta.tag B0_release.tag 77 + in 78 + B0_pack.make "default" ~doc:"mtime package" ~meta ~locked:true @@ 79 + B0_unit.list ()
+1
vendor/opam/mtime/BRZO
··· 1 + (srcs-x myocamlbuild.ml pkg test src/mtime_top.ml src/mtime_top_init.ml)
+134
vendor/opam/mtime/CHANGES.md
··· 1 + v2.1.0 2024-09-10 Zagreb 2 + ------------------------ 3 + 4 + - Add `Mtime.Span.{is_shorter,is_longer}` to make duration 5 + comparisons more obivous. Thanks to Pau Ruiz Safont for 6 + the suggestion and the patch. 7 + - Regularize naming structure. The `mtime.clock.os` library 8 + is deprecated. Use `mtime.clock` instead. 9 + - Make the library `mtime.clock` export `mtime`. 10 + 11 + 12 + v2.0.0 2022-12-02 Zagreb 13 + ------------------------ 14 + 15 + * Use the new `js_of_ocaml` ocamlfind `META` standard to link JavaScript 16 + stubs (#28). 17 + * `Mtime_clock` use `CLOCK_BOOTTIME` rather than `CLOCK_MONOTONIC` 18 + on Linux and `mach_continuous_time` rather than `mach_absolute_time` 19 + on macOS. This means that on these platforms sleep time is taken 20 + into account (#10). Thanks to Bikal Lem for the patch. 21 + * Add `Mtime.{to,of}_float_ns`. 22 + * Remove deprecated values `Mtime.s_to_*` and `Mtime.Span.to_*` floating 23 + points functions. Note that the implementation of `Mtime.Span.to_*` 24 + functions was broken if your span exceeded `Int64.max_int`. Thanks 25 + to Thomas Leonard for the report (#46). 26 + * Change implementation of `Mtime.Span.pp` and remove 27 + `Mtime.Span.pp_float_s`. The implementation no longer uses floating 28 + point arithmetic and always over approximates the result, no 29 + duration is printed shorter than it is. The output is no longer 30 + US-ASCII but UTF-8 encoded since U+03BC is used for µs. 31 + * Stop installing the clock interface in `mtime.clock`, this package 32 + is now empty (#42). 33 + 34 + v1.4.0 2022-02-17 La Forclaz (VS) 35 + --------------------------------- 36 + 37 + * Change the `js_of_ocaml` strategy for `Mtime_clock`'s JavaScript 38 + implementation. Primitives of `mtime.clock.os` are now implemented 39 + in pure JavaScript and linked by `js_of_ocaml`. This means that the 40 + `mtime.clock.jsoo` library no longer exists, simply link against 41 + `mtime.clock.os` instead. Thanks to Hugo Heuzard for suggesting and 42 + implementing this. 43 + 44 + * Add `Mtime.{min,max}_stamp`. 45 + * Add durations `Mtime.Span.{ns,us,ms,s,min,hour,day,year}` and 46 + the `Mtime.Span.(*)` operator (#28). 47 + * Deprecate `Mtime.s_to_*` and `Mtime.*_to_s` floating point constants (#28). 48 + * Require OCaml >= 4.08. 49 + * Allow compiling with MSVC compiler. Thanks to Jonah Beckford for the patch. 50 + 51 + v1.3.0 2021-10-20 Zagreb 52 + ------------------------ 53 + 54 + * Add Windows support. Thanks to Andreas Hauptmann for the patch 55 + and Corentin Leruth for the integration. 56 + 57 + v1.2.0 2019-07-19 Zagreb 58 + ------------------------ 59 + 60 + * Add support for node.js. Thanks to Fabian (@copy) for the patch. 61 + * Support for js_of_ocaml 3.4.0. 62 + * Add MTIME_OS environment variable for specifying the OS at build time. 63 + 64 + v1.1.0 2017-06-24 London 65 + ------------------------ 66 + 67 + * Add `Mtime.Span.{add,zero,one,min_span,max_span}`. 68 + 69 + v1.0.0 2017-05-09 La Forclaz (VS) 70 + --------------------------------- 71 + 72 + This is a major breaking release with a new API. Thanks to David 73 + Sheets for contributions and discussions. The API was changed to 74 + mirror and follow the conventions and design of `Ptime`. The `Mtime` 75 + module now only provides platform independent datatypes for supporting 76 + monotonic clock readings. Platform dependent access to monotonic 77 + clocks is provided by the `Mtime_clock` modules. The `Mtime.t` type 78 + was added for monotonic timestamps. 79 + 80 + * Rename packages `mtime.{jsoo,os}` to `mtime.{clock.jsoo,clock.os}` 81 + which implement the new `Mtime_clock` interface. The `mtime` package 82 + has the platform independent support. 83 + * Remove `Mtime.available`, `Mtime_clock` functions now raise `Sys_error` 84 + on unsupported platforms or errors. 85 + * Add a raw interface to `Mtime_clock` which statisfies MirageOS's monotonic 86 + clock signature. 87 + * Move `Mtime.{elapsed,counter,count}` to 88 + `Mtime_clock.{elapsed,counter,count}`. 89 + * Add `Mtime.t` a type to represent system-relative monotonic 90 + timestamps and related functions. Thanks to David Sheets for the 91 + patch and his patience. 92 + * Add the `Mtime.Span` module for functions on monotonic time 93 + spans. Most of the previous platform independent support is now 94 + provided by this module. See below. 95 + * Move `Mtime.to_ns_uint64` to `Mtime.Span.to_uint64_ns`. 96 + * Move other `Mtime.to_*` to `Mtime.Span.to_*`. 97 + * Move `Mtime.pp_span[_s]` to `Mtime.Span.pp[_float__s]`. 98 + * Add `Mtime.Span.{compare,equal}`. Thanks to David Sheets for the patch. 99 + * Add `Mtime.Span.of_uint64_ns`. Thanks to David Sheets for the patch. 100 + 101 + v0.8.4 2017-02-05 La Forclaz (VS) 102 + --------------------------------- 103 + 104 + * Fix package for -custom linking. Thanks to @orbitz for the report. 105 + * Build depend on topkg. 106 + * Relicense from BSD3 to ISC. 107 + 108 + v0.8.3 2015-12-22 Cambridge (UK) 109 + -------------------------------- 110 + 111 + * Fix Linux bytecode builds. Thanks to Edwin Török for the report. 112 + * Really make js_of_ocaml an optional dependency. 113 + 114 + 115 + v0.8.2 2015-05-17 La Forclaz (VS) 116 + --------------------------------- 117 + 118 + * Simpler toploop support (internal change). 119 + * Improve Linux build support by recording link flags against librt in 120 + the cma and cmxa (this seems to be needed in certain distributions). 121 + Thanks to David Scott for the report and the fix. 122 + 123 + 124 + v0.8.1 2015-03-23 La Forclaz (VS) 125 + --------------------------------- 126 + 127 + * Fix broken arithmetic on 32-bit platform with POSIX clocks. Thanks to 128 + Stephen Dolan for the report and the fix. 129 + 130 + 131 + v0.8.0 2015-03-19 La Forclaz (VS) 132 + --------------------------------- 133 + 134 + First release.
+13
vendor/opam/mtime/LICENSE.md
··· 1 + Copyright (c) 2015 The mtime programmers 2 + 3 + Permission to use, copy, modify, and/or distribute this software for any 4 + purpose with or without fee is hereby granted, provided that the above 5 + copyright notice and this permission notice appear in all copies. 6 + 7 + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+42
vendor/opam/mtime/README.md
··· 1 + Mtime — Monotonic wall-clock time for OCaml 2 + =========================================== 3 + 4 + Mtime has platform independent support for monotonic wall-clock time 5 + in pure OCaml. This time increases monotonically and is not subject to 6 + operating system calendar time adjustments. The library has types to 7 + represent nanosecond precision timestamps and time spans. 8 + 9 + The additional Mtime_clock library provide access to a system 10 + monotonic clock. 11 + 12 + Mtime has a no dependency. Mtime_clock depends on your system library 13 + or JavaScript runtime system. Mtime and its libraries are distributed 14 + under the ISC license. 15 + 16 + Home page: <http://erratique.ch/software/mtime> 17 + 18 + # Installation 19 + 20 + Mtime can be installed with `opam`: 21 + 22 + opam install mtime 23 + 24 + If you don't use `opam` consult the [`opam`](opam) file for build 25 + instructions. 26 + 27 + # Documentation 28 + 29 + The documentation can be consulted [online] or via `odig doc mtime`. 30 + 31 + Questions are welcome but better asked on the [OCaml forum] than on 32 + the issue tracker. 33 + 34 + [online]: http://erratique.ch/software/mtime/doc/ 35 + [OCaml forum]: https://discuss.ocaml.org/ 36 + 37 + # Sample programs 38 + 39 + See [test/min_clock.ml](test/min_clock.ml). 40 + 41 + If you installed mtime with `opam` sample programs are located in 42 + the directory `opam var mtime:doc`.
+7
vendor/opam/mtime/_tags
··· 1 + true : bin_annot, safe_string 2 + <_b0> : -traverse 3 + 4 + <src> : include 5 + <src/top/mtime_top*> : package(compiler-libs.toplevel) 6 + <src/clock/mtime_clock.{cma,cmxa}> : record_mtime_clock_stubs 7 + <src/clock/mtime_clock.cmxs> : link_mtime_clock_stubs
+20
vendor/opam/mtime/doc/index.mld
··· 1 + {0 Mtime {%html: <span class="version">%%VERSION%%</span>%}} 2 + 3 + Mtime has platform independent support for monotonic wall-clock time. 4 + This time increases monotonically and is not subject to operating 5 + system calendar time adjustments. The library has types to represent 6 + nanosecond precision timestamps and time spans. 7 + 8 + {!Mtime_clock} provides acces to {{!Mtime_clock.platform_support}a 9 + monotonic system clock} and its resolution (if available). 10 + 11 + {1:mtime Library [mtime]} 12 + 13 + {!modules: Mtime} 14 + 15 + {1:mtime_clock Library [mtime.clock]} 16 + 17 + {!modules: Mtime_clock} 18 + 19 + This library also works with JavaScript, see the 20 + {{!Mtime_clock.platform_support}platform support}.
+2
vendor/opam/mtime/dune-project
··· 1 + (lang dune 3.0) 2 + (name mtime)
vendor/opam/mtime/mtime.opam

This is a binary file and will not be displayed.

+43
vendor/opam/mtime/myocamlbuild.ml
··· 1 + open Ocamlbuild_plugin 2 + open Command 3 + 4 + let os = try Sys.getenv "MTIME_OS" with 5 + | Not_found -> Ocamlbuild_pack.My_unix.run_and_read "uname -s" 6 + 7 + let system_support_lib = match os with 8 + | "Linux\n" -> [A "-cclib"; A "-lrt"] 9 + | _ -> [] 10 + 11 + let lib s = 12 + match !Ocamlbuild_plugin.Options.ext_lib with 13 + | "" -> s ^ ".a" 14 + | x -> s ^ "." ^ x 15 + 16 + let () = 17 + dispatch begin function 18 + | After_rules -> 19 + 20 + (* mtime *) 21 + 22 + ocaml_lib ~tag_name:"use_mtime" ~dir:"src" "src/mtime"; 23 + 24 + (* mtime-clock *) 25 + 26 + flag_and_dep ["link"; "ocaml"; "link_mtime_clock_stubs"] 27 + (P (lib "src/clock/libmtime_clock_stubs")); 28 + 29 + dep ["record_mtime_clock_stubs"] 30 + [lib "src/clock/libmtime_clock_stubs"]; 31 + 32 + flag ["library"; "ocaml"; "byte"; "record_mtime_clock_stubs"] 33 + (S ([A "-dllib"; A "-lmtime_clock_stubs"] @ system_support_lib)); 34 + flag ["library"; "ocaml"; "record_mtime_clock_stubs"] (* byt + nat *) 35 + (S ([A "-cclib"; A "-lmtime_clock_stubs"] @ system_support_lib)); 36 + 37 + ocaml_lib ~tag_name:"use_mtime_clock" ~dir:"src/clock" 38 + "src/clock/mtime_clock"; 39 + 40 + flag ["link"; "ocaml"; "use_mtime_clock"] 41 + (S [A "-ccopt"; A "-Lsrc/clock"]); 42 + | _ -> () 43 + end
+32
vendor/opam/mtime/opam
··· 1 + opam-version: "2.0" 2 + name: "mtime" 3 + synopsis: "Monotonic wall-clock time for OCaml" 4 + description: """\ 5 + Mtime has platform independent support for monotonic wall-clock time 6 + in pure OCaml. This time increases monotonically and is not subject to 7 + operating system calendar time adjustments. The library has types to 8 + represent nanosecond precision timestamps and time spans. 9 + 10 + The additional Mtime_clock library provide access to a system 11 + monotonic clock. 12 + 13 + Mtime has a no dependency. Mtime_clock depends on your system library 14 + or JavaScript runtime system. Mtime and its libraries are distributed 15 + under the ISC license. 16 + 17 + Home page: <http://erratique.ch/software/mtime>""" 18 + maintainer: "Daniel Bünzli <daniel.buenzl i@erratique.ch>" 19 + authors: "The mtime programmers" 20 + license: "ISC" 21 + tags: ["time" "monotonic" "system" "org:erratique"] 22 + homepage: "https://erratique.ch/software/mtime" 23 + doc: "https://erratique.ch/software/mtime/doc/" 24 + bug-reports: "https://github.com/dbuenzli/mtime/issues" 25 + depends: [ 26 + "ocaml" {>= "4.08.0"} 27 + "ocamlfind" {build} 28 + "ocamlbuild" {build & != "0.9.0"} 29 + "topkg" {build & >= "1.1.0"} 30 + ] 31 + build: ["ocaml" "pkg/pkg.ml" "build" "--dev-pkg" "%{dev}%"] 32 + dev-repo: "git+https://erratique.ch/repos/mtime.git"
+42
vendor/opam/mtime/pkg/META
··· 1 + description = "Monotonic wall-clock time for OCaml" 2 + version = "%%VERSION_NUM%%" 3 + requires = "" 4 + archive(byte) = "mtime.cma" 5 + archive(native) = "mtime.cmxa" 6 + plugin(byte) = "mtime.cma" 7 + plugin(native) = "mtime.cmxs" 8 + exists_if = "mtime.cma mtime.cmxa" 9 + 10 + package "clock" ( 11 + directory = "clock" 12 + description = "The mtime.clock library" 13 + version = "%%VERSION_NUM%%" 14 + requires = "mtime" 15 + exports = "mtime" 16 + archive(byte) = "mtime_clock.cma" 17 + archive(native) = "mtime_clock.cmxa" 18 + plugin(byte) = "mtime_clock.cma" 19 + plugin(native) = "mtime_clock.cmxs" 20 + jsoo_runtime = "runtime.js" 21 + exists_if = "mtime_clock.cma mtime_clock.cmxa" 22 + 23 + package "os" ( 24 + description = "The mtime.clock.os library (deprecated)" 25 + version = "%%VERSION_NUM%%" 26 + requires = "mtime.clock" 27 + exports = "mtime.clock" 28 + warning = "Deprecated, use the mtime.clock library." 29 + ) 30 + ) 31 + 32 + package "top" ( 33 + directory = "top" 34 + description = "The mtime.top library" 35 + version = "%%VERSION_NUM%%" 36 + requires = "mtime" 37 + archive(byte) = "mtime_top.cma" 38 + archive(native) = "mtime_top.cmxa" 39 + plugin(byte) = "mtime_top.cma" 40 + plugin(native) = "mtime_top.cmxs" 41 + exists_if = "mtime_top.cma mtime_top.cmxa" 42 + )
+15
vendor/opam/mtime/pkg/pkg.ml
··· 1 + #!/usr/bin/env ocaml 2 + #use "topfind" 3 + #require "topkg" 4 + open Topkg 5 + 6 + let () = 7 + Pkg.describe "mtime" @@ fun c -> 8 + Ok [ Pkg.mllib "src/mtime.mllib"; 9 + Pkg.mllib "src/clock/mtime_clock.mllib" ~dst_dir:"clock/"; 10 + Pkg.clib "src/clock/libmtime_clock_stubs.clib" ~lib_dst_dir:"clock/"; 11 + Pkg.lib "src/clock/runtime.js" ~dst:"clock/"; 12 + Pkg.mllib ~api:[] "src/top/mtime_top.mllib" ~dst_dir:"top/"; 13 + Pkg.lib "src/mtime_top_init.ml"; 14 + Pkg.doc "doc/index.mld" ~dst:"odoc-pages/index.mld"; 15 + Pkg.doc "test/min_clock.ml"; ]
+18
vendor/opam/mtime/src/clock/dune
··· 1 + (library 2 + (name mtime_clock) 3 + (public_name mtime.clock) 4 + (modules Mtime_clock) 5 + (libraries mtime) 6 + (foreign_stubs 7 + (language c) 8 + (names mtime_clock_stubs)) 9 + (js_of_ocaml (javascript_files runtime.js))) 10 + 11 + (deprecated_library_name 12 + (old_public_name mtime.clock.os) 13 + (new_public_name mtime.clock)) 14 + 15 + (install 16 + (section lib) 17 + (package mtime) 18 + (files runtime.js))
+1
vendor/opam/mtime/src/clock/libmtime_clock_stubs.clib
··· 1 + mtime_clock_stubs.o
+24
vendor/opam/mtime/src/clock/mtime_clock.ml
··· 1 + (*--------------------------------------------------------------------------- 2 + Copyright (c) 2017 The mtime programmers. All rights reserved. 3 + SPDX-License-Identifier: ISC 4 + ---------------------------------------------------------------------------*) 5 + 6 + (* Raw interface *) 7 + 8 + external elapsed_ns : unit -> int64 = "ocaml_mtime_clock_elapsed_ns" 9 + external now_ns : unit -> int64 = "ocaml_mtime_clock_now_ns" 10 + external period_ns : unit -> int64 option = "ocaml_mtime_clock_period_ns" 11 + 12 + let () = ignore (elapsed_ns ()) (* Initalize elapsed_ns's origin. *) 13 + 14 + (* Monotonic clock *) 15 + 16 + let elapsed () = Mtime.Span.of_uint64_ns (elapsed_ns ()) 17 + let now () = Mtime.of_uint64_ns (now_ns ()) 18 + let period () = Mtime.Span.unsafe_of_uint64_ns_option (period_ns ()) 19 + 20 + (* Counters *) 21 + 22 + type counter = int64 23 + let counter = elapsed_ns 24 + let count c = Mtime.Span.of_uint64_ns (Int64.sub (elapsed_ns ()) c)
+108
vendor/opam/mtime/src/clock/mtime_clock.mli
··· 1 + (*--------------------------------------------------------------------------- 2 + Copyright (c) 2017 The mtime programmers. All rights reserved. 3 + SPDX-License-Identifier: ISC 4 + ---------------------------------------------------------------------------*) 5 + 6 + (** Monotonic time clock. 7 + 8 + [Mtime_clock] provides access to a system monotonic clock. This 9 + time increases monotonically and is not subject to operating 10 + system calendar time adjustments. 11 + 12 + Only use {!Mtime_clock.now} if you need inter-process time 13 + correlation, otherwise prefer {!Mtime_clock.elapsed} and 14 + {{!Mtime_clock.counters}counters}. 15 + 16 + Consult important information about {{!err}error handling} 17 + and {{!platform_support}platform support}. *) 18 + 19 + (** {1:clock Monotonic clock} *) 20 + 21 + val elapsed : unit -> Mtime.span 22 + (** [elapsed ()] is the monotonic time span elapsed since the 23 + beginning of the program. 24 + 25 + Raises {!Sys_error}, see {{!err}error handling} *) 26 + 27 + val now : unit -> Mtime.t 28 + (** [now ()] is the current system-relative monotonic timestamp. Its 29 + absolute value is meaningless. 30 + 31 + Raises {!Sys_error}, see {{!err}error handling} *) 32 + 33 + val period : unit -> Mtime.span option 34 + (** [period ()] is the clock's period as a monotonic time span (if 35 + available). *) 36 + 37 + (** {1:counters Time counters} *) 38 + 39 + type counter 40 + (** The type for monotonic wall-clock time counters. *) 41 + 42 + val counter : unit -> counter 43 + (** [counter ()] is a counter counting from now on. 44 + 45 + Raises {!Sys_error}, see {{!err}error handling} *) 46 + 47 + val count : counter -> Mtime.span 48 + (** [count c] is the monotonic time span elapsed since [c] was created. *) 49 + 50 + (** {1:raw Monotonic clock raw interface} *) 51 + 52 + val elapsed_ns : unit -> int64 53 + (** [elapsed_ns ()] is the {e unsigned} 64-bit integer nanosecond monotonic 54 + time span elapsed since the beginning of the program. 55 + 56 + Raises {!Sys_error}, see {{!err}error handling} *) 57 + 58 + val now_ns : unit -> int64 59 + (** [now_ns ()] is an {e unsigned} 64-bit integer nanosecond 60 + system-relative monotonic timestamp. The absolute value is 61 + meaningless. 62 + 63 + Raises {!Sys_error}, see {{!err}error handling} *) 64 + 65 + val period_ns : unit -> int64 option 66 + (** [period_ns ()] is the clock's period as an {e unsigned} 64-bit 67 + integer nanosecond monotonic time span (if available). *) 68 + 69 + (** {1:err Error handling} 70 + 71 + The functions {!elapsed}, {!now}, {!val-counter}, {!elapsed_ns} and 72 + {!now_ns} raise [Sys_error] whenever they can't determine the 73 + current time or that it doesn't fit in [Mtime]'s range. Usually 74 + this exception should only be catched at the toplevel of your 75 + program to log it and abort the program. It indicates a serious 76 + error condition in the system. 77 + 78 + All the other functions, whose functionality is less essential, 79 + simply silently return [None] if they can't determine the 80 + information either because it is unavailable or because an error 81 + occured. 82 + 83 + {1:platform_support Platform support} 84 + 85 + {ul 86 + {- Linux uses {{:http://pubs.opengroup.org/onlinepubs/9699919799/functions/clock_gettime.html}[clock_gettime]} 87 + with {{:https://www.man7.org/linux/man-pages/man3/clock_settime.3.html} 88 + CLOCK_BOOTTIME}. This means that sleep time is taken into account.} 89 + {- Platforms with a POSIX clock use 90 + {{:http://pubs.opengroup.org/onlinepubs/9699919799/functions/clock_gettime.html}[clock_gettime]} 91 + with CLOCK_MONOTONIC.} 92 + {- Darwin uses 93 + {{:https://developer.apple.com/documentation/kernel/1646199-mach_continuous_time}[mach_continous_time]}. 94 + This means that sleep time is taken into account.} 95 + {- Windows uses 96 + {{:https://msdn.microsoft.com/en-us/library/windows/desktop/aa373083%28v=vs.85%29.aspx}Performance counters}. } 97 + {- JavaScript uses 98 + {{:http://www.w3.org/TR/hr-time/}[performance.now]} (consult 99 + {{:http://caniuse.com/#feat=high-resolution-time}availability}) 100 + which returns a 101 + {{:http://www.w3.org/TR/hr-time/#sec-DOMHighResTimeStamp}double 102 + floating point value} in milliseconds with 103 + resolution up to the microsecond.} 104 + {- JavaScript running on Node.js uses the built-in 105 + {{:https://nodejs.org/api/perf_hooks.html#perf_hooks_performance_now}[perf_hooks]} 106 + module, which provides an interface compatible to the [performance] 107 + module in browsers.}} 108 + *)
+1
vendor/opam/mtime/src/clock/mtime_clock.mllib
··· 1 + Mtime_clock
+220
vendor/opam/mtime/src/clock/mtime_clock_stubs.c
··· 1 + /*--------------------------------------------------------------------------- 2 + Copyright (c) 2015 The mtime programmers. All rights reserved. 3 + SPDX-License-Identifier: ISC 4 + ---------------------------------------------------------------------------*/ 5 + 6 + #include <caml/mlvalues.h> 7 + #include <caml/alloc.h> 8 + #include <caml/memory.h> 9 + #include <caml/fail.h> 10 + 11 + #include <stdint.h> 12 + 13 + #define Val_none Val_int(0) 14 + #define OCAML_MTIME_RAISE_SYS_ERROR(ERR) \ 15 + do { caml_raise_sys_error (caml_copy_string("Mtime_clock: " ERR)); } \ 16 + while (0) 17 + 18 + /* Detect platform */ 19 + 20 + #if defined(__APPLE__) && defined(__MACH__) 21 + #define OCAML_MTIME_DARWIN 22 + 23 + #elif defined(__unix__) || defined(__unix) 24 + #include <unistd.h> 25 + #if defined(__linux__) 26 + #define OCAML_MTIME_LINUX 27 + #endif 28 + #if defined(_POSIX_VERSION) 29 + #define OCAML_MTIME_POSIX 30 + #endif 31 + #elif defined(_WIN32) 32 + #define OCAML_MTIME_WINDOWS 33 + #endif 34 + 35 + /* Darwin */ 36 + 37 + #if defined(OCAML_MTIME_DARWIN) 38 + 39 + #include <mach/mach_time.h> 40 + 41 + static mach_timebase_info_data_t scale = {0}; 42 + 43 + void ocaml_mtime_clock_init_scale (void) 44 + { 45 + if (mach_timebase_info (&scale) != KERN_SUCCESS) 46 + OCAML_MTIME_RAISE_SYS_ERROR ("mach_timebase_info () failed"); 47 + 48 + if (scale.denom == 0) 49 + OCAML_MTIME_RAISE_SYS_ERROR ("mach_timebase_info_data.denom is 0"); 50 + } 51 + 52 + CAMLprim value ocaml_mtime_clock_elapsed_ns (value unit) 53 + { 54 + static uint64_t start = 0L; 55 + if (start == 0L) { start = mach_continuous_time (); } 56 + if (scale.denom == 0) { ocaml_mtime_clock_init_scale (); } 57 + uint64_t now = mach_continuous_time (); 58 + return caml_copy_int64 (((now - start) * scale.numer) / scale.denom); 59 + } 60 + 61 + CAMLprim value ocaml_mtime_clock_now_ns (value unit) 62 + { 63 + if (scale.denom == 0) { ocaml_mtime_clock_init_scale (); } 64 + uint64_t now = mach_continuous_time (); 65 + return caml_copy_int64 ((now * scale.numer) / scale.denom); 66 + } 67 + 68 + CAMLprim value ocaml_mtime_clock_period_ns (value unit) 69 + { return Val_none; } 70 + 71 + /* POSIX */ 72 + 73 + #elif defined(OCAML_MTIME_POSIX) 74 + 75 + #include <time.h> 76 + 77 + CAMLprim value ocaml_mtime_clock_elapsed_ns (value unit) 78 + { 79 + static struct timespec start = {0}; 80 + struct timespec now; 81 + clockid_t clockid; 82 + 83 + #if defined(OCAML_MTIME_LINUX) 84 + clockid = CLOCK_BOOTTIME; 85 + #else 86 + clockid = CLOCK_MONOTONIC; 87 + #endif 88 + 89 + if (start.tv_sec == 0) 90 + { 91 + if (clock_gettime (clockid, &start)) 92 + OCAML_MTIME_RAISE_SYS_ERROR ("clock_gettime () failed"); 93 + } 94 + 95 + if (clock_gettime (clockid, &now)) 96 + OCAML_MTIME_RAISE_SYS_ERROR ("clock_gettime () failed"); 97 + 98 + return caml_copy_int64 ((uint64_t)(now.tv_sec - start.tv_sec) * 99 + (uint64_t)1000000000 + 100 + (uint64_t)(now.tv_nsec - start.tv_nsec)); 101 + } 102 + 103 + CAMLprim value ocaml_mtime_clock_now_ns (value unit) 104 + { 105 + struct timespec now; 106 + 107 + if (clock_gettime (CLOCK_MONOTONIC, &now)) 108 + OCAML_MTIME_RAISE_SYS_ERROR ("clock_gettime () failed"); 109 + 110 + return caml_copy_int64 ((uint64_t)(now.tv_sec) * 111 + (uint64_t)1000000000 + 112 + (uint64_t)(now.tv_nsec)); 113 + } 114 + 115 + CAMLprim value ocaml_mtime_clock_period_ns (value unit) 116 + { 117 + CAMLparam1 (unit); 118 + CAMLlocal1 (some); 119 + struct timespec res; 120 + 121 + if (clock_getres (CLOCK_MONOTONIC, &res)) { CAMLreturn (Val_none); } 122 + 123 + /* We only handle valid timespec structs as per POSIX def (§2.8.5 in 2013) */ 124 + if (res.tv_nsec < 0 || res.tv_nsec > 999999999) CAMLreturn (Val_none); 125 + 126 + /* Negative periods are dubious */ 127 + if (res.tv_sec < 0) CAMLreturn (Val_none); 128 + 129 + some = caml_alloc (1, 0); 130 + Store_field (some, 0, 131 + caml_copy_int64 ((uint64_t)(res.tv_sec) * 132 + (uint64_t)1000000000 + 133 + (uint64_t)(res.tv_nsec))); 134 + CAMLreturn (some); 135 + } 136 + 137 + #elif defined(OCAML_MTIME_WINDOWS) 138 + #define WIN32_LEAN_AND_MEAN 139 + #include <windows.h> 140 + 141 + static double performance_frequency; 142 + static void set_performance_frequency(void) 143 + { 144 + LARGE_INTEGER t_freq; 145 + if (!QueryPerformanceFrequency(&t_freq)) { 146 + OCAML_MTIME_RAISE_SYS_ERROR ("clock_gettime () failed"); 147 + } 148 + performance_frequency = (1000000000.0 / t_freq.QuadPart); 149 + } 150 + 151 + CAMLprim value ocaml_mtime_clock_elapsed_ns (value unit) 152 + { 153 + (void) unit; 154 + static LARGE_INTEGER start; 155 + if (performance_frequency == 0.0) { 156 + set_performance_frequency(); 157 + } 158 + if ( start.QuadPart == 0 ) 159 + { 160 + if (!QueryPerformanceCounter(&start)) { 161 + OCAML_MTIME_RAISE_SYS_ERROR ("clock_gettime () failed"); 162 + } 163 + } 164 + static LARGE_INTEGER now; 165 + if ( !QueryPerformanceCounter(&now)) { 166 + OCAML_MTIME_RAISE_SYS_ERROR ("clock_gettime () failed"); 167 + } 168 + uint64_t ret = (now.QuadPart - start.QuadPart) * performance_frequency; 169 + return caml_copy_int64(ret); 170 + } 171 + 172 + CAMLprim value ocaml_mtime_clock_now_ns (value unit) 173 + { 174 + (void) unit; 175 + if (performance_frequency == 0.0) { 176 + set_performance_frequency(); 177 + } 178 + static LARGE_INTEGER now; 179 + if ( !QueryPerformanceCounter(&now)) { 180 + OCAML_MTIME_RAISE_SYS_ERROR ("clock_gettime () failed"); 181 + } 182 + uint64_t ret = now.QuadPart * performance_frequency; 183 + return caml_copy_int64(ret); 184 + } 185 + 186 + CAMLprim value ocaml_mtime_clock_period_ns (value unit) 187 + { 188 + (void) unit; 189 + if (performance_frequency == 0.0) { 190 + set_performance_frequency(); 191 + } 192 + if ( performance_frequency <= 0.0 ) { 193 + return Val_none; 194 + } 195 + value ret; 196 + value p = caml_copy_int64(performance_frequency); 197 + Begin_roots1(p); 198 + ret = caml_alloc_small(1,0); 199 + Field(ret,0) = p; 200 + End_roots(); 201 + return ret; 202 + } 203 + 204 + 205 + /* Unsupported */ 206 + 207 + #else 208 + 209 + #warning OCaml Mtime_clock module: unsupported platform 210 + 211 + CAMLprim value ocaml_mtime_clock_elapsed_ns (value unit) 212 + { OCAML_MTIME_RAISE_SYS_ERROR ("unsupported platform"); } 213 + 214 + CAMLprim value ocaml_mtime_clock_now_ns (value unit) 215 + { OCAML_MTIME_RAISE_SYS_ERROR ("unsupported platform"); } 216 + 217 + CAMLprim value ocaml_mtime_clock_period_ns (value unit) 218 + { OCAML_MTIME_RAISE_SYS_ERROR ("unsupported platform"); } 219 + 220 + #endif
+77
vendor/opam/mtime/src/clock/runtime.js
··· 1 + /*--------------------------------------------------------------------------- 2 + Copyright (c) 2022 The mtime programmers. All rights reserved. 3 + SPDX-License-Identifier: ISC 4 + ---------------------------------------------------------------------------*/ 5 + 6 + //Provides: ocaml_mtime_clock_period_ns 7 + function ocaml_mtime_clock_period_ns (_unit) { 8 + return 0; 9 + } 10 + 11 + //Provides: mtime_clock_now 12 + //Requires: caml_int64_of_float, caml_int64_mul 13 + //Requires: caml_raise_sys_error 14 + function find_performance_obj () { 15 + var test = function (o) 16 + { return (o && o.performance && typeof o.performance.now == "function");}; 17 + 18 + if (test (globalThis)) { return globalThis.performance; }; 19 + if (test (globalThis.perf_hooks)){ return globalThis.perf_hooks.performance;}; 20 + if (typeof require == "function") { 21 + var ph = require ("perf_hooks"); 22 + if (test (ph)) { return ph.performance; } 23 + } 24 + var obj = { now: function () 25 + { caml_raise_sys_error ("performance.now () is not available");}} 26 + return obj; 27 + } 28 + var performance_obj = find_performance_obj (); 29 + function mtime_clock_now () { 30 + /* Conversion of DOMHighResTimeStamp to uint64 nanosecond timestamps. 31 + 32 + The spec https://www.w3.org/TR/hr-time-3 says DOMHighResTimeStamp 33 + are double milliseconds that *should* be accurate to 5 microseconds. 34 + We simply assume we have microsecond precision and multiply the 35 + stamps given by performance.now () by 1e3 to get double microseconds. 36 + 37 + We then use Int64.of_float on these double microseconds to get an 38 + uint64 in microseconds. This works in practice for the following 39 + reasons. Let us assume we have the largest integer microsecond 40 + timestamp representable exactly in double, i.e. 2^53 : 41 + 42 + 1) Assuming the zero of performance.now is when the tab is created, 43 + our 2^53 timestamp only occurs after: 44 + 45 + 2^53 / 1_000_000 / (24 * 3600 * 365.25) ≅ 285.4 Julian years 46 + 47 + 2) 2^53 < Int64.max_int = 2^63 - 1, so seing the result of 48 + Int64.of_float as unsigned for this timestamp is correct and in 49 + the defined domain of the conversion function (the truncated float 50 + must lie in [Int64.min_int;Int64.max_int] for defined behaviour). 51 + 52 + So the Int64.of_float conversion is unlikely to be problematic and 53 + we simply bring the resulting uint64 microsecond to an uint64 54 + nanosecond by multiplying by 1000L, which for 2^53 microseconds 55 + remains smaller than Int64.max_int, yielding a correct uint64 56 + nanosecond timestamp for a reasonable time range. */ 57 + 58 + var now_us = performance_obj.now () * 1e3; 59 + var now_ns = caml_int64_mul (caml_int64_of_float (now_us), 60 + caml_int64_of_float (1000)); 61 + return now_ns; 62 + } 63 + 64 + //Provides: ocaml_mtime_clock_now_ns 65 + //Requires: mtime_clock_now 66 + function ocaml_mtime_clock_now_ns (_unit) { 67 + return mtime_clock_now (); 68 + } 69 + 70 + //Provides: ocaml_mtime_clock_elapsed_ns 71 + //Requires: caml_int64_sub, mtime_clock_now 72 + var mtime_clock_start; 73 + function ocaml_mtime_clock_elapsed_ns (_unix) { 74 + if (!mtime_clock_start) mtime_clock_start = mtime_clock_now (); 75 + var now = mtime_clock_now (); 76 + return caml_int64_sub (now, mtime_clock_start); 77 + }
+9
vendor/opam/mtime/src/dune
··· 1 + (library 2 + (name mtime) 3 + (public_name mtime) 4 + (modules Mtime)) 5 + 6 + (install 7 + (section lib) 8 + (package mtime) 9 + (files mtime_top_init.ml))
+173
vendor/opam/mtime/src/mtime.ml
··· 1 + (*--------------------------------------------------------------------------- 2 + Copyright (c) 2015 The mtime programmers. All rights reserved. 3 + SPDX-License-Identifier: ISC 4 + ---------------------------------------------------------------------------*) 5 + 6 + (* Time spans 7 + 8 + Time spans are in nanoseconds and we represent them by an unsigned 9 + 64-bit integer. This allows to represent spans for: 10 + (2^64-1) / 1_000_000_000 / (24 * 3600 * 365.25) ≅ 584.5 Julian years *) 11 + 12 + type span = int64 (* unsigned nanoseconds *) 13 + 14 + module Span = struct 15 + type t = span 16 + let zero = 0L 17 + let one = 1L 18 + let min_span = zero 19 + let max_span = -1L 20 + 21 + (* Predicates *) 22 + 23 + let equal = Int64.equal 24 + let compare = Int64.unsigned_compare 25 + let is_shorter s ~than = compare s than < 0 26 + let is_longer s ~than = compare s than > 0 27 + 28 + (* Arithmetic *) 29 + 30 + let add = Int64.add 31 + let abs_diff s0 s1 = 32 + if compare s0 s1 < 0 then Int64.sub s1 s0 else Int64.sub s0 s1 33 + 34 + (* Durations *) 35 + 36 + let ( * ) n s = Int64.mul (Int64.of_int n) s 37 + let ns = 1L 38 + let us = 1_000L 39 + let ms = 1_000_000L 40 + let s = 1_000_000_000L 41 + let min = 60_000_000_000L 42 + let hour = 3600_000_000_000L 43 + let day = 86400_000_000_000L 44 + let year = 31_557_600_000_000_000L 45 + 46 + (* Converting *) 47 + 48 + let to_uint64_ns s = s 49 + let of_uint64_ns ns = ns 50 + 51 + let max_float_int = 9007199254740992. (* 2^53. *) 52 + let int64_min_int_float = Int64.to_float Int64.min_int 53 + let int64_max_int_float = Int64.to_float Int64.max_int 54 + 55 + let of_float_ns sf = 56 + if sf < 0. || sf >= max_float_int || not (Float.is_finite sf) 57 + then None else Some (Int64.of_float sf) 58 + 59 + let to_float_ns s = 60 + if Int64.compare 0L s <= 0 then Int64.to_float s else 61 + int64_max_int_float +. (-. int64_min_int_float +. Int64.to_float s) 62 + 63 + let unsafe_of_uint64_ns_option nsopt = nsopt 64 + 65 + (* Formatting *) 66 + 67 + let pf = Format.fprintf 68 + 69 + let rec pp_si_span unit_str unit_str_len si_unit si_higher_unit ppf span = 70 + let geq x y = Int64.unsigned_compare x y >= 0 in 71 + let m = Int64.unsigned_div span si_unit in 72 + let n = Int64.unsigned_rem span si_unit in 73 + let pp_unit ppf () = Format.pp_print_as ppf unit_str_len unit_str in 74 + match m with 75 + | m when geq m 100L -> (* No fractional digit *) 76 + let m_up = if Int64.equal n 0L then m else Int64.succ m in 77 + let span' = Int64.mul m_up si_unit in 78 + if geq span' si_higher_unit then pp ppf span' else 79 + (pf ppf "%Ld" m_up; pp_unit ppf ()) 80 + | m when geq m 10L -> (* One fractional digit w.o. trailing zero *) 81 + let f_factor = Int64.unsigned_div si_unit 10L in 82 + let f_m = Int64.unsigned_div n f_factor in 83 + let f_n = Int64.unsigned_rem n f_factor in 84 + let f_m_up = if Int64.equal f_n 0L then f_m else Int64.succ f_m in 85 + begin match f_m_up with 86 + | 0L -> pf ppf "%Ld" m; pp_unit ppf () 87 + | f when geq f 10L -> 88 + pp ppf Int64.(add (mul m si_unit) (mul f f_factor)) 89 + | f -> pf ppf "%Ld.%Ld" m f; pp_unit ppf () 90 + end 91 + | m -> (* Two or zero fractional digits w.o. trailing zero *) 92 + let f_factor = Int64.unsigned_div si_unit 100L in 93 + let f_m = Int64.unsigned_div n f_factor in 94 + let f_n = Int64.unsigned_rem n f_factor in 95 + let f_m_up = if Int64.equal f_n 0L then f_m else Int64.succ f_m in 96 + match f_m_up with 97 + | 0L -> pf ppf "%Ld" m; pp_unit ppf () 98 + | f when geq f 100L -> 99 + pp ppf Int64.(add (mul m si_unit) (mul f f_factor)) 100 + | f when Int64.equal (Int64.rem f 10L) 0L -> 101 + pf ppf "%Ld.%Ld" m (Int64.div f 10L); pp_unit ppf () 102 + | f -> 103 + pf ppf "%Ld.%02Ld" m f; pp_unit ppf () 104 + 105 + and pp_non_si unit_str unit unit_lo_str unit_lo unit_lo_size ppf span = 106 + let geq x y = Int64.unsigned_compare x y >= 0 in 107 + let m = Int64.unsigned_div span unit in 108 + let n = Int64.unsigned_rem span unit in 109 + if Int64.equal n 0L then pf ppf "%Ld%s" m unit_str else 110 + let f_m = Int64.unsigned_div n unit_lo in 111 + let f_n = Int64.unsigned_rem n unit_lo in 112 + let f_m_up = if Int64.equal f_n 0L then f_m else Int64.succ f_m in 113 + match f_m_up with 114 + | f when geq f unit_lo_size -> 115 + pp ppf Int64.(add (mul m unit) (mul f unit_lo)) 116 + | f -> 117 + pf ppf "%Ld%s%Ld%s" m unit_str f unit_lo_str 118 + 119 + and pp ppf span = 120 + let geq x y = Int64.unsigned_compare x y >= 0 in 121 + let lt x y = Int64.unsigned_compare x y = -1 in 122 + match span with 123 + | sp when lt sp us -> pf ppf "%Ldns" sp 124 + | sp when lt sp ms -> pp_si_span "\xCE\xBCs" 2 us ms ppf sp 125 + | sp when lt sp s -> pp_si_span "ms" 2 ms s ppf sp 126 + | sp when lt sp min -> pp_si_span "s" 1 s min ppf sp 127 + | sp when lt sp hour -> pp_non_si "min" min "s" s 60L ppf sp 128 + | sp when lt sp day -> pp_non_si "h" hour "min" min 60L ppf sp 129 + | sp when lt sp year -> pp_non_si "d" day "h" hour 24L ppf sp | sp -> 130 + let m = Int64.unsigned_div sp year in 131 + let n = Int64.unsigned_rem sp year in 132 + if Int64.equal n 0L then pf ppf "%Lda" m else 133 + let f_m = Int64.unsigned_div n day in 134 + let f_n = Int64.unsigned_rem n day in 135 + let f_m_up = if Int64.equal f_n 0L then f_m else Int64.succ f_m in 136 + match f_m_up with 137 + | f when geq f 366L -> pf ppf "%Lda" (Int64.succ m) 138 + | f -> pf ppf "%Lda%Ldd" m f 139 + 140 + let dump ppf s = Format.fprintf ppf "%Lu" s 141 + end 142 + 143 + (* Monotonic timestamps *) 144 + 145 + type t = int64 146 + 147 + let to_uint64_ns s = s 148 + let of_uint64_ns ns = ns 149 + let min_stamp = 0L 150 + let max_stamp = -1L 151 + 152 + (* Predicates *) 153 + 154 + let equal = Int64.equal 155 + let compare = Int64.unsigned_compare 156 + let is_earlier t ~than = compare t than < 0 157 + let is_later t ~than = compare t than > 0 158 + 159 + (* Arithmetic *) 160 + 161 + let span t0 t1 = if compare t0 t1 < 0 then Int64.sub t1 t0 else Int64.sub t0 t1 162 + 163 + let add_span t s = 164 + let sum = Int64.add t s in 165 + if compare t sum <= 0 then Some sum else None 166 + 167 + let sub_span t s = 168 + if compare t s < 0 then None else Some (Int64.sub t s) 169 + 170 + (* Formatters *) 171 + 172 + let pp ppf ns = Format.fprintf ppf "%Luns" ns 173 + let dump ppf ns = Format.fprintf ppf "%Lu" ns
+228
vendor/opam/mtime/src/mtime.mli
··· 1 + (*--------------------------------------------------------------------------- 2 + Copyright (c) 2015 The mtime programmers. All rights reserved. 3 + SPDX-License-Identifier: ISC 4 + ---------------------------------------------------------------------------*) 5 + 6 + (** Monotonic time values. 7 + 8 + [Mtime] has platform independent support for monotonic wall-clock 9 + time. This time increases monotonically and is not subject to 10 + operating system calendar time adjustments. 11 + 12 + {{!spans}Time spans} represent non-negative monotonic time spans 13 + between two monotonic clock readings. {{!timestamps}Timestamps} 14 + represent system-relative monotonic {e timestamps}, their absolute 15 + value is meaningless but they can be compared across the processes 16 + of an operating system run. 17 + 18 + {!Mtime_clock} provides access to a system monotonic clock. *) 19 + 20 + (** {1:spans Monotonic time spans} *) 21 + 22 + type span 23 + (** The type for non-negative monotonic time spans. They represent the 24 + difference between two monotonic clock readings. If the platform's 25 + clock has nanosecond resolution the representation guarantees that 26 + the function {!Mtime_clock.elapsed} can measure up to 27 + approximatively 584 Julian year spans before silently rolling over 28 + (unlikely since this is in a single program run). *) 29 + 30 + (** Monotonic time spans. *) 31 + module Span : sig 32 + 33 + (** {1:spans Monotonic time spans} *) 34 + 35 + type t = span 36 + (** See {!Mtime.type-span}. *) 37 + 38 + val zero : span 39 + (** [zero] is a span of 0ns. *) 40 + 41 + val one : span 42 + (** [one] is a span of 1ns. *) 43 + 44 + val min_span : span 45 + (** [min_span] is {!zero}. *) 46 + 47 + val max_span : span 48 + (** [max_span] is 2{^64}-1ns. *) 49 + 50 + (** {1:preds Predicates} *) 51 + 52 + val equal : span -> span -> bool 53 + (** [equal span span'] is [true] iff [span] and [span'] are equal. *) 54 + 55 + val compare : span -> span -> int 56 + (** [compare span span'] orders spans by increasing duration. *) 57 + 58 + val is_shorter : span -> than:span -> bool 59 + (** [is_shorter span ~than] is [true] iff [span] lasts less than [than]. *) 60 + 61 + val is_longer : span -> than:span -> bool 62 + (** [is_longer span ~than] is [true] iff [span] lasts more than [than]. *) 63 + 64 + (** {1:arith Arithmetic} *) 65 + 66 + val add : span -> span -> span 67 + (** [add span span'] is [span + span']. 68 + 69 + {b Warning.} Rolls over on overflow. *) 70 + 71 + val abs_diff : span -> span -> span 72 + (** [abs_diff span span'] is the absolute difference between 73 + [span] and [span']. *) 74 + 75 + (** {1:const Durations} *) 76 + 77 + val ( * ) : int -> span -> span 78 + (** [n * dur] is [n] times duration [dur]. 79 + 80 + {b Warning.} Does not check for overflow or that [n] is 81 + positive. *) 82 + 83 + val ns : span 84 + (** [ns] is a nanosecond duration, 1·10{^-9}s. 85 + @since 1.4.0 *) 86 + 87 + val us : span 88 + (** [us] is a microsecond duration, 1·10{^-6}s. 89 + @since 1.4.0 *) 90 + 91 + val ms : span 92 + (** [ms] is a millisecond duration, 1·10{^-3}s. 93 + @since 1.4.0 *) 94 + 95 + val s : span 96 + (** [s] is a second duration, 1s. 97 + @since 1.4.0 *) 98 + 99 + val min : span 100 + (** [min] is a minute duration, 60s. 101 + @since 1.4.0 *) 102 + 103 + val hour : span 104 + (** [hour] is an hour duration, 3600s. 105 + @since 1.4.0 *) 106 + 107 + val day : span 108 + (** [day] is a day duration, 86'400s. 109 + @since 1.4.0 *) 110 + 111 + val year : span 112 + (** [year] is a Julian year duration (365.25 days), 31'557'600s. *) 113 + 114 + (** {1:convert Converting} *) 115 + 116 + val to_uint64_ns : span -> int64 117 + (** [to_uint64_ns span] is [span] as an {e unsigned} 64-bit integer 118 + nanosecond span. *) 119 + 120 + val of_uint64_ns : int64 -> span 121 + (** [of_uint64_ns u] is the {e unsigned} 64-bit integer nanosecond 122 + span [u] as a span. *) 123 + 124 + val of_float_ns : float -> span option 125 + (** [of_float_ns f] is the positive floating point nanosecond span [f] as 126 + a span. This is [None] if [f] is negative, non finite, or 127 + larger or equal than 2{^53} (~104 days, the largest exact floating point 128 + integer). 129 + @since 2.0.0 *) 130 + 131 + val to_float_ns : span -> float 132 + (** [to_float_ns s] is [span] as a nanosecond floating point span. 133 + Note that if [s] is larger than 2{^53} (~104 days, the largest 134 + exact floating point integer) the result is an approximation and 135 + will not round trip with {!of_float_ns}. 136 + @since 2.0.0 *) 137 + 138 + (** {1:fmt Formatters} *) 139 + 140 + val pp : Format.formatter -> span -> unit 141 + (** [pp] formats spans according to their magnitude using SI 142 + prefixes on seconds and accepted non-SI units. Years are counted 143 + in Julian years (365.25 SI-accepted days) as 144 + {{:http://www.iau.org/publications/proceedings_rules/units/}defined} 145 + by the International Astronomical Union. 146 + 147 + Rounds towards positive infinity, i.e. over approximates, no 148 + duration is formatted shorter than it is. 149 + 150 + The output is UTF-8 encoded, it uses U+03BC for [µs] 151 + (10{^-6}[s]). *) 152 + 153 + val dump : Format.formatter -> t -> unit 154 + (** [dump ppf span] formats an unspecified raw representation of [span] 155 + on [ppf]. *) 156 + 157 + (**/**) 158 + 159 + val unsafe_of_uint64_ns_option : int64 option -> t option 160 + end 161 + 162 + (** {1:timestamps Monotonic timestamps} 163 + 164 + {b Note.} Only use timestamps if you need inter-process time 165 + correlation, otherwise prefer {!Mtime_clock.elapsed} and 166 + {{!Mtime_clock.counters}counters}. *) 167 + 168 + type t 169 + (** The type for monotonic timestamps relative to an indeterminate 170 + system-wide event (e.g. last startup). Their absolute value has no 171 + meaning but can be used for inter-process time correlation. *) 172 + 173 + val to_uint64_ns : t -> int64 174 + (** [to_uint64_ns t] is [t] as an {e unsigned} 64-bit integer 175 + nanosecond timestamp. The absolute value is meaningless. *) 176 + 177 + val of_uint64_ns : int64 -> t 178 + (** [to_uint64_ns t] is [t] is an {e unsigned} 64-bit integer 179 + nanosecond timestamp as a timestamp. 180 + 181 + {b Warning.} Timestamps returned by this function should only be 182 + used with other timestamp values that are know to come from the 183 + same operating system run. *) 184 + 185 + val min_stamp : t 186 + (** [min_stamp] is the earliest timestamp. *) 187 + 188 + val max_stamp : t 189 + (** [max_stamp] is the latest timestamp. *) 190 + 191 + (** {2:preds Predicates} *) 192 + 193 + val equal : t -> t -> bool 194 + (** [equal t t'] is [true] iff [t] and [t'] are equal. *) 195 + 196 + val compare : t -> t -> int 197 + (** [compare t t'] orders timestamps by increasing time. *) 198 + 199 + val is_earlier : t -> than:t -> bool 200 + (** [is_earlier t ~than] is [true] iff [t] occurred before [than]. *) 201 + 202 + val is_later : t -> than:t -> bool 203 + (** [is_later t ~than] is [true] iff [t] occurred after [than]. *) 204 + 205 + (** {2:arith Arithmetic} *) 206 + 207 + val span : t -> t -> span 208 + (** [span t t'] is the span between [t] and [t'] regardless of the 209 + order between [t] and [t']. *) 210 + 211 + val add_span : t -> span -> t option 212 + (** [add_span t s] is the timestamp [s] units later than [t] or [None] if 213 + the result overflows. *) 214 + 215 + val sub_span : t -> span -> t option 216 + (** [sub_span t s] is the timestamp [s] units earlier than [t] or 217 + [None] if the result underflows. *) 218 + 219 + (** {2:fmt Formatting} *) 220 + 221 + val pp : Format.formatter -> t -> unit 222 + (** [pp] formats [t] as an {e unsigned} 64-bit integer 223 + nanosecond timestamp. Note that the absolute value is 224 + meaningless. *) 225 + 226 + val dump : Format.formatter -> t -> unit 227 + (** [dump ppf t] formats an unspecified raw representation of [t] on 228 + [ppf]. *)
+1
vendor/opam/mtime/src/mtime.mllib
··· 1 + Mtime
+7
vendor/opam/mtime/src/mtime_top_init.ml
··· 1 + (*--------------------------------------------------------------------------- 2 + Copyright (c) 2015 The mtime programmers. All rights reserved. 3 + SPDX-License-Identifier: ISC 4 + ---------------------------------------------------------------------------*) 5 + 6 + #install_printer Mtime.pp;; 7 + #install_printer Mtime.Span.pp;;
+5
vendor/opam/mtime/src/top/dune
··· 1 + (library 2 + (name mtime_top) 3 + (public_name mtime.top) 4 + (modules Mtime_top) 5 + (libraries compiler-libs.toplevel mtime))
+6
vendor/opam/mtime/src/top/mtime_top.ml
··· 1 + (*--------------------------------------------------------------------------- 2 + Copyright (c) 2015 The mtime programmers. All rights reserved. 3 + SPDX-License-Identifier: ISC 4 + ---------------------------------------------------------------------------*) 5 + 6 + let () = ignore (Toploop.use_file Format.err_formatter "mtime_top_init.ml")
+1
vendor/opam/mtime/src/top/mtime_top.mllib
··· 1 + Mtime_top
+23
vendor/opam/mtime/test/min_clock.ml
··· 1 + (* 2 + Compile with: 3 + 4 + ocamlfind ocamlopt \ 5 + -package mtime.clock -linkpkg -o min_clock.native min_clock.ml 6 + 7 + ocamlfind ocamlc \ 8 + -package mtime.clock -linkpkg -o min_clock.byte min_clock.ml 9 + 10 + js_of_ocaml \ 11 + $(ocamlfind query -format "%+(jsoo_runtime)" -r mtime.clock) \ 12 + min_clock.byte 13 + *) 14 + 15 + let main () = 16 + Format.printf "Elapsed: %a@." Mtime.Span.pp (Mtime_clock.elapsed ()); 17 + Format.printf "Timestamp: %a@." Mtime.pp (Mtime_clock.now ()); 18 + Format.printf "Clock period: %s@." 19 + (match Mtime_clock.period () with 20 + | None -> "unknown" | Some s -> Format.asprintf "%a" Mtime.Span.pp s); 21 + () 22 + 23 + let () = if !Sys.interactive then () else main ()
+283
vendor/opam/mtime/test/test_mtime.ml
··· 1 + (*--------------------------------------------------------------------------- 2 + Copyright (c) 2015 The mtime programmers. All rights reserved. 3 + SPDX-License-Identifier: ISC 4 + ---------------------------------------------------------------------------*) 5 + 6 + open B0_testing 7 + 8 + let test_pp_span = 9 + Test.test "Mtime.pp_span" @@ fun () -> 10 + (* The floating point stuff here comes from the previous incarnations 11 + of the formatter. Let's keep that it exercices a bit the of_float_ns. *) 12 + let pp s = 13 + let s = Option.get (Mtime.Span.of_float_ns (s *. 1e+9)) in 14 + Format.asprintf "%a" Mtime.Span.pp s 15 + in 16 + (* sub ns scale *) 17 + Test.string ~__POS__ (pp 1.0e-10) "0ns"; 18 + Test.string ~__POS__ (pp 4.0e-10) "0ns"; 19 + Test.string ~__POS__ (pp 6.0e-10) "0ns"; 20 + Test.string ~__POS__ (pp 9.0e-10) "0ns"; 21 + (* ns scale *) 22 + Test.string ~__POS__ (pp 2.0e-9) "2ns"; 23 + Test.string ~__POS__ (pp 2.136767676e-9) "2ns"; 24 + Test.string ~__POS__ (pp 2.6e-9) "2ns"; 25 + Test.string ~__POS__ (pp 2.836767676e-9) "2ns"; 26 + (* us scale *) 27 + Test.string ~__POS__ (pp 2.0e-6) "2μs"; 28 + Test.string ~__POS__ (pp 2.555e-6) "2.56μs"; 29 + Test.string ~__POS__ (pp 2.5556e-6) "2.56μs"; 30 + Test.string ~__POS__ (pp 99.9994e-6) "100μs"; 31 + Test.string ~__POS__ (pp 99.9996e-6) "100μs"; 32 + Test.string ~__POS__ (pp 100.1555e-6) "101μs"; 33 + Test.string ~__POS__ (pp 100.5555e-6) "101μs"; 34 + Test.string ~__POS__ (pp 100.6555e-6) "101μs"; 35 + Test.string ~__POS__ (pp 999.4e-6) "1ms"; 36 + Test.string ~__POS__ (pp 999.6e-6) "1ms"; 37 + (* ms scale *) 38 + Test.string ~__POS__ (pp 1e-3) "1ms"; 39 + Test.string ~__POS__ (pp 1.555e-3) "1.56ms"; 40 + Test.string ~__POS__ (pp 1.5556e-3) "1.56ms"; 41 + Test.string ~__POS__ (pp 99.9994e-3) "100ms"; 42 + Test.string ~__POS__ (pp 99.9996e-3) "100ms"; 43 + Test.string ~__POS__ (pp 100.1555e-3) "101ms"; 44 + Test.string ~__POS__ (pp 100.5555e-3) "101ms"; 45 + Test.string ~__POS__ (pp 100.6555e-3) "101ms"; 46 + Test.string ~__POS__ (pp 999.4e-3) "1s"; 47 + Test.string ~__POS__ (pp 999.6e-3) "1s"; 48 + (* s scale *) 49 + Test.string ~__POS__ (pp 1.) "1s"; 50 + Test.string ~__POS__ (pp 1.555) "1.56s"; 51 + Test.string ~__POS__ (pp 1.5554) "1.56s"; 52 + Test.string ~__POS__ (pp 1.5556) "1.56s"; 53 + Test.string ~__POS__ (pp 59.) "59s"; 54 + Test.string ~__POS__ (pp 59.9994) "1min"; 55 + Test.string ~__POS__ (pp 59.9996) "1min"; 56 + (* min scale *) 57 + Test.string ~__POS__ (pp 60.) "1min"; 58 + Test.string ~__POS__ (pp 62.) "1min2s"; 59 + Test.string ~__POS__ (pp 62.4) "1min3s"; 60 + Test.string ~__POS__ (pp 3599.) "59min59s"; 61 + (* hour scale *) 62 + Test.string ~__POS__ (pp 3600.0) "1h"; 63 + Test.string ~__POS__ (pp 3629.0) "1h1min"; 64 + Test.string ~__POS__ (pp 3660.0) "1h1min"; 65 + Test.string ~__POS__ (pp 7164.0) "2h"; 66 + Test.string ~__POS__ (pp 7200.0) "2h"; 67 + Test.string ~__POS__ (pp 86399.) "1d"; 68 + (* day scale *) 69 + Test.string ~__POS__ (pp 86400.) "1d"; 70 + Test.string ~__POS__ (pp (86400. +. (23. *. 3600.))) "1d23h"; 71 + Test.string ~__POS__ (pp (86400. +. (24. *. 3600.))) "2d"; 72 + (* These tests come from the b0 Fmt.uint64_ns_span tes *); 73 + let span s = 74 + Format.asprintf "%a" 75 + Mtime.Span.pp (Mtime.Span.of_uint64_ns (Int64.of_string s)); 76 + in 77 + Test.string ~__POS__ (span "0u0") "0ns"; 78 + Test.string ~__POS__ (span "0u999") "999ns"; 79 + Test.string ~__POS__ (span "0u1_000") "1μs"; 80 + Test.string ~__POS__ (span "0u1_001") "1.01μs"; 81 + Test.string ~__POS__ (span "0u1_009") "1.01μs"; 82 + Test.string ~__POS__ (span "0u1_010") "1.01μs"; 83 + Test.string ~__POS__ (span "0u1_011") "1.02μs"; 84 + Test.string ~__POS__ (span "0u1_090") "1.09μs"; 85 + Test.string ~__POS__ (span "0u1_091") "1.1μs"; 86 + Test.string ~__POS__ (span "0u1_100") "1.1μs"; 87 + Test.string ~__POS__ (span "0u1_101") "1.11μs"; 88 + Test.string ~__POS__ (span "0u1_109") "1.11μs"; 89 + Test.string ~__POS__ (span "0u1_110") "1.11μs"; 90 + Test.string ~__POS__ (span "0u1_111") "1.12μs"; 91 + Test.string ~__POS__ (span "0u1_990") "1.99μs"; 92 + Test.string ~__POS__ (span "0u1_991") "2μs"; 93 + Test.string ~__POS__ (span "0u1_999") "2μs"; 94 + Test.string ~__POS__ (span "0u2_000") "2μs"; 95 + Test.string ~__POS__ (span "0u2_001") "2.01μs"; 96 + Test.string ~__POS__ (span "0u9_990") "9.99μs"; 97 + Test.string ~__POS__ (span "0u9_991") "10μs"; 98 + Test.string ~__POS__ (span "0u9_999") "10μs"; 99 + Test.string ~__POS__ (span "0u10_000") "10μs"; 100 + Test.string ~__POS__ (span "0u10_001") "10.1μs"; 101 + Test.string ~__POS__ (span "0u10_099") "10.1μs"; 102 + Test.string ~__POS__ (span "0u10_100") "10.1μs"; 103 + Test.string ~__POS__ (span "0u10_101") "10.2μs"; 104 + Test.string ~__POS__ (span "0u10_900") "10.9μs"; 105 + Test.string ~__POS__ (span "0u10_901") "11μs"; 106 + Test.string ~__POS__ (span "0u10_999") "11μs"; 107 + Test.string ~__POS__ (span "0u11_000") "11μs"; 108 + Test.string ~__POS__ (span "0u11_001") "11.1μs"; 109 + Test.string ~__POS__ (span "0u11_099") "11.1μs"; 110 + Test.string ~__POS__ (span "0u11_100") "11.1μs"; 111 + Test.string ~__POS__ (span "0u11_101") "11.2μs"; 112 + Test.string ~__POS__ (span "0u99_900") "99.9μs"; 113 + Test.string ~__POS__ (span "0u99_901") "100μs"; 114 + Test.string ~__POS__ (span "0u99_999") "100μs"; 115 + Test.string ~__POS__ (span "0u100_000") "100μs"; 116 + Test.string ~__POS__ (span "0u100_001") "101μs"; 117 + Test.string ~__POS__ (span "0u100_999") "101μs"; 118 + Test.string ~__POS__ (span "0u101_000") "101μs"; 119 + Test.string ~__POS__ (span "0u101_001") "102μs"; 120 + Test.string ~__POS__ (span "0u101_999") "102μs"; 121 + Test.string ~__POS__ (span "0u102_000") "102μs"; 122 + Test.string ~__POS__ (span "0u999_000") "999μs"; 123 + Test.string ~__POS__ (span "0u999_001") "1ms"; 124 + Test.string ~__POS__ (span "0u999_001") "1ms"; 125 + Test.string ~__POS__ (span "0u999_999") "1ms"; 126 + Test.string ~__POS__ (span "0u1_000_000") "1ms"; 127 + Test.string ~__POS__ (span "0u1_000_001") "1.01ms"; 128 + Test.string ~__POS__ (span "0u1_009_999") "1.01ms"; 129 + Test.string ~__POS__ (span "0u1_010_000") "1.01ms"; 130 + Test.string ~__POS__ (span "0u1_010_001") "1.02ms"; 131 + Test.string ~__POS__ (span "0u9_990_000") "9.99ms"; 132 + Test.string ~__POS__ (span "0u9_990_001") "10ms"; 133 + Test.string ~__POS__ (span "0u9_999_999") "10ms"; 134 + Test.string ~__POS__ (span "0u10_000_000") "10ms"; 135 + Test.string ~__POS__ (span "0u10_000_001") "10.1ms"; 136 + Test.string ~__POS__ (span "0u10_000_001") "10.1ms"; 137 + Test.string ~__POS__ (span "0u10_099_999") "10.1ms"; 138 + Test.string ~__POS__ (span "0u10_100_000") "10.1ms"; 139 + Test.string ~__POS__ (span "0u10_100_001") "10.2ms"; 140 + Test.string ~__POS__ (span "0u99_900_000") "99.9ms"; 141 + Test.string ~__POS__ (span "0u99_900_001") "100ms"; 142 + Test.string ~__POS__ (span "0u99_999_999") "100ms"; 143 + Test.string ~__POS__ (span "0u100_000_000") "100ms"; 144 + Test.string ~__POS__ (span "0u100_000_001") "101ms"; 145 + Test.string ~__POS__ (span "0u100_999_999") "101ms"; 146 + Test.string ~__POS__ (span "0u101_000_000") "101ms"; 147 + Test.string ~__POS__ (span "0u101_000_001") "102ms"; 148 + Test.string ~__POS__ (span "0u999_000_000") "999ms"; 149 + Test.string ~__POS__ (span "0u999_000_001") "1s"; 150 + Test.string ~__POS__ (span "0u999_999_999") "1s"; 151 + Test.string ~__POS__ (span "0u1_000_000_000") "1s"; 152 + Test.string ~__POS__ (span "0u1_000_000_001") "1.01s"; 153 + Test.string ~__POS__ (span "0u1_009_999_999") "1.01s"; 154 + Test.string ~__POS__ (span "0u1_010_000_000") "1.01s"; 155 + Test.string ~__POS__ (span "0u1_010_000_001") "1.02s"; 156 + Test.string ~__POS__ (span "0u1_990_000_000") "1.99s"; 157 + Test.string ~__POS__ (span "0u1_990_000_001") "2s"; 158 + Test.string ~__POS__ (span "0u1_999_999_999") "2s"; 159 + Test.string ~__POS__ (span "0u2_000_000_000") "2s"; 160 + Test.string ~__POS__ (span "0u2_000_000_001") "2.01s"; 161 + Test.string ~__POS__ (span "0u9_990_000_000") "9.99s"; 162 + Test.string ~__POS__ (span "0u9_999_999_999") "10s"; 163 + Test.string ~__POS__ (span "0u10_000_000_000") "10s"; 164 + Test.string ~__POS__ (span "0u10_000_000_001") "10.1s"; 165 + Test.string ~__POS__ (span "0u10_099_999_999") "10.1s"; 166 + Test.string ~__POS__ (span "0u10_100_000_000") "10.1s"; 167 + Test.string ~__POS__ (span "0u10_100_000_001") "10.2s"; 168 + Test.string ~__POS__ (span "0u59_900_000_000") "59.9s"; 169 + Test.string ~__POS__ (span "0u59_900_000_001") "1min"; 170 + Test.string ~__POS__ (span "0u59_999_999_999") "1min"; 171 + Test.string ~__POS__ (span "0u60_000_000_000") "1min"; 172 + Test.string ~__POS__ (span "0u60_000_000_001") "1min1s"; 173 + Test.string ~__POS__ (span "0u60_999_999_999") "1min1s"; 174 + Test.string ~__POS__ (span "0u61_000_000_000") "1min1s"; 175 + Test.string ~__POS__ (span "0u61_000_000_001") "1min2s"; 176 + Test.string ~__POS__ (span "0u119_000_000_000") "1min59s"; 177 + Test.string ~__POS__ (span "0u119_000_000_001") "2min"; 178 + Test.string ~__POS__ (span "0u119_999_999_999") "2min"; 179 + Test.string ~__POS__ (span "0u120_000_000_000") "2min"; 180 + Test.string ~__POS__ (span "0u120_000_000_001") "2min1s"; 181 + Test.string ~__POS__ (span "0u3599_000_000_000") "59min59s"; 182 + Test.string ~__POS__ (span "0u3599_000_000_001") "1h"; 183 + Test.string ~__POS__ (span "0u3599_999_999_999") "1h"; 184 + Test.string ~__POS__ (span "0u3600_000_000_000") "1h"; 185 + Test.string ~__POS__ (span "0u3600_000_000_001") "1h1min"; 186 + Test.string ~__POS__ (span "0u3659_000_000_000") "1h1min"; 187 + Test.string ~__POS__ (span "0u3659_000_000_001") "1h1min"; 188 + Test.string ~__POS__ (span "0u3659_999_999_999") "1h1min"; 189 + Test.string ~__POS__ (span "0u3660_000_000_000") "1h1min"; 190 + Test.string ~__POS__ (span "0u3660_000_000_001") "1h2min"; 191 + Test.string ~__POS__ (span "0u3660_000_000_001") "1h2min"; 192 + Test.string ~__POS__ (span "0u3660_000_000_001") "1h2min"; 193 + Test.string ~__POS__ (span "0u3720_000_000_000") "1h2min"; 194 + Test.string ~__POS__ (span "0u3720_000_000_001") "1h3min"; 195 + Test.string ~__POS__ (span "0u7140_000_000_000") "1h59min"; 196 + Test.string ~__POS__ (span "0u7140_000_000_001") "2h"; 197 + Test.string ~__POS__ (span "0u7199_999_999_999") "2h"; 198 + Test.string ~__POS__ (span "0u7200_000_000_000") "2h"; 199 + Test.string ~__POS__ (span "0u7200_000_000_001") "2h1min"; 200 + Test.string ~__POS__ (span "0u86340_000_000_000") "23h59min"; 201 + Test.string ~__POS__ (span "0u86340_000_000_001") "1d"; 202 + Test.string ~__POS__ (span "0u86400_000_000_000") "1d"; 203 + Test.string ~__POS__ (span "0u86400_000_000_001") "1d1h"; 204 + Test.string ~__POS__ (span "0u89999_999_999_999") "1d1h"; 205 + Test.string ~__POS__ (span "0u90000_000_000_000") "1d1h"; 206 + Test.string ~__POS__ (span "0u90000_000_000_001") "1d2h"; 207 + Test.string ~__POS__ (span "0u169200_000_000_000") "1d23h"; 208 + Test.string ~__POS__ (span "0u169200_000_000_001") "2d"; 209 + Test.string ~__POS__ (span "0u169200_000_000_001") "2d"; 210 + Test.string ~__POS__ (span "0u172799_999_999_999") "2d"; 211 + Test.string ~__POS__ (span "0u172800_000_000_000") "2d"; 212 + Test.string ~__POS__ (span "0u172800_000_000_001") "2d1h"; 213 + Test.string ~__POS__ (span "0u31536000_000_000_000") "365d"; 214 + Test.string ~__POS__ (span "0u31554000_000_000_000") "365d5h"; 215 + Test.string ~__POS__ ( 216 + (* Technically this should round to a year but it does get rendered. 217 + I don't think it matters, it's not inacurate per se. *) 218 + span "0u31554000_000_000_001") "365d6h"; 219 + Test.string ~__POS__ (span "0u31557600_000_000_000") "1a"; 220 + Test.string ~__POS__ (span "0u31557600_000_000_001") "1a1d"; 221 + Test.string ~__POS__ (span "0u63028800_000_000_000") "1a365d"; 222 + Test.string ~__POS__ (span "0u63093600_000_000_000") "1a365d"; 223 + Test.string ~__POS__ (span "0u63093600_000_000_001") "2a"; 224 + Test.string ~__POS__ (span "0u63115200_000_000_000") "2a"; 225 + Test.string ~__POS__ (span "0u63115200_000_000_001") "2a1d"; 226 + () 227 + 228 + let test_span_compare = 229 + Test.test "Mtime.Span.{compare,is_shorter,is_longer}" @@ fun () -> 230 + let zero_mtime = Mtime.Span.of_uint64_ns 0_L in 231 + let large_mtime = Mtime.Span.of_uint64_ns Int64.max_int in 232 + let larger_mtime = Mtime.Span.of_uint64_ns Int64.min_int in 233 + let max_mtime = Mtime.Span.of_uint64_ns (-1_L) in 234 + let test_less_than fn = 235 + let (<) = fn in 236 + assert (zero_mtime < large_mtime); 237 + assert (zero_mtime < larger_mtime); 238 + assert (zero_mtime < max_mtime); 239 + assert (large_mtime < larger_mtime); 240 + assert (large_mtime < max_mtime); 241 + assert (larger_mtime < max_mtime); 242 + () 243 + in 244 + test_less_than (fun x y -> Mtime.Span.compare x y < 0); 245 + test_less_than (fun x y -> Mtime.Span.is_shorter x ~than:y); 246 + test_less_than (fun x y -> Mtime.Span.compare y x > 0); 247 + test_less_than (fun x y -> Mtime.Span.is_longer y ~than:x); 248 + () 249 + 250 + let test_span_constants = 251 + Test.test "Mtime.Span.{zero,one,max_span,min_span}" @@ fun () -> 252 + let (<) x y = Mtime.Span.compare x y < 0 in 253 + assert (Mtime.Span.zero < Mtime.Span.one); 254 + assert (Mtime.Span.zero < Mtime.Span.max_span); 255 + assert (Mtime.Span.min_span < Mtime.Span.one); 256 + assert (Mtime.Span.min_span < Mtime.Span.max_span); 257 + assert (Mtime.Span.one < Mtime.Span.max_span); 258 + () 259 + 260 + let test_span_arith = 261 + Test.test "Mtime.Span.{abs_diff,add}" @@ fun () -> 262 + assert (Mtime.Span.(equal (add zero one) one)); 263 + assert (Mtime.Span.(equal (add one zero) one)); 264 + assert (Mtime.Span.(equal (add (abs_diff max_span one) one) max_span)); 265 + () 266 + 267 + let test_float_ns = 268 + Test.test "Mtime.{to,of}_float_ns" @@ fun () -> 269 + assert (Mtime.Span.to_float_ns Mtime.Span.max_span = (2. ** 64.) -. 1.); 270 + assert (Mtime.Span.to_float_ns Mtime.Span.min_span = 0.); 271 + assert (Mtime.Span.of_float_ns (2. ** 53. -. 1.) = 272 + Some (Mtime.Span.of_uint64_ns (Int64.(sub (shift_left 1L 53) one)))); 273 + assert (Mtime.Span.of_float_ns (2. ** 53.) = None); 274 + assert (Mtime.Span.of_float_ns 0. = Some Mtime.Span.zero); 275 + assert (Mtime.Span.of_float_ns (-.0.) = Some Mtime.Span.zero); 276 + assert (Mtime.Span.of_float_ns infinity = None); 277 + assert (Mtime.Span.of_float_ns nan = None); 278 + assert (Mtime.Span.of_float_ns (-3.) = None); 279 + assert (Mtime.Span.of_float_ns 1. = Some Mtime.Span.one); 280 + () 281 + 282 + let main () = Test.main @@ fun () -> Test.autorun () 283 + let () = if !Sys.interactive then () else exit (main ())
+55
vendor/opam/mtime/test/test_mtime_clock.ml
··· 1 + (*--------------------------------------------------------------------------- 2 + Copyright (c) 2015 The mtime programmers. All rights reserved. 3 + SPDX-License-Identifier: ISC 4 + ---------------------------------------------------------------------------*) 5 + 6 + open B0_testing 7 + 8 + (* Note nothing is being asserted in these tests. *) 9 + 10 + let test_available () = try ignore (Mtime_clock.elapsed ()) with 11 + | Sys_error e -> Test.failstop "No monotonic time available: %s" e 12 + 13 + let test_counters = 14 + Test.test "Mtime_clock.counter" @@ fun () -> 15 + let count max = 16 + let c = Mtime_clock.counter () in 17 + for i = 1 to max do () done; 18 + Mtime_clock.count c 19 + in 20 + let do_count max = 21 + let span = count max in 22 + let span_ns = Mtime.Span.to_uint64_ns span in 23 + Test.log "Count to % 8d: %10Luns %gs %a" 24 + max span_ns (Mtime.Span.to_float_ns span *. 1e-9) Mtime.Span.pp span 25 + in 26 + do_count 1000000; 27 + do_count 100000; 28 + do_count 10000; 29 + do_count 1000; 30 + do_count 100; 31 + do_count 10; 32 + do_count 1; 33 + () 34 + 35 + let test_elapsed = 36 + Test.test "Mtime_clock.elapsed ns - s - pp - dump" @@ fun () -> 37 + let span = Mtime_clock.elapsed () in 38 + Test.log " %Luns - %gs - %a - %a" 39 + (Mtime.Span.to_uint64_ns span) 40 + (Mtime.Span.to_float_ns span *. 1e-9) 41 + Mtime.Span.pp span 42 + Mtime.Span.dump span; 43 + () 44 + 45 + let test_now = 46 + Test.test "Mtime_clock.now ns - s - pp - dump " @@ fun () -> 47 + let t = Mtime_clock.now () in 48 + let span = Mtime.(span t (of_uint64_ns 0_L)) in 49 + Test.log " %Luns - %gs - %a - %a" 50 + (Mtime.to_uint64_ns t) (Mtime.Span.to_float_ns span *. 1e-9) 51 + Mtime.pp t Mtime.dump t; 52 + () 53 + 54 + let main () = Test.main @@ fun () -> Test.autorun () 55 + let () = if !Sys.interactive then () else exit (main ())