facebook / pyre-check

Performant type-checking for python.
https://pyre-check.org/
MIT License
6.8k stars 434 forks source link

[pysa][MLH] Add a high level API for step logging #845

Open arthaud opened 4 months ago

arthaud commented 4 months ago

We currently use the following pattern to log a Pysa analysis step (e.g, call graph builting, type checking, etc.):

let timer = Timer.start () in
let () = Log.info "Fetching initial callables to analyze..." in
let initial_callables =
  Interprocedural.FetchCallables.from_qualifiers
    ~scheduler
    ~configuration
    ~pyre_api
    ~include_unit_tests:false
    ~qualifiers
in
Statistics.performance
  ~name:"Fetched initial callables to analyze"
  ~phase_name:"Fetching initial callables to analyze"
  ~timer
  ~integers:(Interprocedural.FetchCallables.get_stats initial_callables)
  ();
initial_callables

For instance: https://github.com/facebook/pyre-check/blob/main/source/interprocedural_analyses/taint/taintAnalysis.ml#L723-L743

It would be better to have a proper API that avoids code duplication:

let step_log = StepLogger.start
  ~start:"Fetching initial callables to analyze"
  ~end:"Fetched initial callables to analyze""
in
(* code of the step *)
let initial_callables =
  Interprocedural.FetchCallables.from_qualifiers
    ~scheduler
    ~configuration
    ~pyre_api
    ~include_unit_tests:false
    ~qualifiers
in
StepLogger.end ~integers:(Interprocedural.FetchCallables.get_stats initial_callables);
initial_callables

This is tracked internally by T184908437.