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

close root timer and support pre-argument-parsing timers

We have to default to measure_times = true because we'll only know once we've parsed the arguments.
Simon Krajewski 5 сар өмнө
parent
commit
39a0f90e13

+ 4 - 1
src/compiler/args.ml

@@ -64,6 +64,7 @@ let parse_args com =
 		raise_usage = (fun () -> ());
 		display_arg = None;
 		deprecations = [];
+		measure_times = false;
 	} in
 	let add_deprecation s =
 		actx.deprecations <- s :: actx.deprecations
@@ -261,7 +262,9 @@ let parse_args com =
 			actx.hxb_out <- Some file;
 		),"<file>", "generate haxe binary representation to target archive");
 		("Optimization",["--no-output"],[], Arg.Unit (fun() -> actx.no_output <- true),"","compiles but does not generate any file");
-		("Debug",["--times"],[], Arg.Unit (fun() -> com.timer_ctx.measure_times <- true),"","measure compilation times");
+		("Debug",["--times"],[], Arg.Unit (fun() ->
+			actx.measure_times <- true
+		),"","measure compilation times");
 		("Optimization",["--no-inline"],[],Arg.Unit (fun () ->
 			add_deprecation "--no-inline has been deprecated, use -D no-inline instead";
 			Common.define com Define.NoInline

+ 1 - 0
src/compiler/compilationContext.ml

@@ -37,6 +37,7 @@ type arg_context = {
 	mutable raise_usage : unit -> unit;
 	mutable display_arg : string option;
 	mutable deprecations : string list;
+	mutable measure_times : bool;
 }
 
 type communication = {

+ 2 - 1
src/compiler/compiler.ml

@@ -503,6 +503,7 @@ let catch_completion_and_exit ctx callbacks run =
 			i
 
 let process_actx ctx actx =
+	ctx.timer_ctx.measure_times <- actx.measure_times;
 	DisplayProcessing.process_display_arg ctx actx;
 	List.iter (fun s ->
 		ctx.com.warning WDeprecated [] s null_pos
@@ -703,7 +704,7 @@ module HighLevel = struct
 		end
 
 	let entry server_api comm args =
-		let timer_ctx = Timer.make_context (Timer.make ["root"]) in
+		let timer_ctx = Timer.make_context (Timer.make ["other"]) in
 		let create = create_context comm server_api.cache timer_ctx in
 		let each_args = ref [] in
 		let curdir = Unix.getcwd () in

+ 19 - 9
src/core/timer.ml

@@ -6,6 +6,7 @@ type timer = {
 }
 
 type timer_context = {
+	root_timer : timer;
 	mutable current : timer;
 	mutable measure_times : bool;
 	start_time : float;
@@ -19,12 +20,22 @@ let make id = {
 	calls = 0;
 }
 
-let make_context root_timer = {
-	current = root_timer;
-	timer_lut = Hashtbl.create 0;
-	measure_times = false;
-	start_time = Extc.time();
-}
+let make_context root_timer =
+	let ctx = {
+		root_timer = root_timer;
+		current = root_timer;
+		timer_lut = Hashtbl.create 0;
+		measure_times = true;
+		start_time = Extc.time();
+	} in
+	Hashtbl.add ctx.timer_lut root_timer.id root_timer;
+	ctx
+
+let update_timer timer start =
+	let now = Extc.time () in
+	let dt = now -. start in
+	timer.total <- timer.total +. dt -. timer.pauses;
+	dt
 
 let start_timer ctx id =
 	let start = Extc.time () in
@@ -39,9 +50,7 @@ let start_timer ctx id =
 	timer.calls <- timer.calls + 1;
 	ctx.current <- timer;
 	(fun () ->
-		let now = Extc.time () in
-		let dt = now -. start in
-		timer.total <- timer.total +. dt -. timer.pauses;
+		let dt = update_timer timer start in
 		timer.pauses <- 0.;
 		old.pauses <- old.pauses +. dt;
 		ctx.current <- old
@@ -85,6 +94,7 @@ type timer_node = {
 }
 
 let build_times_tree ctx =
+	ignore(update_timer ctx.root_timer ctx.start_time);
 	let nodes = Hashtbl.create 0 in
 	let rec root = {
 		name = "";