|
1 | 1 | open Olly_format_backend |
2 | | -open Tracing |
3 | 2 |
|
4 | 3 | let name = "fuchsia" |
5 | 4 | let description = "Perfetto" |
6 | 5 |
|
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 () |
8 | 19 |
|
9 | 20 | 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; |
11 | 28 | let doms = |
12 | 29 | let max_doms = 128 in |
13 | 30 | Array.init max_doms (fun i -> |
14 | 31 | (* 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)) |
16 | 33 | in |
17 | | - { doms; file } |
| 34 | + { doms; buf; subscriber; exporter } |
18 | 35 |
|
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 |
21 | 39 |
|
22 | 40 | let emit trace evt = |
23 | 41 | 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 |
27 | 44 | and name = evt.name in |
28 | 45 | match evt.kind with |
29 | 46 | | SpanBegin | SpanEnd -> |
30 | 47 | 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 |
33 | 50 | in |
34 | | - write trace.file ~args:[] ~thread ~category ~name ~time |
| 51 | + write trace.buf ~args:[] ~t_ref ~name ~time_ns () |
35 | 52 | | 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) ] () |
38 | 54 | | 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 () |
41 | 56 | | _ -> () |
0 commit comments