-
Notifications
You must be signed in to change notification settings - Fork 437
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
Added a stepLog API to reduce code duplication. #876
Conversation
Hi @esohel30! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this the right Idea for the steplog API?
Yes, that's the idea :)
Since this would only be used by Pysa, could we move this in source/interprocedural_analysis/taint/stepLogger.ml?
Also, no need to wrap it into a module StepLogger = struct
, since the file is stepLogger.ml
it will automatically be available as a module StepLogger.start/finish
. We module StepLogger = struct
it would stutter, i.e StepLogger.StepLogger.start/finish
.
source/stepLogger.ml
Outdated
|
||
let start ~start_message ~end_message = | ||
let timer = Timer.start () in | ||
Log.info "%s" start_message; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We usually have extra ...
for the first message
Log.info "%s" start_message; | |
Log.info "%s..." start_message; |
source/stepLogger.ml
Outdated
|
||
let finish ~step_logger ~section ~integers () = | ||
let time_in_seconds = Timer.stop_in_sec step_logger.timer in | ||
Log.log ~section "%s: %.3fs" step_logger.end_message time_in_seconds; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we always use Log.info
, no need for section
:)
Log.log ~section "%s: %.3fs" step_logger.end_message time_in_seconds; | |
Log.info "%s: %.3fs" step_logger.end_message time_in_seconds; |
I updated the code according to the feedback. Please review again! |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
Could you now start using this in taintAnalysis.ml
?
This should be in the same PR IMO, as a way to test it. Otherwise we would be pushing code that's never used.
source/stepLogger.ml
Outdated
@@ -0,0 +1,24 @@ | |||
open Core |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you remove source/stepLogger.ml
and .mli
?
Finished adding steplog api to places where applicable in taintAnalysis.ml to reduce code duplication |
Thanks, that's mostly it! |
Co-authored-by: Maxime Arthaud <maxime@arthaud.me>
Co-authored-by: Maxime Arthaud <maxime@arthaud.me>
Co-authored-by: Maxime Arthaud <maxime@arthaud.me>
Co-authored-by: Maxime Arthaud <maxime@arthaud.me>
Co-authored-by: Maxime Arthaud <maxime@arthaud.me>
All feedback has been applied and code is ready for a final review. I double checked but as there is a lot of code I probably missed a thing or two again. Sorry in advanced and thank you for the great feedback! I am really learning a lot and feeling more confident. |
@arthaud has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
~timer | ||
() | ||
in | ||
StepLogger.finish ~step_logger ~integers:[]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't compile, it should be:
StepLogger.finish ~step_logger ~integers:[]; | |
StepLogger.finish ~integers:[] step_logger; |
I will fix it myself so we don't take another week to merge this.
In the future, please run make test
before submitting :)
~name:"Parsed taint models" | ||
~phase_name:"Parsing taint models" | ||
~timer | ||
~integers:["models", Registry.size models; "queries", List.length queries] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should keep this too.
#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?
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!