From 37bf7a50390f59dfd7862557e254d30c7c6b709c Mon Sep 17 00:00:00 2001 From: Martino Luca Date: Mon, 10 Sep 2018 10:53:58 -0700 Subject: [PATCH] Emit human-readable cost info when in developer-mode Reviewed By: ezgicicek Differential Revision: D9751207 fbshipit-source-id: c815df543 --- infer/src/atd/jsonbug.atd | 6 ++++++ infer/src/backend/InferPrint.ml | 12 +++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/infer/src/atd/jsonbug.atd b/infer/src/atd/jsonbug.atd index b10afecaa..b1b6d9a53 100644 --- a/infer/src/atd/jsonbug.atd +++ b/infer/src/atd/jsonbug.atd @@ -49,10 +49,16 @@ type json_trace = { trace : json_trace_item list; } +type hum_info = { + hum_polynomial : string; + hum_degree : string; +} + type cost_item = { loc : loc; procedure_id : string; polynomial : string; + ?hum : hum_info option; } type costs_report = cost_item list diff --git a/infer/src/backend/InferPrint.ml b/infer/src/backend/InferPrint.ml index be769c408..da59af690 100644 --- a/infer/src/backend/InferPrint.ml +++ b/infer/src/backend/InferPrint.ml @@ -348,6 +348,15 @@ module JsonCostsPrinter = MakeJsonListPrinter (struct let to_string {loc; proc_name; cost_opt} = match cost_opt with | 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 = { Jsonbug_t.loc= { Jsonbug_t.file= SourceFile.to_string loc.Location.file @@ -355,7 +364,8 @@ module JsonCostsPrinter = MakeJsonListPrinter (struct ; cnum= loc.Location.col ; enum= -1 } ; procedure_id= Typ.Procname.to_string proc_name - ; polynomial= CostDomain.BasicCost.encode post } + ; polynomial= CostDomain.BasicCost.encode post + ; hum } in Some (Jsonbug_j.string_of_cost_item cost_item) | None ->