Ver código fonte

don't look if you want to sleep at night

Rudy Ges 1 ano atrás
pai
commit
bf8a2645a4
2 arquivos alterados com 33 adições e 2 exclusões
  1. 24 1
      src/compiler/hxb/hxbReader.ml
  2. 9 1
      src/core/timer.ml

+ 24 - 1
src/compiler/hxb/hxbReader.ml

@@ -116,6 +116,7 @@ class hxb_reader
 = object(self)
 	val mutable api = Obj.magic ""
 	val mutable current_module = null_module
+	val mutable timers = Array.make 3 (EOM,None)
 
 	val mutable ch = BytesWithPosition.create (Bytes.create 0)
 	val mutable string_pool = Array.make 0 ""
@@ -1840,6 +1841,17 @@ class hxb_reader
 			doc_pool <- self#read_string_pool;
 		| MDF ->
 			current_module <- self#read_mdf;
+
+			let module_name = String.concat "_" (ExtLib.String.nsplit (s_type_path current_module.m_path) ".") in
+			Array.iter (fun (kind, timer) ->
+				match timer with
+					| None -> ()
+					| Some (t:Timer.timer_infos) ->
+						let infos = match kind with STR -> Printf.sprintf "%d strings." (Array.length string_pool) | _ -> "" in
+						Hashtbl.remove Timer.htimers t.id;
+						t.id <- t.id @ [infos ^ module_name];
+						Hashtbl.add Timer.htimers t.id t;
+			) timers;
 		| MTF ->
 			current_module.m_types <- self#read_mtf;
 			api#add_module current_module;
@@ -1881,7 +1893,18 @@ class hxb_reader
 			incr stats.modules_fully_restored;
 
 	method private read_chunk_data kind =
-		let close = Timer.timer ["hxb";"read";string_of_chunk_kind kind] in
+		let id = ["hxb";"read";string_of_chunk_kind kind] in
+		let id = match kind with
+			| STR | DOC | MDF -> id
+			| _ -> id @ [String.concat "_" (ExtLib.String.nsplit (s_type_path current_module.m_path) ".")]
+		in
+
+		let close,t = Timer.timer_with_ref id in
+		(match kind with
+			| STR -> timers.(0) <- (kind, t)
+			| DOC -> timers.(1) <- (kind, t)
+			| MDF -> timers.(2) <- (kind, t)
+			| _ -> ());
 		self#read_chunk_data' kind;
 		close()
 

+ 9 - 1
src/core/timer.ml

@@ -18,7 +18,7 @@
  *)
 
 type timer_infos = {
-	id : string list;
+	mutable id : string list;
 	mutable start : float list;
 	mutable pauses : float list;
 	mutable total : float;
@@ -77,6 +77,14 @@ let timer id =
 	) else
 		(fun() -> ())
 
+let timer_with_ref id =
+	if !measure_times then (
+		let t = new_timer id in
+		curtime := t :: !curtime;
+		((function() -> close (get_time()) t), Some t)
+	) else
+		((fun() -> ()), None)
+
 let current_id() =
 	match !curtime with
 	| [] -> None