Skip to content

Commit

Permalink
Emit runtime counter events for tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
tmcgilchrist committed Feb 21, 2024
1 parent 5136e42 commit 2c553cc
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions bin/olly.ml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ let print_percentiles json output hist =
let lost_events ring_id num =
Printf.eprintf "[ring_id=%d] Lost %d events\n%!" ring_id num

let olly ?extra ~runtime_begin ~runtime_end ~cleanup ~lifecycle ~init exec_args
let olly ?extra ?runtime_counter ~runtime_begin ~runtime_end ~cleanup ~lifecycle ~init exec_args
=
let argsl = String.split_on_char ' ' exec_args in
let executable_filename = List.hd argsl in
Expand All @@ -123,7 +123,7 @@ let olly ?extra ~runtime_begin ~runtime_end ~cleanup ~lifecycle ~init exec_args
let cursor = Runtime_events.create_cursor (Some (tmp_dir, child_pid)) in
let callbacks =
Runtime_events.Callbacks.create ~runtime_begin ~runtime_end ~lifecycle
~lost_events ()
?runtime_counter ~lost_events ()
|> Option.value extra ~default:Fun.id
in
let child_alive () =
Expand Down Expand Up @@ -169,14 +169,22 @@ let trace format trace_filename exec_args =
(ts_to_us ts) ring_id ring_id;
flush trace_file
in
let runtime_counter ring_id ts counter_event i =
Printf.fprintf trace_file
"{\"name\" : \"%s\", \"ph\" : \"C\", \"ts\":%Ld,\
\"args\" : {\"value\" : \"%d\", \"pid\": %d, \"tid\": %d}}"
(Runtime_events.runtime_counter_name counter_event) (ts_to_us ts)
i ring_id ring_id;
flush trace_file
in
let extra = Olly_custom_events.v_json trace_file in
let init () =
(* emit prefix in the tracefile *)
Printf.fprintf trace_file "["
in
let cleanup () = close_out trace_file in
olly ~extra ~runtime_begin ~runtime_end ~init ~lifecycle ~cleanup
exec_args
~runtime_counter exec_args
| Fuchsia ->
let open Tracing in
let trace_file =
Expand Down Expand Up @@ -209,10 +217,21 @@ let trace format trace_filename exec_args =
~name:(Runtime_events.runtime_phase_name phase)
~time:(ts |> ts_to_int |> int_to_span)
in
let runtime_counter ring_id ts counter_event i =
let thread = doms.(ring_id) in
let args =
["value", Trace.Arg.Int i;
"pid", Trace.Arg.Int ring_id;
"tid", Trace.Arg.Int ring_id]
in
Trace.write_counter trace_file ~thread ~args ~category:"C"
~name:(Runtime_events.runtime_counter_name counter_event)
~time:(ts |> ts_to_int |> int_to_span)
in
let extra = Olly_custom_events.v trace_file doms in
let init () = () in
let cleanup () = Trace.close trace_file in
olly ~extra ~runtime_begin ~runtime_end ~init ~lifecycle ~cleanup
olly ~extra ~runtime_begin ~runtime_end ~init ~lifecycle ~runtime_counter ~cleanup
exec_args

let gc_stats json output exec_args =
Expand Down

0 comments on commit 2c553cc

Please sign in to comment.