Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
arthaud opened this issue May 1, 2024 · 0 comments
Open

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

arthaud opened this issue May 1, 2024 · 0 comments

Comments

@arthaud
Copy link
Contributor

arthaud commented May 1, 2024

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.

@arthaud arthaud changed the title [pysa] Add a high level API for step logging [pysa][MLH] Add a high level API for step logging May 31, 2024
facebook-github-bot pushed a commit that referenced this issue Jun 24, 2024
Summary:
#845

This pull request introduces a new StepLogger API to simplify and standardize the logging and performance measurement process in the Pysa taint analysis codebase. By encapsulating common patterns of starting timers, logging information, and recording performance metrics, this API helps to reduce code duplication and improve maintainability.

Questions:

Is this the right Idea for the steplog API?

![image](https://github.com/facebook/pyre-check/assets/90656205/9458355c-3306-4ccb-b0b7-c3d9360d07bc)

IF this general Idea is correct. Please take  look at the newly created steplog.ml and stepLog.mli file and provide any feedback.

I will then implement the feedback and update the taintAnalysis.ml file and ask for feedback once again!

Pull Request resolved: #876

Reviewed By: tianhan0

Differential Revision: D58945119

Pulled By: arthaud

fbshipit-source-id: 65fcbcbfabce39165ed087880029b726de09ca6c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant