2
0
Эх сурвалжийг харах

fix measure_times properly

Simon Krajewski 5 сар өмнө
parent
commit
ec7476d728

+ 1 - 1
src/compiler/compiler.ml

@@ -503,7 +503,7 @@ let catch_completion_and_exit ctx callbacks run =
 			i
 
 let process_actx ctx actx =
-	ctx.timer_ctx.measure_times <- actx.measure_times;
+	ctx.timer_ctx.measure_times <- (if actx.measure_times then Yes else No);
 	DisplayProcessing.process_display_arg ctx actx;
 	List.iter (fun s ->
 		ctx.com.warning WDeprecated [] s null_pos

+ 1 - 1
src/compiler/displayOutput.ml

@@ -272,7 +272,7 @@ let handle_display_exception_old ctx dex = match dex with
 		raise (Completion (String.concat "." pack))
 	| DisplayFields r ->
 		DisplayPosition.display_position#reset;
-		let fields = if ctx.com.timer_ctx.measure_times then begin
+		let fields = if ctx.com.timer_ctx.measure_times = Yes then begin
 			(List.map (fun (name,value) ->
 				CompletionItem.make_ci_timer ("@TIME " ^ name) value
 			) (get_timer_fields ctx.com.timer_ctx)) @ r.fitems

+ 4 - 5
src/compiler/server.ml

@@ -114,7 +114,7 @@ module Communication = struct
 			);
 			exit = (fun timer_ctx code ->
 				if code = 0 then begin
-					if timer_ctx.measure_times then Timer.report_times timer_ctx (fun s -> self.write_err (s ^ "\n"));
+					if timer_ctx.measure_times = Yes then Timer.report_times timer_ctx (fun s -> self.write_err (s ^ "\n"));
 				end;
 				exit code;
 			);
@@ -139,11 +139,10 @@ module Communication = struct
 
 					sctx.was_compilation <- ctx.com.display.dms_full_typing;
 					if has_error ctx then begin
-						ctx.timer_ctx.measure_times <- false;
+						ctx.timer_ctx.measure_times <- No;
 						write "\x02\n"
-					end else begin
-						if ctx.timer_ctx.measure_times then Timer.report_times ctx.timer_ctx (fun s -> self.write_err (s ^ "\n"));
-					end
+					end else
+						if ctx.timer_ctx.measure_times = Yes then Timer.report_times ctx.timer_ctx (fun s -> self.write_err (s ^ "\n"));
 				)
 			);
 			exit = (fun timer_ctx i ->

+ 1 - 1
src/context/display/displayJson.ml

@@ -506,7 +506,7 @@ let parse_input com input =
 			"result",json;
 			"timestamp",jfloat (Unix.gettimeofday ());
 		] in
-		let fl = if com.timer_ctx.measure_times then begin
+		let fl = if com.timer_ctx.measure_times = Yes then begin
 			let _,_,root = Timer.build_times_tree com.timer_ctx in
 			begin match json_of_times root with
 			| None -> fl

+ 9 - 4
src/core/timer.ml

@@ -5,10 +5,15 @@ type timer = {
 	mutable calls : int;
 }
 
+type measure_times =
+	| Yes
+	| No
+	| Maybe
+
 type timer_context = {
 	root_timer : timer;
 	mutable current : timer;
-	mutable measure_times : bool;
+	mutable measure_times : measure_times;
 	start_time : float;
 	timer_lut : (string list,timer) Hashtbl.t;
 }
@@ -25,7 +30,7 @@ let make_context root_timer =
 		root_timer = root_timer;
 		current = root_timer;
 		timer_lut = Hashtbl.create 0;
-		measure_times = true;
+		measure_times = Maybe;
 		start_time = Extc.time();
 	} in
 	Hashtbl.add ctx.timer_lut root_timer.id root_timer;
@@ -56,8 +61,8 @@ let start_timer ctx id =
 		ctx.current <- old
 	)
 
-let start_timer ctx id = match id with
-	| _ :: _ when ctx.measure_times && Domain.is_main_domain () ->
+let start_timer ctx id = match id,ctx.measure_times with
+	| (_ :: _),(Yes | Maybe) when Domain.is_main_domain () ->
 		start_timer ctx id
 	| _ ->
 		(fun () -> ())