Browse Source

[display] move timer fields generation function to display.ml

Dan Korostelev 9 years ago
parent
commit
367366e424
2 changed files with 20 additions and 14 deletions
  1. 11 0
      src/display/display.ml
  2. 9 14
      src/main.ml

+ 11 - 0
src/display/display.ml

@@ -143,6 +143,17 @@ let display_enum_field dm ef p = match dm.dms_kind with
 	| DMType -> raise (DisplayType (ef.ef_type,p))
 	| _ -> ()
 
+let get_timer_fields start_time =
+	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), None, "")] in
+	if !tot > 0. then
+		Hashtbl.fold (fun _ t acc ->
+			("@TIME " ^ t.name, Printf.sprintf "%.3fs (%.0f%%)" t.total (t.total *. 100. /. !tot), None, "") :: acc
+		) Common.htimers fields
+	else
+		fields
+
 open Json
 
 let htmlescape s =

+ 9 - 14
src/main.ml

@@ -1224,20 +1224,15 @@ with
 	| Display.DisplayPackage pack ->
 		raise (Completion (String.concat "." pack))
 	| Display.DisplayFields fields ->
-		let ctx = print_context() in
-		let fields = List.map (fun (name,t,kind,doc) -> name, s_type ctx t, kind, (match doc with None -> "" | Some d -> d)) fields in
-		let fields = if !measure_times then begin
-			close_times();
-			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), None, "") :: fields in
-			if !tot > 0. then
-				Hashtbl.fold (fun _ t acc ->
-					("@TIME " ^ t.name, Printf.sprintf "%.3fs (%.0f%%)" t.total (t.total *. 100. /. !tot), None, "") :: acc
-				) Common.htimers fields
-			else fields
-		end else
-			fields
+		let fields = List.map (
+			fun (name,t,kind,doc) -> name, s_type (print_context()) t, kind, (Option.default "" doc)
+		) fields in
+		let fields =
+			if !measure_times then begin
+				close_times();
+				(Display.get_timer_fields !start_time) @ fields
+			end else
+				fields
 		in
 		raise (Completion (Display.print_fields fields))
 	| Display.DisplayType (t,p) ->