|
|
@@ -102,9 +102,11 @@ let report_times print =
|
|
|
let tot = ref 0. in
|
|
|
Hashtbl.iter (fun _ t -> tot := !tot +. t.total) Common.htimers;
|
|
|
print (Printf.sprintf "Total time : %.3fs" !tot);
|
|
|
- print "------------------------------------";
|
|
|
- let timers = List.sort (fun t1 t2 -> compare t1.name t2.name) (Hashtbl.fold (fun _ t acc -> t :: acc) Common.htimers []) in
|
|
|
- List.iter (fun t -> print (Printf.sprintf " %s : %.3fs, %.0f%%" t.name t.total (t.total *. 100. /. !tot))) timers
|
|
|
+ if !tot > 0. then begin
|
|
|
+ print "------------------------------------";
|
|
|
+ let timers = List.sort (fun t1 t2 -> compare t1.name t2.name) (Hashtbl.fold (fun _ t acc -> t :: acc) Common.htimers []) in
|
|
|
+ List.iter (fun t -> print (Printf.sprintf " %s : %.3fs, %.0f%%" t.name t.total (t.total *. 100. /. !tot))) timers
|
|
|
+ end
|
|
|
|
|
|
let make_path f =
|
|
|
let f = String.concat "/" (ExtString.String.nsplit f "\\") in
|
|
|
@@ -337,47 +339,47 @@ let run_command ctx cmd =
|
|
|
let binary_string s =
|
|
|
if Sys.os_type <> "Win32" && Sys.os_type <> "Cygwin" then s else String.concat "\n" (Str.split (Str.regexp "\r\n") s)
|
|
|
in
|
|
|
- let pout, pin, perr = Unix.open_process_full cmd (Unix.environment()) in
|
|
|
- let iout = Unix.descr_of_in_channel pout in
|
|
|
- let ierr = Unix.descr_of_in_channel perr in
|
|
|
- let berr = Buffer.create 0 in
|
|
|
- let bout = Buffer.create 0 in
|
|
|
+ let pout, pin, perr = Unix.open_process_full cmd (Unix.environment()) in
|
|
|
+ let iout = Unix.descr_of_in_channel pout in
|
|
|
+ let ierr = Unix.descr_of_in_channel perr in
|
|
|
+ let berr = Buffer.create 0 in
|
|
|
+ let bout = Buffer.create 0 in
|
|
|
let tmp = String.create 1024 in
|
|
|
let result = ref None in
|
|
|
(*
|
|
|
we need to read available content on process out/err if we want to prevent
|
|
|
the process from blocking when the pipe is full
|
|
|
- *)
|
|
|
- let is_process_running() =
|
|
|
- let pid, r = Unix.waitpid [Unix.WNOHANG] (-1) in
|
|
|
- if pid = 0 then
|
|
|
- true
|
|
|
- else begin
|
|
|
- result := Some r;
|
|
|
- false;
|
|
|
- end
|
|
|
- in
|
|
|
- let rec loop ins =
|
|
|
- let (ch,_,_), timeout = (try Unix.select ins [] [] 0.02, true with _ -> ([],[],[]),false) in
|
|
|
- match ch with
|
|
|
- | [] ->
|
|
|
- (* make sure we read all *)
|
|
|
- if timeout && is_process_running() then
|
|
|
- loop ins
|
|
|
- else begin
|
|
|
- Buffer.add_string berr (IO.read_all (IO.input_channel perr));
|
|
|
- Buffer.add_string bout (IO.read_all (IO.input_channel pout));
|
|
|
- end
|
|
|
- | s :: _ ->
|
|
|
- let n = Unix.read s tmp 0 (String.length tmp) in
|
|
|
- Buffer.add_substring (if s == iout then bout else berr) tmp 0 n;
|
|
|
- loop (if n = 0 then List.filter ((!=) s) ins else ins)
|
|
|
+ *)
|
|
|
+ let is_process_running() =
|
|
|
+ let pid, r = Unix.waitpid [Unix.WNOHANG] (-1) in
|
|
|
+ if pid = 0 then
|
|
|
+ true
|
|
|
+ else begin
|
|
|
+ result := Some r;
|
|
|
+ false;
|
|
|
+ end
|
|
|
+ in
|
|
|
+ let rec loop ins =
|
|
|
+ let (ch,_,_), timeout = (try Unix.select ins [] [] 0.02, true with _ -> ([],[],[]),false) in
|
|
|
+ match ch with
|
|
|
+ | [] ->
|
|
|
+ (* make sure we read all *)
|
|
|
+ if timeout && is_process_running() then
|
|
|
+ loop ins
|
|
|
+ else begin
|
|
|
+ Buffer.add_string berr (IO.read_all (IO.input_channel perr));
|
|
|
+ Buffer.add_string bout (IO.read_all (IO.input_channel pout));
|
|
|
+ end
|
|
|
+ | s :: _ ->
|
|
|
+ let n = Unix.read s tmp 0 (String.length tmp) in
|
|
|
+ Buffer.add_substring (if s == iout then bout else berr) tmp 0 n;
|
|
|
+ loop (if n = 0 then List.filter ((!=) s) ins else ins)
|
|
|
in
|
|
|
loop [iout;ierr];
|
|
|
- let serr = binary_string (Buffer.contents berr) in
|
|
|
- let sout = binary_string (Buffer.contents bout) in
|
|
|
- if serr <> "" then ctx.messages <- (if serr.[String.length serr - 1] = '\n' then String.sub serr 0 (String.length serr - 1) else serr) :: ctx.messages;
|
|
|
- if sout <> "" then ctx.com.print sout;
|
|
|
+ let serr = binary_string (Buffer.contents berr) in
|
|
|
+ let sout = binary_string (Buffer.contents bout) in
|
|
|
+ if serr <> "" then ctx.messages <- (if serr.[String.length serr - 1] = '\n' then String.sub serr 0 (String.length serr - 1) else serr) :: ctx.messages;
|
|
|
+ if sout <> "" then ctx.com.print sout;
|
|
|
(match (try Unix.close_process_full (pout,pin,perr) with Unix.Unix_error (Unix.ECHILD,_,_) -> (match !result with None -> assert false | Some r -> r)) with
|
|
|
| Unix.WEXITED e -> if e <> 0 then failwith ("Command failed with error " ^ string_of_int e)
|
|
|
| Unix.WSIGNALED s | Unix.WSTOPPED s -> failwith ("Command stopped with signal " ^ string_of_int s));
|
|
|
@@ -1083,7 +1085,7 @@ try
|
|
|
Genjava.generate com;
|
|
|
);
|
|
|
end;
|
|
|
- Sys.catch_break false;
|
|
|
+ Sys.catch_break false;
|
|
|
if not !no_output then List.iter (run_command ctx) (List.rev !cmds)
|
|
|
with
|
|
|
| Abort ->
|
|
|
@@ -1114,9 +1116,11 @@ with
|
|
|
let tot = ref 0. in
|
|
|
Hashtbl.iter (fun _ t -> tot := !tot +. t.total) Common.htimers;
|
|
|
let fields = ("@TOTAL", Printf.sprintf "%.3fs" (get_time() -. !start_time), "") :: fields in
|
|
|
- Hashtbl.fold (fun _ t acc ->
|
|
|
- ("@TIME " ^ t.name, Printf.sprintf "%.3fs (%.0f%%)" t.total (t.total *. 100. /. !tot), "") :: acc
|
|
|
- ) Common.htimers fields;
|
|
|
+ if !tot > 0. then
|
|
|
+ Hashtbl.fold (fun _ t acc ->
|
|
|
+ ("@TIME " ^ t.name, Printf.sprintf "%.3fs (%.0f%%)" t.total (t.total *. 100. /. !tot), "") :: acc
|
|
|
+ ) Common.htimers fields
|
|
|
+ else fields
|
|
|
end else
|
|
|
fields
|
|
|
in
|