From bf8a2645a4c19dc59436870439b294cdde145727 Mon Sep 17 00:00:00 2001 From: Rudy Ges Date: Thu, 18 Jan 2024 21:52:58 +0100 Subject: [PATCH] don't look if you want to sleep at night --- src/compiler/hxb/hxbReader.ml | 25 ++++++++++++++++++++++++- src/core/timer.ml | 10 +++++++++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/compiler/hxb/hxbReader.ml b/src/compiler/hxb/hxbReader.ml index 4ef702ee8db..b3f4db82d23 100644 --- a/src/compiler/hxb/hxbReader.ml +++ b/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() diff --git a/src/core/timer.ml b/src/core/timer.ml index 436736c71ab..32b6e9936ae 100644 --- a/src/core/timer.ml +++ b/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