mirror of
https://github.com/ocaml-tracing/ocaml-trace.git
synced 2026-03-08 03:47:57 -04:00
test: update and improve fuchsia tests
This commit is contained in:
parent
7acc1b930f
commit
86e65d2046
7 changed files with 62 additions and 32 deletions
1
test/fuchsia/t1.expected
Normal file
1
test/fuchsia/t1.expected
Normal file
File diff suppressed because one or more lines are too long
|
|
@ -43,6 +43,33 @@ let run () =
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
|
|
||||||
|
let to_hex (s : string) : string =
|
||||||
|
let i_to_hex (i : int) =
|
||||||
|
if i < 10 then
|
||||||
|
Char.chr (i + Char.code '0')
|
||||||
|
else
|
||||||
|
Char.chr (i - 10 + Char.code 'a')
|
||||||
|
in
|
||||||
|
|
||||||
|
let res = Bytes.create (2 * String.length s) in
|
||||||
|
for i = 0 to String.length s - 1 do
|
||||||
|
let n = Char.code (String.get s i) in
|
||||||
|
Bytes.set res (2 * i) (i_to_hex ((n land 0xf0) lsr 4));
|
||||||
|
Bytes.set res ((2 * i) + 1) (i_to_hex (n land 0x0f))
|
||||||
|
done;
|
||||||
|
Bytes.unsafe_to_string res
|
||||||
|
|
||||||
let () =
|
let () =
|
||||||
Trace_tef.Private_.mock_all_ ();
|
Trace_fuchsia.Internal_.mock_all_ ();
|
||||||
Trace_tef.with_setup ~out:`Stdout () @@ fun () -> run ()
|
let buf = Buffer.create 32 in
|
||||||
|
let exporter = Trace_fuchsia.Exporter.of_buffer buf in
|
||||||
|
Trace_fuchsia.with_setup ~out:(`Exporter exporter) () run;
|
||||||
|
exporter.close ();
|
||||||
|
|
||||||
|
let data = Buffer.contents buf in
|
||||||
|
(let oc = open_out_bin "t1.fxt" in
|
||||||
|
output_string oc data;
|
||||||
|
close_out_noerr oc);
|
||||||
|
|
||||||
|
print_endline (to_hex data);
|
||||||
|
flush stdout
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
(tests
|
(tests
|
||||||
(names t1 t2)
|
(names t1 t2)
|
||||||
(package trace-fuchsia)
|
(package trace-fuchsia)
|
||||||
(libraries trace-fuchsia.write))
|
(libraries trace-fuchsia))
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
open Trace_fuchsia_write
|
open Trace_fuchsia
|
||||||
|
|
||||||
module Str_ = struct
|
module Str_ = struct
|
||||||
open String
|
open String
|
||||||
|
|
@ -39,14 +39,14 @@ module Str_ = struct
|
||||||
end
|
end
|
||||||
|
|
||||||
let () =
|
let () =
|
||||||
let l = List.init 100 (fun i -> Util.round_to_word i) in
|
let l = List.init 100 (fun i -> Writer.Util.round_to_word i) in
|
||||||
assert (List.for_all (fun x -> x mod 8 = 0) l)
|
assert (List.for_all (fun x -> x mod 8 = 0) l)
|
||||||
|
|
||||||
let () =
|
let () =
|
||||||
assert (Str_ref.inline 0 = 0b0000_0000_0000_0000);
|
assert (Writer.Str_ref.inline 0 = 0b0000_0000_0000_0000);
|
||||||
assert (Str_ref.inline 1 = 0b1000_0000_0000_0001);
|
assert (Writer.Str_ref.inline 1 = 0b1000_0000_0000_0001);
|
||||||
assert (Str_ref.inline 6 = 0b1000_0000_0000_0110);
|
assert (Writer.Str_ref.inline 6 = 0b1000_0000_0000_0110);
|
||||||
assert (Str_ref.inline 31999 = 0b1111_1100_1111_1111);
|
assert (Writer.Str_ref.inline 31999 = 0b1111_1100_1111_1111);
|
||||||
()
|
()
|
||||||
|
|
||||||
let () =
|
let () =
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
open Trace_fuchsia_write
|
open Trace_fuchsia
|
||||||
|
open Trace_fuchsia.Writer
|
||||||
|
|
||||||
let pf = Printf.printf
|
let pf = Printf.printf
|
||||||
|
|
||||||
|
|
@ -40,24 +41,27 @@ module Str_ = struct
|
||||||
Bytes.unsafe_to_string res
|
Bytes.unsafe_to_string res
|
||||||
end
|
end
|
||||||
|
|
||||||
let with_buf_output (f : Output.t -> unit) : string =
|
let with_buf_chain (f : Buf_chain.t -> unit) : string =
|
||||||
let buf_pool = Buf_pool.create () in
|
let buf_pool = Buf_pool.create () in
|
||||||
let buffer = Buffer.create 32 in
|
let buffer = Buffer.create 32 in
|
||||||
let out = Output.into_buffer ~buf_pool buffer in
|
let buf_chain = Buf_chain.create ~sharded:true ~buf_pool () in
|
||||||
f out;
|
f buf_chain;
|
||||||
Output.flush out;
|
|
||||||
|
Buf_chain.ready_all_non_empty buf_chain;
|
||||||
|
let exp = Exporter.of_buffer buffer in
|
||||||
|
Buf_chain.pop_ready buf_chain ~f:exp.write_bufs;
|
||||||
Buffer.contents buffer
|
Buffer.contents buffer
|
||||||
|
|
||||||
let () = pf "first trace\n"
|
let () = pf "first trace\n"
|
||||||
|
|
||||||
let () =
|
let () =
|
||||||
let str =
|
let str =
|
||||||
with_buf_output (fun out ->
|
with_buf_chain (fun bufs ->
|
||||||
Metadata.Magic_record.encode out;
|
Metadata.Magic_record.encode bufs;
|
||||||
Thread_record.encode out ~as_ref:5 ~pid:1 ~tid:86 ();
|
Thread_record.encode bufs ~as_ref:5 ~pid:1 ~tid:86 ();
|
||||||
Event.Instant.encode out ~name:"hello" ~time_ns:1234_5678L
|
Event.Instant.encode bufs ~name:"hello" ~time_ns:1234_5678L
|
||||||
~t_ref:(Thread_ref.Ref 5)
|
~t_ref:(Thread_ref.Ref 5)
|
||||||
~args:[ "x", `Int 42 ]
|
~args:[ "x", A_int 42 ]
|
||||||
())
|
())
|
||||||
in
|
in
|
||||||
pf "%s\n" (Str_.to_hex str)
|
pf "%s\n" (Str_.to_hex str)
|
||||||
|
|
@ -66,21 +70,21 @@ let () = pf "second trace\n"
|
||||||
|
|
||||||
let () =
|
let () =
|
||||||
let str =
|
let str =
|
||||||
with_buf_output (fun out ->
|
with_buf_chain (fun bufs ->
|
||||||
Metadata.Magic_record.encode out;
|
Metadata.Magic_record.encode bufs;
|
||||||
Metadata.Initialization_record.(
|
Metadata.Initialization_record.(
|
||||||
encode out ~ticks_per_secs:default_ticks_per_sec ());
|
encode bufs ~ticks_per_secs:default_ticks_per_sec ());
|
||||||
Thread_record.encode out ~as_ref:5 ~pid:1 ~tid:86 ();
|
Thread_record.encode bufs ~as_ref:5 ~pid:1 ~tid:86 ();
|
||||||
Metadata.Provider_info.encode out ~id:1 ~name:"ocaml-trace" ();
|
Metadata.Provider_info.encode bufs ~id:1 ~name:"ocaml-trace" ();
|
||||||
Event.Duration_complete.encode out ~name:"outer"
|
Event.Duration_complete.encode bufs ~name:"outer"
|
||||||
~t_ref:(Thread_ref.Ref 5) ~time_ns:100_000L ~end_time_ns:5_000_000L
|
~t_ref:(Thread_ref.Ref 5) ~time_ns:100_000L ~end_time_ns:5_000_000L
|
||||||
~args:[] ();
|
~args:[] ();
|
||||||
Event.Duration_complete.encode out ~name:"inner"
|
Event.Duration_complete.encode bufs ~name:"inner"
|
||||||
~t_ref:(Thread_ref.Ref 5) ~time_ns:180_000L ~end_time_ns:4_500_000L
|
~t_ref:(Thread_ref.Ref 5) ~time_ns:180_000L ~end_time_ns:4_500_000L
|
||||||
~args:[] ();
|
~args:[] ();
|
||||||
Event.Instant.encode out ~name:"hello" ~time_ns:1_234_567L
|
Event.Instant.encode bufs ~name:"hello" ~time_ns:1_234_567L
|
||||||
~t_ref:(Thread_ref.Ref 5)
|
~t_ref:(Thread_ref.Ref 5)
|
||||||
~args:[ "x", `Int 42 ]
|
~args:[ "x", A_int 42 ]
|
||||||
())
|
())
|
||||||
in
|
in
|
||||||
(let oc = open_out "foo.fxt" in
|
(let oc = open_out "foo.fxt" in
|
||||||
|
|
|
||||||
|
|
@ -1049,5 +1049,4 @@
|
||||||
{"pid":2,"cat":"","tid": 3,"ts": 1299.00,"name":"world","ph":"I"},
|
{"pid":2,"cat":"","tid": 3,"ts": 1299.00,"name":"world","ph":"I"},
|
||||||
{"pid":2,"tid":3,"ts":1300.00,"name":"c","ph":"C","args": {"n":200}},
|
{"pid":2,"tid":3,"ts":1300.00,"name":"c","ph":"C","args": {"n":200}},
|
||||||
{"pid":2,"cat":"","tid": 3,"dur": 4.00,"ts": 1297.00,"name":"inner.loop","ph":"X","args": {"i":50}},
|
{"pid":2,"cat":"","tid": 3,"dur": 4.00,"ts": 1297.00,"name":"inner.loop","ph":"X","args": {"i":50}},
|
||||||
{"pid":2,"cat":"","tid": 3,"dur": 25.00,"ts": 1277.00,"name":"outer.loop","ph":"X"},
|
{"pid":2,"cat":"","tid": 3,"dur": 25.00,"ts": 1277.00,"name":"outer.loop","ph":"X"}]
|
||||||
{"pid":2,"cat":"","tid": 1,"ts": 1304.00,"name":"tef-worker.exit","ph":"I"}]
|
|
||||||
|
|
@ -929,5 +929,4 @@
|
||||||
{"pid":2,"cat":"","tid": 3,"dur": 217.00,"ts": 1642.00,"name":"Dune__exe__T2.fib2","ph":"X"},
|
{"pid":2,"cat":"","tid": 3,"dur": 217.00,"ts": 1642.00,"name":"Dune__exe__T2.fib2","ph":"X"},
|
||||||
{"pid":2,"cat":"","tid": 3,"dur": 353.00,"ts": 1507.00,"name":"Dune__exe__T2.fib2","ph":"X"},
|
{"pid":2,"cat":"","tid": 3,"dur": 353.00,"ts": 1507.00,"name":"Dune__exe__T2.fib2","ph":"X"},
|
||||||
{"pid":2,"cat":"","tid": 3,"dur": 573.00,"ts": 1288.00,"name":"Dune__exe__T2.fib2","ph":"X"},
|
{"pid":2,"cat":"","tid": 3,"dur": 573.00,"ts": 1288.00,"name":"Dune__exe__T2.fib2","ph":"X"},
|
||||||
{"pid":2,"cat":"","tid": 3,"dur": 929.00,"ts": 933.00,"name":"Dune__exe__T2.fib2","ph":"X"},
|
{"pid":2,"cat":"","tid": 3,"dur": 929.00,"ts": 933.00,"name":"Dune__exe__T2.fib2","ph":"X"}]
|
||||||
{"pid":2,"cat":"","tid": 1,"ts": 1864.00,"name":"tef-worker.exit","ph":"I"}]
|
|
||||||
Loading…
Add table
Reference in a new issue