[Perf] Emit costs to a separate file named costs-report.json

Reviewed By: mbouaziz

Differential Revision: D9337974

fbshipit-source-id: 392410736
master
Martino Luca 6 years ago committed by Facebook Github Bot
parent 04af716fba
commit 55c2188615

@ -51,3 +51,12 @@ type report = jsonbug list
type json_trace = { type json_trace = {
trace : json_trace_item list; trace : json_trace_item list;
} }
type cost_item = {
loc : loc;
procedure_id : string;
polynomial : string;
}
type costs_report = cost_item list

@ -342,8 +342,31 @@ module IssuesJson = struct
err_log err_log
end end
type json_costs_printer_typ =
{loc: Location.t; proc_name: Typ.Procname.t; cost_opt: CostDomain.summary option}
module JsonCostsPrinter = MakeJsonListPrinter (struct
type elt = json_costs_printer_typ
let to_string {loc; proc_name; cost_opt} =
match cost_opt with
| Some {post} ->
let cost_item =
{ Jsonbug_t.loc=
{ Jsonbug_t.file= SourceFile.to_string loc.Location.file
; lnum= loc.Location.line
; cnum= loc.Location.col
; enum= -1 }
; procedure_id= Typ.Procname.to_string proc_name
; polynomial= CostDomain.BasicCost.encode post }
in
Some (Jsonbug_j.string_of_cost_item cost_item)
| None ->
None
end)
let pp_custom_of_report fmt report fields = let pp_custom_of_report fmt report fields =
let pp_custom_of_issue fmt issue = let pp_custom_of_issue fmt (issue: Jsonbug_t.jsonbug) =
let open Jsonbug_t in let open Jsonbug_t in
let comma_separator index = if index > 0 then ", " else "" in let comma_separator index = if index > 0 then ", " else "" in
let pp_trace fmt trace comma = let pp_trace fmt trace comma =
@ -698,9 +721,11 @@ let error_filter filters proc_name file error_name =
&& filters.Inferconfig.proc_filter proc_name && filters.Inferconfig.proc_filter proc_name
type report_kind = Issues | Procs | Stats | Summary [@@deriving compare] type report_kind = Costs | Issues | Procs | Stats | Summary [@@deriving compare]
let _string_of_report_kind = function let _string_of_report_kind = function
| Costs ->
"Costs"
| Issues -> | Issues ->
"Issues" "Issues"
| Procs -> | Procs ->
@ -824,10 +849,31 @@ let pp_summary summary =
summary summary
let pp_costs_in_format (format_kind, (outfile_opt: Utils.outfile option)) =
match format_kind with
| Json ->
let outf = get_outfile outfile_opt in
JsonCostsPrinter.pp outf.fmt
| Csv | Tests | Text | Logs ->
L.(die InternalError) "Printing costs in csv/tests/text/logs is not implemented"
let pp_costs summary costs_format_list =
let pp format =
pp_costs_in_format format
{ loc= Summary.get_loc summary
; proc_name= Summary.get_proc_name summary
; cost_opt= summary.Summary.payloads.Payloads.cost }
in
List.iter ~f:pp costs_format_list
let pp_summary_by_report_kind formats_by_report_kind summary error_filter linereader stats file let pp_summary_by_report_kind formats_by_report_kind summary error_filter linereader stats file
issues_acc = issues_acc =
let pp_summary_by_report_kind (report_kind, format_list) = let pp_summary_by_report_kind (report_kind, format_list) =
match (report_kind, format_list) with match (report_kind, format_list) with
| Costs, _ ->
pp_costs summary format_list
| Procs, _ :: _ -> | Procs, _ :: _ ->
pp_procs summary format_list pp_procs summary format_list
| Stats, _ :: _ -> | Stats, _ :: _ ->
@ -976,10 +1022,17 @@ let init_files format_list_by_kind =
| Csv, Stats -> | Csv, Stats ->
let outfile = get_outfile outfile_opt in let outfile = get_outfile outfile_opt in
Report.pp_header outfile.fmt () Report.pp_header outfile.fmt ()
| Json, Costs ->
let outfile = get_outfile outfile_opt in
JsonCostsPrinter.pp_open outfile.fmt ()
| Json, Issues -> | Json, Issues ->
let outfile = get_outfile outfile_opt in let outfile = get_outfile outfile_opt in
IssuesJson.pp_open outfile.fmt () IssuesJson.pp_open outfile.fmt ()
| Csv, Summary | Logs, Stats | Json, (Procs | Stats | Summary) | Tests, _ | Text, _ -> | Csv, (Costs | Summary)
| Logs, (Costs | Stats)
| Json, (Procs | Stats | Summary)
| Tests, _
| Text, _ ->
() ()
in in
List.iter ~f:init_files_of_format format_list List.iter ~f:init_files_of_format format_list
@ -996,11 +1049,14 @@ let finalize_and_close_files format_list_by_kind (stats: Stats.t) =
| Csv, Stats -> | Csv, Stats ->
let outfile = get_outfile outfile_opt in let outfile = get_outfile outfile_opt in
F.fprintf outfile.fmt "%a@?" Report.pp_stats stats F.fprintf outfile.fmt "%a@?" Report.pp_stats stats
| Json, Costs ->
let outfile = get_outfile outfile_opt in
JsonCostsPrinter.pp_close outfile.fmt ()
| Json, Issues -> | Json, Issues ->
let outfile = get_outfile outfile_opt in let outfile = get_outfile outfile_opt in
IssuesJson.pp_close outfile.fmt () IssuesJson.pp_close outfile.fmt ()
| Csv, (Issues | Procs | Summary) | Csv, (Costs | Issues | Procs | Summary)
| Logs, Stats | Logs, (Costs | Stats)
| Json, (Procs | Stats | Summary) | Json, (Procs | Stats | Summary)
| Tests, _ | Tests, _
| Text, _ -> | Text, _ ->
@ -1046,10 +1102,19 @@ let register_perf_stats_report () =
let main ~report_json = let main ~report_json =
let issue_formats = init_issues_format_list report_json in let issue_formats = init_issues_format_list report_json in
let formats_by_report_kind = let formats_by_report_kind =
[ (Issues, issue_formats) let costs_report_format_kind =
; (Procs, init_procs_format_list ()) match report_json with
; (Stats, init_stats_format_list ()) | Some _ ->
; (Summary, []) ] let file = Config.(results_dir ^/ Config.costs_report_json) in
[(Costs, mk_format Json file)]
| None ->
[]
in
costs_report_format_kind
@ [ (Issues, issue_formats)
; (Procs, init_procs_format_list ())
; (Stats, init_stats_format_list ())
; (Summary, []) ]
in in
register_perf_stats_report () ; register_perf_stats_report () ;
init_files formats_by_report_kind ; init_files formats_by_report_kind ;

