Skip to content

Commit

Permalink
Expose reset_counters in the BuckleScript runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
aantron committed Apr 13, 2020
1 parent 2938882 commit 5b0404f
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 9 deletions.
8 changes: 8 additions & 0 deletions src/common/bisect_common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,14 @@ end
let table : (string, int array * string) Hashtbl.t Lazy.t =
lazy (Hashtbl.create 17)

let reset_counters () =
Lazy.force table
|> Hashtbl.iter begin fun _ (point_state, _) ->
match Array.length point_state with
| 0 -> ()
| n -> Array.fill point_state 0 (n - 1) 0
end

let runtime_data_to_string () =
let data = Hashtbl.fold (fun k v acc -> (k, v)::acc) (Lazy.force table) [] in
match data with
Expand Down
4 changes: 2 additions & 2 deletions src/common/bisect_common.mli
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ val read_runtime_data : string -> (string * (int array * string)) list
val read_points : string -> point_definition list
(** [read_points s] reads point definitions from the string [s]. *)

val table : (string, int array * string) Hashtbl.t Lazy.t
(** Coverage statistics table used by the runtime. *)
val reset_counters : unit -> unit
(** Clears accumulated coverage statistics. *)

val register_file :
string -> point_count:int -> point_definitions:string ->
Expand Down
3 changes: 3 additions & 0 deletions src/runtime/bucklescript/runtime.ml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@ let node_at_exit = [%bs.raw {|

let write_coverage_data_on_exit () =
node_at_exit write_coverage_data

let reset_coverage_data =
Bisect_common.reset_counters
3 changes: 3 additions & 0 deletions src/runtime/bucklescript/runtime.mli
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@ val write_coverage_data : unit -> unit
val write_coverage_data_on_exit : unit -> unit
(** Registers {!write_coverage_data} to be called automatically on process
exit. *)

val reset_coverage_data : unit -> unit
(** [reset_coverage_data ()] clears accumulated coverage statistics. *)
10 changes: 3 additions & 7 deletions src/runtime/native/runtime.ml
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,12 @@ let file_channel () =
in
create_file ()

let reset_counters =
Common.reset_counters

let dump_counters_exn =
Common.write_runtime_data

let reset_counters () =
Hashtbl.iter (fun _ (point_state, _) ->
match Array.length point_state with
| 0 -> ()
| n -> Array.(fill point_state 0 (n - 1) 0)
) (Lazy.force Common.table)

let dump () =
match file_channel () with
| None -> ()
Expand Down

0 comments on commit 5b0404f

Please sign in to comment.