Emit human-readable cost info when in developer-mode

Reviewed By: ezgicicek

Differential Revision: D9751207

fbshipit-source-id: c815df543
master
Martino Luca 6 years ago committed by Facebook Github Bot
parent 15bdcca119
commit 37bf7a5039

@ -49,10 +49,16 @@ type json_trace = {
trace : json_trace_item list; trace : json_trace_item list;
} }
type hum_info = {
hum_polynomial : string;
hum_degree : string;
}
type cost_item = { type cost_item = {
loc : loc; loc : loc;
procedure_id : string; procedure_id : string;
polynomial : string; polynomial : string;
?hum : hum_info option;
} }
type costs_report = cost_item list type costs_report = cost_item list

@ -348,6 +348,15 @@ module JsonCostsPrinter = MakeJsonListPrinter (struct
let to_string {loc; proc_name; cost_opt} = let to_string {loc; proc_name; cost_opt} =
match cost_opt with match cost_opt with
| Some {post} -> | Some {post} ->
let hum =
if Config.developer_mode then
Some
{ Jsonbug_t.hum_polynomial= Format.asprintf "%a" CostDomain.BasicCost.pp post
; hum_degree=
Option.value_map ~default:"Top" ~f:string_of_int
(CostDomain.BasicCost.degree post) }
else None
in
let cost_item = let cost_item =
{ Jsonbug_t.loc= { Jsonbug_t.loc=
{ Jsonbug_t.file= SourceFile.to_string loc.Location.file { Jsonbug_t.file= SourceFile.to_string loc.Location.file
@ -355,7 +364,8 @@ module JsonCostsPrinter = MakeJsonListPrinter (struct
; cnum= loc.Location.col ; cnum= loc.Location.col
; enum= -1 } ; enum= -1 }
; procedure_id= Typ.Procname.to_string proc_name ; procedure_id= Typ.Procname.to_string proc_name
; polynomial= CostDomain.BasicCost.encode post } ; polynomial= CostDomain.BasicCost.encode post
; hum }
in in
Some (Jsonbug_j.string_of_cost_item cost_item) Some (Jsonbug_j.string_of_cost_item cost_item)
| None -> | None ->

Loading…
Cancel
Save