Skip to content

Commit

Permalink
don't look if you want to sleep at night
Browse files Browse the repository at this point in the history
  • Loading branch information
kLabz committed Jan 18, 2024
1 parent 2d0561b commit bf8a264
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
25 changes: 24 additions & 1 deletion src/compiler/hxb/hxbReader.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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()

Expand Down
10 changes: 9 additions & 1 deletion src/core/timer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit bf8a264

Please sign in to comment.