@ -168,6 +168,8 @@ let clang_inner_destructor_prefix = "__infer_inner_destructor_"
let classnames_dir_name = "classnames" let classnames_dir_name = "classnames"
let costs_report_json = "costs-report.json"
(** Experimental: if true do some specialized analysis of concurrent constructs. *) (** Experimental: if true do some specialized analysis of concurrent constructs. *)
let csl_analysis = true let csl_analysis = true

@ -80,6 +80,8 @@ val classnames_dir_name : string
val classpath : string option val classpath : string option
val costs_report_json : string
val cpp_extra_include_dir : string val cpp_extra_include_dir : string
val driver_stats_dir_name : string val driver_stats_dir_name : string

@ -392,6 +392,9 @@ module NonNegativePolynomial = struct
let degree p = let degree p =
match p with Top -> None | NonTop p -> Some (NonNegativeNonTopPolynomial.degree p) match p with Top -> None | NonTop p -> Some (NonNegativeNonTopPolynomial.degree p)
let encode astate = Marshal.to_string astate [] |> B64.encode
end end
module ItvRange = struct module ItvRange = struct

@ -54,6 +54,8 @@ module NonNegativePolynomial : sig
val subst : astate -> Bound.t bottom_lifted SymbolMap.t -> astate val subst : astate -> Bound.t bottom_lifted SymbolMap.t -> astate
val degree : astate -> int option val degree : astate -> int option
val encode : astate -> string
end end
module ItvRange : sig module ItvRange : sig

Loading…
Cancel
Save