From 8d410d63c0cdf6797443339660f164d2ff1a68c0 Mon Sep 17 00:00:00 2001 From: Martino Luca Date: Wed, 7 Nov 2018 07:18:23 -0800 Subject: [PATCH] [Infer][Perf] Make reports more human readable Reviewed By: ezgicicek Differential Revision: D12956943 fbshipit-source-id: d94dcaed4 --- infer/src/backend/Differential.ml | 12 +++++++++--- infer/src/bufferoverrun/itv.ml | 20 ++++++++++++++++++++ infer/src/bufferoverrun/itv.mli | 2 ++ 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/infer/src/backend/Differential.ml b/infer/src/backend/Differential.ml index bf5e46a5f..a4c049ab6 100644 --- a/infer/src/backend/Differential.ml +++ b/infer/src/backend/Differential.ml @@ -144,9 +144,15 @@ let issue_of_cost cost_info ~delta ~prev_cost ~curr_cost = | `Increased -> Format.fprintf fmt "increased" in - Format.asprintf "Max degree %a from %a to %a. Cost is %a (degree is %a)" pp_delta delta - CostDomain.BasicCost.pp_degree prev_cost CostDomain.BasicCost.pp_degree curr_cost - CostDomain.BasicCost.pp curr_cost CostDomain.BasicCost.pp_degree curr_cost + let pp_raw_cost fmt cost_polynomial = + if Config.developer_mode then + Format.fprintf fmt " Cost is %a (degree is %a)" CostDomain.BasicCost.pp cost_polynomial + CostDomain.BasicCost.pp_degree cost_polynomial + else () + in + Format.asprintf "Complexity %a from %a to %a.%a" pp_delta delta + CostDomain.BasicCost.pp_degree_hum prev_cost CostDomain.BasicCost.pp_degree_hum curr_cost + pp_raw_cost curr_cost in let line = cost_info.Jsonbug_t.loc.lnum in let column = cost_info.Jsonbug_t.loc.cnum in diff --git a/infer/src/bufferoverrun/itv.ml b/infer/src/bufferoverrun/itv.ml index 776e7d55b..47574e288 100644 --- a/infer/src/bufferoverrun/itv.ml +++ b/infer/src/bufferoverrun/itv.ml @@ -412,6 +412,26 @@ module NonNegativePolynomial = struct Format.pp_print_int fmt (NonNegativeNonTopPolynomial.degree p) + let pp_degree_hum fmt p = + match p with + | Top -> + Format.pp_print_string fmt "Top" + | NonTop p -> ( + match NonNegativeNonTopPolynomial.degree p with + | 0 -> + Format.pp_print_string fmt "constant" + | 1 -> + Format.pp_print_string fmt "linear" + | 2 -> + Format.pp_print_string fmt "quadratic" + | 3 -> + Format.pp_print_string fmt "cubic" + | 4 -> + Format.pp_print_string fmt "quartic" + | d -> + Format.fprintf fmt "O(N^%d)" d ) + + let encode astate = Marshal.to_string astate [] |> B64.encode let decode enc_str = Marshal.from_string (B64.decode enc_str) 0 diff --git a/infer/src/bufferoverrun/itv.mli b/infer/src/bufferoverrun/itv.mli index a0227dcca..e5e230c02 100644 --- a/infer/src/bufferoverrun/itv.mli +++ b/infer/src/bufferoverrun/itv.mli @@ -58,6 +58,8 @@ module NonNegativePolynomial : sig val pp_degree : Format.formatter -> astate -> unit + val pp_degree_hum : Format.formatter -> astate -> unit + val encode : astate -> string val decode : string -> astate