[Perf] Add hash to costs report

Reviewed By: mbouaziz

Differential Revision: D9769723

fbshipit-source-id: 56dbf41fe
master
Martino Luca 6 years ago committed by Facebook Github Bot
parent e715d48c12
commit dcdc5ec168

@ -55,6 +55,7 @@ type hum_info = {
} }
type cost_item = { type cost_item = {
hash : string;
loc : loc; loc : loc;
procedure_id : string; procedure_id : string;
polynomial : string; polynomial : string;

@ -127,7 +127,8 @@ let of_reports ~(current_report : Jsonbug_t.report) ~(previous_report : Jsonbug_
~(current_costs : Jsonbug_t.costs_report) ~(previous_costs : Jsonbug_t.costs_report) : t = ~(current_costs : Jsonbug_t.costs_report) ~(previous_costs : Jsonbug_t.costs_report) : t =
let to_map report = let to_map report =
List.fold_left List.fold_left
~f:(fun map issue -> Map.add_multi map ~key:issue.Jsonbug_t.hash ~data:issue) ~f:(fun map (issue : Jsonbug_t.jsonbug) ->
Map.add_multi map ~key:issue.Jsonbug_t.hash ~data:issue )
~init:String.Map.empty report ~init:String.Map.empty report
in in
let fold_aux ~key:_ ~data (left, both, right) = let fold_aux ~key:_ ~data (left, both, right) =

@ -49,9 +49,9 @@ let compute_key (bug_type : string) (proc_name : Typ.Procname.t) (filename : str
String.concat ~sep:"|" [base_filename; simple_procedure_name; bug_type] String.concat ~sep:"|" [base_filename; simple_procedure_name; bug_type]
let compute_hash (severity : string) (bug_type : string) (proc_name : Typ.Procname.t) let compute_hash ~(severity : string) ~(bug_type : string) ~(proc_name : Typ.Procname.t)
(filename : string) (qualifier : string) = ~(file : string) ~(qualifier : string) =
let base_filename = Filename.basename filename in let base_filename = Filename.basename file in
let hashable_procedure_name = Typ.Procname.hashable_name proc_name in let hashable_procedure_name = Typ.Procname.hashable_name proc_name in
let location_independent_qualifier = let location_independent_qualifier =
(* Removing the line,column, and infer temporary variable (e.g., n$67) information from the (* Removing the line,column, and infer temporary variable (e.g., n$67) information from the
@ -309,7 +309,7 @@ module JsonIssuePrinter = MakeJsonListPrinter (struct
; bug_trace= loc_trace_to_jsonbug_record err_data.loc_trace err_key.severity ; bug_trace= loc_trace_to_jsonbug_record err_data.loc_trace err_key.severity
; node_key= Option.map ~f:Procdesc.NodeKey.to_string err_data.node_key ; node_key= Option.map ~f:Procdesc.NodeKey.to_string err_data.node_key
; key= compute_key bug_type proc_name file ; key= compute_key bug_type proc_name file
; hash= compute_hash severity bug_type proc_name file qualifier ; hash= compute_hash ~severity ~bug_type ~proc_name ~file ~qualifier
; dotty= error_desc_to_dotty_string err_key.err_desc ; dotty= error_desc_to_dotty_string err_key.err_desc
; infer_source_loc= json_ml_loc ; infer_source_loc= json_ml_loc
; bug_type_hum= err_key.err_name.IssueType.hum ; bug_type_hum= err_key.err_name.IssueType.hum
@ -353,11 +353,9 @@ module JsonCostsPrinter = MakeJsonListPrinter (struct
else None else None
in in
let cost_item = let cost_item =
{ Jsonbug_t.loc= let file = SourceFile.to_string loc.Location.file in
{ Jsonbug_t.file= SourceFile.to_string loc.Location.file { Jsonbug_t.hash= compute_hash ~severity:"" ~bug_type:"" ~proc_name ~file ~qualifier:""
; lnum= loc.Location.line ; loc= {file; lnum= loc.Location.line; cnum= loc.Location.col; enum= -1}
; cnum= loc.Location.col
; 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 } ; hum }
@ -429,7 +427,7 @@ let pp_custom_of_report fmt report fields =
List.iter ~f:(pp_custom_of_issue fmt) report List.iter ~f:(pp_custom_of_issue fmt) report
let tests_jsonbug_compare bug1 bug2 = let tests_jsonbug_compare (bug1 : Jsonbug_t.jsonbug) (bug2 : Jsonbug_t.jsonbug) =
let open Jsonbug_t in let open Jsonbug_t in
[%compare: string * string * int * string * Caml.Digest.t] [%compare: string * string * int * string * Caml.Digest.t]
(bug1.file, bug1.procedure, bug1.line - bug1.procedure_start_line, bug1.bug_type, bug1.hash) (bug1.file, bug1.procedure, bug1.line - bug1.procedure_start_line, bug1.bug_type, bug1.hash)

@ -34,7 +34,8 @@ let test_diff_keeps_duplicated_hashes =
let hashes_expected = 3 in let hashes_expected = 3 in
let hashes_found = let hashes_found =
List.fold ~init:0 List.fold ~init:0
~f:(fun acc i -> if String.equal i.Jsonbug_t.hash "2" then acc + 1 else acc) ~f:(fun acc (i : Jsonbug_t.jsonbug) ->
if String.equal i.Jsonbug_t.hash "2" then acc + 1 else acc )
diff.introduced diff.introduced
in in
let pp_diff fmt (expected, actual) = let pp_diff fmt (expected, actual) =

@ -47,6 +47,6 @@ let pp_diff_of_string_list = pp_diff_of_list ~pp:Format.pp_print_string
let pp_diff_of_int_list = pp_diff_of_list ~pp:Format.pp_print_int let pp_diff_of_int_list = pp_diff_of_list ~pp:Format.pp_print_int
(* Sort hashes to make things easier to compare *) (* Sort hashes to make things easier to compare *)
let sorted_hashes_of_issues issues = let sorted_hashes_of_issues (issues : Jsonbug_t.report) =
let hash i = i.Jsonbug_t.hash in let hash (i : Jsonbug_t.jsonbug) = i.Jsonbug_t.hash in
List.sort ~compare:String.compare (List.rev_map ~f:hash issues) List.sort ~compare:String.compare (List.rev_map ~f:hash issues)

Loading…
Cancel
Save