Procházet zdrojové kódy

support --times on toplevel display (closes #5710)

Simon Krajewski před 9 roky
rodič
revize
eda0164f30
3 změnil soubory, kde provedl 14 přidání a 3 odebrání
  1. 2 0
      src/context/common.ml
  2. 4 2
      src/display/displayOutput.ml
  3. 8 1
      src/main.ml

+ 2 - 0
src/context/common.ml

@@ -207,6 +207,7 @@ module IdentifierType = struct
 		| ITGlobal of module_type * string * Type.t
 		| ITType of module_type
 		| ITPackage of string
+		| ITTimer of string
 
 	let get_name = function
 		| ITLocal v -> v.v_name
@@ -215,6 +216,7 @@ module IdentifierType = struct
 		| ITGlobal(_,s,_) -> s
 		| ITType mt -> snd (t_infos mt).mt_path
 		| ITPackage s -> s
+		| ITTimer s -> s
 end
 
 type shared_display_information = {

+ 4 - 2
src/display/displayOutput.ml

@@ -17,10 +17,10 @@ let htmlescape s =
 let get_timer_fields start_time =
 	let tot = ref 0. in
 	Hashtbl.iter (fun _ t -> tot := !tot +. t.total) Common.htimers;
-	let fields = [("@TOTAL", FKTimer (Printf.sprintf "%.3fs" (get_time() -. start_time)), "")] in
+	let fields = [("@TOTAL", Printf.sprintf "%.3fs" (get_time() -. start_time))] in
 	if !tot > 0. then
 		Hashtbl.fold (fun _ t acc ->
-			("@TIME " ^ (String.concat "." t.id), FKTimer (Printf.sprintf "%.3fs (%.0f%%)" t.total (t.total *. 100. /. !tot)), "") :: acc
+			((String.concat "." t.id),(Printf.sprintf "%.3fs (%.0f%%)" t.total (t.total *. 100. /. !tot))) :: acc
 		) Common.htimers fields
 	else
 		fields
@@ -78,6 +78,8 @@ let print_toplevel il =
 			Buffer.add_string b (Printf.sprintf "<i k=\"type\" p=\"%s\"%s>%s</i>\n" (s_type_path infos.mt_path) (s_doc infos.mt_doc) (snd infos.mt_path));
 		| IdentifierType.ITPackage s ->
 			Buffer.add_string b (Printf.sprintf "<i k=\"package\">%s</i>\n" s)
+		| IdentifierType.ITTimer s ->
+			Buffer.add_string b (Printf.sprintf "<i k=\"timer\">%s</i>\n" s)
 	) il;
 	Buffer.add_string b "</il>";
 	Buffer.contents b

+ 8 - 1
src/main.ml

@@ -891,7 +891,7 @@ with
 		let fields =
 			if !measure_times then begin
 				close_times();
-				(DisplayOutput.get_timer_fields !start_time) @ fields
+				(List.map (fun (name,value) -> ("@TIME " ^ name, Display.FKTimer value, "")) (DisplayOutput.get_timer_fields !start_time)) @ fields
 			end else
 				fields
 		in
@@ -907,6 +907,13 @@ with
 	| Display.DisplayPosition pl ->
 		raise (DisplayOutput.Completion (DisplayOutput.print_positions pl))
 	| Display.DisplayToplevel il ->
+		let il =
+			if !measure_times then begin
+				close_times();
+				(List.map (fun (name,value) -> IdentifierType.ITTimer ("@TIME " ^ name ^ ": " ^ value)) (DisplayOutput.get_timer_fields !start_time)) @ il
+			end else
+				il
+		in
 		raise (DisplayOutput.Completion (DisplayOutput.print_toplevel il))
 	| Parser.TypePath (p,c,is_import) ->
 		let fields =