Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ocamldoc generation Better doc in oclock.mli Add a precision evaluation function in examples/realtime.ml Add one example examples/getcputime.ml Improve README Use markdown in README Add Findlib support Minor fix in error handling in pthread_getcpuclockid
- Loading branch information
Showing
10 changed files
with
206 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ | |
*.so | ||
*.byte | ||
*.opt | ||
/doc/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
verson = "0.2" | ||
description = "Oclock: Precise POSIX clock for Ocaml" | ||
archive(byte) = "oclock.cma" | ||
archive(native) = "oclock.cmxa" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
README.markdown |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
Oclock: precise POSIX clock for OCaml | ||
|
||
Mickaël Delahaye | ||
|
||
This module give access to the `clock_gettime (2)` family of functions to Ocaml | ||
programs. | ||
|
||
Requirements | ||
============ | ||
|
||
Just the usual suspects: GNU Make, GCC, OCaml, and optionally Findlib (i.e., | ||
ocamlfind). | ||
|
||
Installation | ||
============ | ||
|
||
$ make | ||
Build the library | ||
|
||
# make install | ||
Install the library in the standard ocaml directory | ||
|
||
Usage | ||
===== | ||
|
||
Manually: | ||
ocamlc -I +oclock oclock.cma ... | ||
ocamlopt -I +oclock oclock.cmxa ... | ||
|
||
Or with ocamlfind: | ||
ocamlfind ocamlc -package oclock ... | ||
ocamlfind ocamlopt -package oclock ... | ||
|
||
Documentation | ||
============= | ||
|
||
To build the API documentation in HTML, use: | ||
$ make doc | ||
Then, open `doc/index.html` with your favorite browser. | ||
|
||
Two examples are also provided in `examples`: | ||
|
||
* _getcputime_ gets the CPU-time consumed by a process given by its PID. | ||
* _realtime_ gets the real time since the Epoch, and evaluates the clock | ||
precision. | ||
|
||
License | ||
======= | ||
Copyright (c) 2010, Mickaël Delahaye <mickael.delahaye@gmail.com> | ||
|
||
Permission to use, copy, modify, and/or 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
(** Example of CPU-time measurement with Oclock *) | ||
|
||
let rec loop () = | ||
Printf.printf "PID? "; | ||
try | ||
let pid = read_int () in | ||
begin try | ||
let clk = Oclock.getcpuclockid pid in | ||
let time = Oclock.gettime clk in | ||
Printf.printf "The process %d used %Ld ns of CPU time up until now.\n\n" pid time; | ||
with Invalid_argument s | Failure s -> | ||
Printf.printf "Error: %s\n" s; | ||
end; | ||
loop (); | ||
with End_of_file -> | ||
Printf.printf "Bye!\n" | ||
|
||
let () = | ||
loop () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,39 @@ | ||
open Oclock | ||
(** Example of realtime measurement with Oclock *) | ||
|
||
(** Experimentally estimates the precision of a clock by observing gaps between | ||
[num] successive measures (by default 100000). | ||
Returns the observed (arithmetic) mean, the standard deviation, the minimal | ||
value and the maximal value. | ||
*) | ||
let measure_precision ?(num=100000) clkid = | ||
let t () = Oclock.gettime clkid in | ||
let measures = Array.make num 0L in | ||
for i = 0 to num - 1 do | ||
measures.(i) <- t (); | ||
done; | ||
let last = ref measures.(0) in | ||
let nb_diffs = ref 0 in | ||
let diffs = ref [] in | ||
for i = 1 to num - 1 do | ||
if measures.(i) <> !last then begin | ||
incr nb_diffs; | ||
diffs := Int64.to_float (Int64.sub measures.(i) !last) :: !diffs; | ||
last := measures.(i); | ||
end | ||
done; | ||
let n = float_of_int !nb_diffs in | ||
let mean = (List.fold_left (+.) 0.0 !diffs) /. n in | ||
let var = (List.fold_left (fun acc e -> (e -. mean) ** 2.0 +. acc) 0.0 !diffs) /. n in | ||
let min = List.fold_left min max_float !diffs in | ||
let max = List.fold_left max min_float !diffs in | ||
let stddev = var ** 0.5 in | ||
mean, stddev, min, max | ||
|
||
(** Gets time since Epoch and evaluates the precision of the clock *) | ||
let () = | ||
let nsecs = gettime realtime in | ||
let res = getres realtime in | ||
Printf.printf "%Ld ns (resolution %Ld ns)\n" nsecs res; | ||
let nsecs = Oclock.gettime Oclock.realtime in | ||
let res = Oclock.getres Oclock.realtime in | ||
Printf.printf "%Ld ns since the Epock (resolution %Ld ns)\n" nsecs res; | ||
|
||
let prec, precsv, max, min = measure_precision Oclock.realtime in | ||
Printf.printf "Precision evaluation\n Mean: %10.2f ns\n Sdev: %10.2f ns\n Min: %10.2f ns\n Max: %10.2f ns\n" prec precsv min max |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters