Skip to content

Commit ffa0874

Browse files
authored
Merge pull request #57 from patricoferris/use-trace-fuchsia
Use trace instead of tracing
2 parents 088ce54 + e2a633e commit ffa0874

5 files changed

Lines changed: 41 additions & 24 deletions

File tree

dune-project

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
(ocaml (>= "5.0.0~"))
2020
hdr_histogram
2121
(cmdliner (>= 1.1.0))
22-
tracing
23-
(ocaml_intrinsics (>= v0.16.1))
22+
(trace-fuchsia (>= 0.10))
2423
(menhir :with-test)
2524
(alcotest (and :with-test (>= 1.9.0)))))
2625

lib/olly_trace/olly_format_backend/dune

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@
1111
(name olly_format_fuchsia)
1212
(modules olly_format_fuchsia)
1313
(optional)
14-
(libraries olly_format_backend tracing))
14+
(libraries olly_format_backend trace trace-fuchsia))
Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,56 @@
11
open Olly_format_backend
2-
open Tracing
32

43
let name = "fuchsia"
54
let description = "Perfetto"
65

7-
type trace = { doms : Trace.Thread.t array; file : Trace.t }
6+
module Trace = Trace_fuchsia.Writer
7+
8+
type trace = {
9+
doms : Trace.Thread_ref.t array;
10+
buf : Trace_fuchsia.Buf_chain.t;
11+
subscriber : Trace_fuchsia.Subscriber.t;
12+
exporter : Trace_fuchsia.Exporter.t;
13+
}
14+
15+
let flush trace =
16+
Trace_fuchsia.Buf_chain.ready_all_non_empty trace.buf;
17+
Trace_fuchsia.Buf_chain.pop_ready trace.buf ~f:trace.exporter.write_bufs;
18+
trace.exporter.flush ()
819

920
let create ~filename =
10-
let file = Trace.create_for_file ~base_time:None ~filename in
21+
let buf_pool = Trace_fuchsia.Buf_pool.create () in
22+
let buf = Trace_fuchsia.Buf_chain.create ~sharded:false ~buf_pool () in
23+
let oc = Out_channel.open_bin filename in
24+
let exporter = Trace_fuchsia.Exporter.of_out_channel ~close_channel:true oc in
25+
let subscriber = Trace_fuchsia.Subscriber.create ~buf_pool ~pid:0 ~exporter () in
26+
(* Adds the headers to output *)
27+
Trace_fuchsia.Subscriber.Callbacks.on_init subscriber ~time_ns:0L;
1128
let doms =
1229
let max_doms = 128 in
1330
Array.init max_doms (fun i ->
1431
(* Use a different pid for each domain *)
15-
Trace.allocate_thread file ~pid:i ~name:(Printf.sprintf "Ring_id %d" i))
32+
Trace.Thread_ref.ref (i + 1))
1633
in
17-
{ doms; file }
34+
{ doms; buf; subscriber; exporter }
1835

19-
let close trace = Trace.close trace.file
20-
let ts_to_span ts = ts |> Int64.to_int |> Core.Time_ns.Span.of_int_ns
36+
let close trace =
37+
flush trace;
38+
Trace_fuchsia.Subscriber.close trace.subscriber
2139

2240
let emit trace evt =
2341
let open Event in
24-
let thread = trace.doms.(evt.ring_id)
25-
and category = "PERF"
26-
and time = ts_to_span evt.ts
42+
let t_ref = trace.doms.(evt.ring_id)
43+
and time_ns = evt.ts
2744
and name = evt.name in
2845
match evt.kind with
2946
| SpanBegin | SpanEnd ->
3047
let write =
31-
if evt.kind = SpanBegin then Trace.write_duration_begin
32-
else Trace.write_duration_end
48+
if evt.kind = SpanBegin then Trace.Event.Duration_begin.encode
49+
else Trace.Event.Duration_end.encode
3350
in
34-
write trace.file ~args:[] ~thread ~category ~name ~time
51+
write trace.buf ~args:[] ~t_ref ~name ~time_ns ()
3552
| Counter value ->
36-
Trace.write_counter trace.file ~thread ~category ~name ~time
37-
~args:[ ("v", Int value) ]
53+
Trace.Event.Counter.encode trace.buf ~t_ref ~name ~time_ns ~args:[ ("v", A_int value) ] ()
3854
| Instant ->
39-
Trace.write_duration_instant trace.file ~args:[] ~thread ~category ~name
40-
~time
55+
Trace.Event.Instant.encode trace.buf ~name ~args:[] ~t_ref ~time_ns ()
4156
| _ -> ()

runtime_events_tools.opam

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ depends: [
1313
"ocaml" {>= "5.0.0~"}
1414
"hdr_histogram"
1515
"cmdliner" {>= "1.1.0"}
16-
"tracing"
17-
"ocaml_intrinsics" {>= "v0.16.1"}
16+
"trace-fuchsia" {>= "0.10"}
1817
"menhir" {with-test}
1918
"alcotest" {with-test & >= "1.9.0"}
2019
"odoc" {with-doc}

test/dune

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,19 @@
5656
(run olly_bare trace --format=json test-bare-json.trace ./test_fib.exe))))
5757

5858
; Dummy process for testing process launching.
59+
5960
(executables
6061
(names run_endlessly)
62+
(modules run_endlessly)
6163
(libraries unix))
6264

6365
(test
6466
(name test_launch)
67+
(modules test_launch)
6568
(package runtime_events_tools)
6669
(enabled_if
6770
(>= %{ocaml_version} 5.1.0))
6871
(libraries olly_common alcotest)
69-
(deps run_endlessly.exe)
70-
(action (run %{test} --show-errors)))
72+
(deps run_endlessly.exe)
73+
(action
74+
(run %{test} --show-errors)))

0 commit comments

Comments
 (0)