1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
|
(* TEST *)
(* Tests various valid and invalid orderings of start/stop/discard
statmemprof calls. Doesn't test any callbacks or count any allocations,
etc.*)
module MP = Gc.Memprof
let prof () = MP.start ~sampling_rate:1. MP.null_tracker
(* Null test: start/stop/discard *)
let _ =
let profile = prof () in
MP.stop ();
MP.discard profile;
print_endline "Null test."
(* Stop without starting *)
let _ = try
MP.stop ()
with
Failure s -> Printf.printf "Stop without starting fails with \"%s\"\n" s
(* Second start without stopping. *)
let _ =
try
Fun.protect ~finally:MP.stop
(fun () -> (ignore (prof ());
ignore (prof ())))
with
Failure s -> Printf.printf "Start without stopping fails with \"%s\"\n" s
(* Discard without stopping. *)
let _ =
try
Fun.protect ~finally:MP.stop
(fun () -> MP.discard (prof()))
with
Failure s -> Printf.printf "Discard without stopping fails with \"%s\"\n" s
(* Discard same profile twice. *)
let _ =
let profile = prof () in
MP.stop ();
MP.discard profile;
try
MP.discard profile;
with
Failure s -> Printf.printf "Second discard fails with \"%s\"\n" s
(* Double profile *)
let _ =
ignore (prof ());
MP.stop ();
ignore (prof ());
MP.stop ();
print_endline "Double profile."
(* Double profile with intervening discard *)
let _ =
let prof1 = prof () in
MP.stop ();
MP.discard prof1;
ignore (prof ());
MP.stop ();
print_endline "Double profile with single discard."
(* Double profile, both discarded *)
let _ =
let prof1 = prof () in
MP.stop ();
MP.discard prof1;
let prof2 = prof () in
MP.stop ();
MP.discard prof2;
print_endline "Double profile, discarding both."
(* Double profile, discard both at end *)
let _ =
let prof1 = prof () in
MP.stop ();
let prof2 = prof () in
MP.stop ();
MP.discard prof1;
MP.discard prof2;
print_endline "Double profile, discarding both at end."
(* Double profile, discard in reverse order *)
let _ =
let prof1 = prof () in
MP.stop ();
let prof2 = prof () in
MP.stop ();
MP.discard prof2;
MP.discard prof1;
print_endline "Double profile, discarding in reverse order."
(* Double profile, discard first while second is sampling *)
let _ =
let prof1 = prof () in
MP.stop ();
let prof2 = prof () in
MP.discard prof1;
MP.stop ();
MP.discard prof2;
print_endline "Discarding old profile while sampling."
|