Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ jobs:
strategy:
matrix:
ocaml-compiler:
- 5.0
- 5.1
- 5.2
- 5.3
os:
- ubuntu-latest
- macos-15
- macos-latest

runs-on: ${{ matrix.os }}

Expand Down
2 changes: 1 addition & 1 deletion .ocamlformat
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = 0.27.0
profile = conventional

ocaml-version = 5.2.0
ocaml-version = 5.0.0
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ Percentile Latency (ms)
99.9990 72.55
99.9999 72.55
100.0000 72.55

GC allocations (in words):
Total heap: 501516808
Minor heap: 602373895
Promoted words: 100857087 (16.74%)

Minor Gen: 904 collections
Major Gen: 34 collections 0 forced collections
Compactions: 0
```

### Tracing a program
Expand Down
5 changes: 3 additions & 2 deletions dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
(name runtime_events_tools)
(version "0.5.1")
(generate_opam_files true)
(cram enable)

(source
(github tarides/runtime_events_tools))
Expand All @@ -18,7 +19,7 @@
(depends
(ocaml (>= "5.0.0~"))
hdr_histogram
(cmdliner (>= 1.1.0))
(cmdliner (>= 1.3.0))
(trace-fuchsia (>= 0.10))
(trace (>= 0.10))
(menhir :with-test)
Expand All @@ -31,4 +32,4 @@
(description "Various tools for the runtime events tracing system in OCaml: minimal dependencies")
(depends
(ocaml (>= "5.0.0~"))
(cmdliner (>= 1.1.0))))
(cmdliner (>= 1.3.0))))
16 changes: 16 additions & 0 deletions lib/olly_common/cli.ml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,22 @@ let freq_option =
& opt float 0.1 (* Poll at 10Hz by default. *)
& info [ "freq" ] ~docv:"freq" ~doc)

let runtime_events_dir =
let doc =
"Sets the directory where the .events files containing the runtime event \
tracing system’s ring buffers will be located.\n\n\
\ If not specified a temporary directory will be used."
in
Arg.(value & opt (some string) None & info [ "d"; "dir" ] ~docv:"dir" ~doc)

let runtime_events_log_wsize =
let doc =
"Size of the per-domain runtime events ring buffers in log powers of two \
words. Defaults to 16."
in
Arg.(
value & opt (some int) None & info [ "log-wsize" ] ~docv:"log-wsize" ~doc)

let exec_args p =
let exec_and_args, ea_docv =
let doc = "Executable and arguments to trace." in
Expand Down
43 changes: 33 additions & 10 deletions lib/olly_common/launch.ml
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,23 @@ type subprocess = {
pid : int;
}

type runtime_events = { log_wsize : int option; dir : string option }
type exec_config = Attach of string * int | Execute of string list

(* Raised by exec_process to indicate various unrecoverable failures. *)
exception Fail of string

let exec_process (argsl : string list) : subprocess =
if not (List.length argsl > 0) then
let exec_process (config : runtime_events) args =
if not (List.length args > 0) then
raise (Fail (Printf.sprintf "no executable provided for exec_process"));

let executable_filename = List.hd argsl in
let executable_filename = List.hd args in

(* TODO Set the temp directory. We should make this configurable. *)
let dir = Filename.get_temp_dir_name () |> Unix.realpath in
let dir =
match config.dir with
| None -> Filename.get_temp_dir_name () |> Unix.realpath
| Some path -> Unix.realpath path
in
if not @@ Sys.file_exists dir then
raise (Fail (Printf.sprintf "directory %s does not exist" dir));
if not @@ Sys.is_directory dir then
Expand All @@ -29,15 +33,23 @@ let exec_process (argsl : string list) : subprocess =
let env =
Array.append
[|
(* See https://ocaml.org/manual/5.3/runtime-tracing.html#s:runtime-tracing-environment-variables *)
"OCAML_RUNTIME_EVENTS_START=1";
"OCAML_RUNTIME_EVENTS_DIR=" ^ dir;
"OCAML_RUNTIME_EVENTS_PRESERVE=1";
((* See https://ocaml.org/manual/5.3/runtime.html#s:ocamlrun-options *)
let log_wsize =
match config.log_wsize with
| Some i -> "e=" ^ Int.to_string i
| None -> ""
in
"OCAMLRUNPARAM=" ^ log_wsize);
|]
(Unix.environment ())
in
let child_pid =
try
Unix.create_process_env executable_filename (Array.of_list argsl) env
Unix.create_process_env executable_filename (Array.of_list args) env
Unix.stdin Unix.stdout Unix.stderr
with Unix.Unix_error (Unix.ENOENT, _, _) ->
raise
Expand Down Expand Up @@ -74,9 +86,9 @@ let attach_process (dir : string) (pid : int) : subprocess =
and close () = Runtime_events.free_cursor cursor in
{ alive; cursor; close; pid }

let launch_process (exec_args : exec_config) : subprocess =
let launch_process config (exec_args : exec_config) : subprocess =
match exec_args with
| Execute argsl -> exec_process argsl
| Execute argsl -> exec_process config argsl
| Attach (dir, pid) -> attach_process dir pid

let collect_events poll_sleep child callbacks =
Expand All @@ -99,6 +111,8 @@ type consumer_config = {
init : unit -> unit;
cleanup : unit -> unit;
poll_sleep : float;
runtime_events_dir : string option;
runtime_events_log_wsize : int option;
}

let empty_config =
Expand All @@ -111,12 +125,21 @@ let empty_config =
init = (fun () -> ());
cleanup = (fun () -> ());
poll_sleep = 0.1 (* Poll at 10Hz *);
runtime_events_dir = None (* Use default tmp directory *);
runtime_events_log_wsize = None;
(* Use default size 16. *)
}

let olly config (exec_args : exec_config) =
let olly config exec_args =
config.init ();
Fun.protect ~finally:config.cleanup (fun () ->
let child = launch_process exec_args in
let runtime_config =
{
dir = config.runtime_events_dir;
log_wsize = config.runtime_events_log_wsize;
}
in
let child = launch_process runtime_config exec_args in
Fun.protect ~finally:child.close (fun () ->
let callbacks =
let {
Expand Down
16 changes: 16 additions & 0 deletions lib/olly_gc_stats/dune
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,19 @@
(name olly_gc_stats)
(optional)
(libraries olly_common hdr_histogram))

(rule
(deps olly_gc_stats.5.0.ml)
(target olly_gc_impl.ml)
(enabled_if
(< %{ocaml_version} 5.3))
(action
(copy %{deps} %{target})))

(rule
(deps olly_gc_stats.5.3.ml)
(target olly_gc_impl.ml)
(enabled_if
(>= %{ocaml_version} 5.3))
(action
(copy %{deps} %{target})))
Loading
Loading