Utilize @[deriving fields] in BackendStats

Summary:
:

In previous commits we introduced deriving capabilities in Backend stats.
Now we can rewrite the code so that usage of all fields is enforced at compile time.

Reviewed By: jvillard

Differential Revision: D16458130

fbshipit-source-id: aef751440
master
Mitya Lyubarskiy 5 years ago committed by Facebook Github Bot
parent d84b0881ba
commit 860d3aa8a4

@ -51,19 +51,15 @@ let incr_summary_has_model_queries () =
let copy from ~into = let copy from ~into =
(* so we don't forget to add new fields to [copy] *) let { summary_file_try_load
let[@warning "+9"] { summary_file_try_load ; summary_read_from_disk
; summary_read_from_disk ; summary_cache_hits
; summary_cache_hits ; summary_cache_misses
; summary_cache_misses ; summary_has_model_queries } =
; summary_has_model_queries } =
from from
in in
into.summary_file_try_load <- summary_file_try_load ; Fields.Direct.set_all_mutable_fields into ~summary_file_try_load ~summary_read_from_disk
into.summary_read_from_disk <- summary_read_from_disk ; ~summary_cache_hits ~summary_cache_misses ~summary_has_model_queries
into.summary_cache_hits <- summary_cache_hits ;
into.summary_cache_misses <- summary_cache_misses ;
into.summary_has_model_queries <- summary_has_model_queries
let merge stats1 stats2 = let merge stats1 stats2 =
@ -86,26 +82,25 @@ let initial =
let reset () = copy initial ~into:global_stats let reset () = copy initial ~into:global_stats
let pp f stats = let pp f stats =
(* make sure we print all the fields *)
let[@warning "+9"] { summary_file_try_load
; summary_read_from_disk
; summary_cache_hits
; summary_cache_misses
; summary_has_model_queries } =
stats
in
let pp_hit_percent hit miss f = let pp_hit_percent hit miss f =
let total = hit + miss in let total = hit + miss in
if Int.equal total 0 then F.pp_print_string f "N/A%%" if Int.equal total 0 then F.pp_print_string f "N/A%%"
else F.fprintf f "%d%%" (hit * 100 / total) else F.fprintf f "%d%%" (hit * 100 / total)
in in
F.fprintf f let pp_int_field stats f field =
"@[Backend stats:@\n\ F.fprintf f "%s= %d@;" (Field.name field) (Field.get field stats)
@[<v2> summary_file_try_load= %d@;summary_read_from_disk= %d@;summary_cache_hits= %d \ in
(%t)@;summary_cache_misses= %d@;summary_has_model_queries= %d@;@]@]@." let pp_cache_hits stats f cache_hits_field =
summary_file_try_load summary_read_from_disk summary_cache_hits F.fprintf f "%s= %d (%t)@;" (Field.name cache_hits_field) stats.summary_cache_hits
(pp_hit_percent summary_cache_hits summary_cache_misses) (pp_hit_percent stats.summary_cache_hits stats.summary_cache_misses)
summary_cache_misses summary_has_model_queries in
let pp_stats stats f =
Fields.iter ~summary_file_try_load:(pp_int_field stats f)
~summary_read_from_disk:(pp_int_field stats f) ~summary_cache_hits:(pp_cache_hits stats f)
~summary_cache_misses:(pp_int_field stats f)
~summary_has_model_queries:(pp_int_field stats f)
in
F.fprintf f "@[Backend stats:@\n@[<v2> %t@]@]@." (pp_stats stats)
let log_to_scuba stats = let log_to_scuba stats =

Loading…
Cancel
Save