Printf.eprintf "Final Mem: %s\n\n\n%!" s2;
r
;;
+
+let pid = ref 0
+let start_perf () =
+
+ let ppid = Unix.getpid() in
+ let cmd = "/usr/bin/perf" in
+ if not (Sys.file_exists cmd) then (failwith "Binary '/usr/bin/perf' not found");
+ let args = [| cmd; "stat"; "--pid=" ^ (string_of_int ppid);
+ "-e"; "L1-dcache-load";
+ "-e"; "L1-dcache-load-misses";
+ "-e"; "L1-dcache-store";
+ "-e"; "L1-dcache-store-misses";
+ "-e"; "L1-icache-load";
+ "-e"; "L1-icache-load-misses";
+ "-e"; "branch-load";
+ "-e"; "branch-load-misses";
+ "-e"; "cpu-cycles";
+ "-e"; "stalled-cycles-frontend";
+ "-e"; "stalled-cycles-backend";
+ "-e"; "instructions";
+ "-e"; "cache-references";
+ "-e"; "cache-misses";
+ "-e"; "branch-instructions";
+ "-e"; "branch-misses";
+ "-e"; "bus-cycles";
+ |] in
+ let p = Unix.fork() in
+ pid := p;
+ if !pid == 0 then Unix.execv cmd args
+
+let stop_perf () =
+ Unix.kill !pid Sys.sigint
+
let time f ?(count=1) ?(msg="") x =
let rec loop i =
Gc.compact();