From 6345198218dbb5ef9b1c3d8cdec52b6d3522501c Mon Sep 17 00:00:00 2001 From: Alex Kassil Date: Thu, 6 Jan 2022 15:11:09 -0800 Subject: [PATCH] Add call graph/overrides performance tracking Summary: Adding performance timers to call graph and overrides Reviewed By: arthaud Differential Revision: D33358207 fbshipit-source-id: 1f4bdbf3757e2a2da6aea931b2f193550186e86e --- source/interprocedural/callGraph.ml | 34 +++++++++++++++-------- source/interprocedural/dependencyGraph.ml | 14 +++++++++- 2 files changed, 36 insertions(+), 12 deletions(-) diff --git a/source/interprocedural/callGraph.ml b/source/interprocedural/callGraph.ml index 7fc6943201d..c69b1f9091b 100644 --- a/source/interprocedural/callGraph.ml +++ b/source/interprocedural/callGraph.ml @@ -1360,6 +1360,7 @@ let call_graph_of_define ~environment ~define:({ Define.signature = { Define.Signature.name; parent; _ }; _ } as define) = + let timer = Timer.start () in let callees_at_location = Location.Table.create () in let module DefineFixpoint = DefineCallGraphFixpoint (struct let global_resolution = TypeEnvironment.ReadOnly.global_resolution environment @@ -1388,17 +1389,28 @@ let call_graph_of_define in DefineFixpoint.forward ~cfg:(Cfg.create define) ~initial:() |> ignore; - Location.Table.to_alist callees_at_location - |> List.map ~f:(fun (location, unprocessed_callees) -> - match String.Map.Tree.to_alist unprocessed_callees with - | [] -> failwith "unreachable" - | [(_, callees)] -> - location, LocationCallees.Singleton (ExpressionCallees.deduplicate callees) - | _ -> - ( location, - LocationCallees.Compound - (Core.String.Map.Tree.map ~f:ExpressionCallees.deduplicate unprocessed_callees) )) - |> Location.Map.of_alist_exn + let call_graph = + Location.Table.to_alist callees_at_location + |> List.map ~f:(fun (location, unprocessed_callees) -> + match String.Map.Tree.to_alist unprocessed_callees with + | [] -> failwith "unreachable" + | [(_, callees)] -> + location, LocationCallees.Singleton (ExpressionCallees.deduplicate callees) + | _ -> + ( location, + LocationCallees.Compound + (Core.String.Map.Tree.map ~f:ExpressionCallees.deduplicate unprocessed_callees) )) + |> Location.Map.of_alist_exn + in + Statistics.performance + ~randomly_log_every:1000 + ~always_log_time_threshold:1.0 (* Seconds *) + ~name:"Call graph built" + ~section:`DependencyGraph + ~normals:["callable", Reference.show name] + ~timer + (); + call_graph module SharedMemory = struct diff --git a/source/interprocedural/dependencyGraph.ml b/source/interprocedural/dependencyGraph.ml index d59c42da8a0..814258583d4 100644 --- a/source/interprocedural/dependencyGraph.ml +++ b/source/interprocedural/dependencyGraph.ml @@ -220,6 +220,7 @@ let create_overrides ~environment ~source = if GlobalResolution.source_is_unit_test resolution ~source then Reference.Map.empty else + let timer = Timer.start () in let class_method_overrides { Node.value = { Class.body; name = class_name; _ }; _ } = let get_method_overrides child_method = let method_name = Define.unqualified_name child_method in @@ -247,7 +248,18 @@ let create_overrides ~environment ~source = | { Node.value = Statement.Define define; _ } -> Some define | _ -> None in - body |> List.filter_map ~f:extract_define |> List.filter_map ~f:get_method_overrides + let overrides = + body |> List.filter_map ~f:extract_define |> List.filter_map ~f:get_method_overrides + in + Statistics.performance + ~randomly_log_every:1000 + ~always_log_time_threshold:1.0 (* Seconds *) + ~name:"Overrides built" + ~section:`DependencyGraph + ~normals:["class", Reference.show class_name] + ~timer + (); + overrides in let record_overrides map (ancestor_method, overriding_type) = let update_types = function