Something went wrong. Try again.
Codec for the pprof sampled-profile format (profile.proto)
Something went wrong. Try again.
2.4 kB · 76 lines
OCaml
at main
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677(** [Function] (profile.proto lines 221-233): "Unique nonzero id for the function", a human-readable {!Pprof.Function.name} and the {!Pprof.Function.system_name} the system knows it by, which for OCaml is the mangled [caml*] symbol. *)
let f : Pprof.Function.t = { id = 2L; name = "List.map"; system_name = "camlStdlib__List__map_267"; filename = "list.ml"; start_line = 96L; }
let eq = Pprof.Function.equallet bools = Alcotest.(check bool)
let test_equal () = bools "reflexive" true (eq f f); bools "differing id" false (eq f { f with id = 3L }); bools "differing name" false (eq f { f with name = "List.rev" }); bools "differing system_name" false (eq f { f with system_name = "x" }); bools "differing filename" false (eq f { f with filename = "array.ml" }); bools "differing start_line" false (eq f { f with start_line = 97L }); (* A demangled and a mangled name are different strings, not aliases. *) bools "name vs system_name swapped" false (eq f { f with name = f.system_name; system_name = f.name })
let test_pp () = Alcotest.(check string) "id, name, source" "#2 List.map (list.ml:96)" (Fmt.str "%a" Pprof.Function.pp f); Alcotest.(check string) "unsymbolised" "#2 (:0)" (Fmt.str "%a" Pprof.Function.pp { f with name = ""; filename = ""; start_line = 0L })
let with_functions functions = { Fixture.minimal with functions }
let test_roundtrip () = Expect.roundtrips (with_functions [ { f with id = 7L } ]); (* An unsymbolised function keeps only its id; every string indexes 0. *) Expect.roundtrips (with_functions [ { id = 7L; name = ""; system_name = ""; filename = ""; start_line = 0L; }; ]); (* Ids are uint64 on the wire: the top bit must survive as a bit pattern. *) Expect.roundtrips { (with_functions [ { f with id = -1L } ]) with locations = [ { id = 5L; mapping_id = 0L; address = 0L; lines = [ { function_id = -1L; line = 1L; column = 0L } ]; is_folded = false; }; ]; }
let suite = ( "function", [ ("equal", `Quick, test_equal); ("pp", `Quick, test_pp); ("roundtrip", `Quick, test_roundtrip); ] )