-
Notifications
You must be signed in to change notification settings - Fork 52
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
[New] saveframe utility #356
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This commit adds a new utility named 'saveframe' in pyflyby. This utility can be used to save information for debugging / reproducing an issue. Usage: If you have a piece of code that is currently failing due to an issue originating from another team's code, and you cannot share your private code as a reproducer, use this utility to save relevant information to a file. Share the generated file with the other team, enabling them to reproduce and diagnose the issue independently. This utility is provided with 2 interfaces: a script and a function. Script location: `pyflyby/bin/saveframe` Function location: `pyflyby.saveframe` (`from pyflyby import saveframe`) For more information on the `savefrane` script, checkout the help message using `pyflyby/bin/saveframe --help` For more information on the `saveframe` function, checkout the doc of `pyflyby.saveframe`.
rakh-deshaw
reviewed
Sep 24, 2024
saharan-deshaw
force-pushed
the
PyInf#12047
branch
from
September 30, 2024 08:01
a652a6c
to
cea69a2
Compare
saharan-deshaw
force-pushed
the
PyInf#12047
branch
from
September 30, 2024 08:22
cea69a2
to
4d52269
Compare
Carreau
approved these changes
Oct 3, 2024
Carreau
reviewed
Oct 3, 2024
rakh-deshaw
approved these changes
Oct 3, 2024
saharan-deshaw
force-pushed
the
PyInf#12047
branch
from
October 3, 2024 14:17
85e9494
to
82ed389
Compare
- Removed f-strings from logger's info and warning - Use sys.last_exc for python 3.12+ - Added some examples in the doc of saveframe function and the script
saharan-deshaw
force-pushed
the
PyInf#12047
branch
from
October 3, 2024 15:15
82ed389
to
455c149
Compare
saharan-deshaw
added a commit
that referenced
this pull request
Oct 18, 2024
Updated README to include info about the newly added saveframe utility (#356)
saharan-deshaw
pushed a commit
to saharan-deshaw/pyflyby
that referenced
this pull request
Dec 10, 2024
**Background:** In deshaw#356, we added a new utility named `saveframe` in Pyflyby, that can be used to save information for debugging / reproducing an issue. **Issue:** The `saveframe` utility saves data as a pickled Python dictionary. Reading this raw data and extracting values of specific variables or metadata fields can be complex. This commit adds a new class named `SaveframeReader`, for reading data saved by the `saveframe` utility. The `SaveframeReader` class provides an easy and efficient way to read the raw data and extract specific items. This class has a user-friendly `repr` for visualizing the data and provides various helpful methods to extract different items. **Usage Example:** **Creating an instance** First, create an instance of this class by passing the path of the file that contains the `saveframe` data. ``` >>> from pyflyby import SaveframeReader >>> reader = SaveframeReader('/path/to/file') ``` **Extracting all available metadata fields** To extract all available metadata fields, use the `SaveframeReader.metadata` property. Example: ``` >>> reader.metadata ['frame_index', 'filename', 'lineno', 'function_name', 'function_qualname', 'function_object', 'module_name', 'code', 'frame_identifier', 'exception_string', 'exception_full_string', 'exception_class_name', 'exception_class_qualname', 'exception_object', 'traceback'] ``` **Extracting all stored local variables** To extract the names of all local variables stored in the frames, use the `SaveframeReader.variables` property. Example: ``` >>> reader.variables { 1: ['var1', 'var2', ...], 2: ['var5', 'var8', 'var9', ...], ... } ``` **Extracting the value of a specific metadata field** To extract the value of a specific metadata field, use the `SaveframeReader.get_metadata` method. Example: ``` >> reader.get_metadata("filename") {1: '/dir1/mod1.py', 2: '/dir2/mod2.py', ...} >> reader.get_metadata("filename", frame_idx=2) '/dir2/mod2.py' >> reader.get_metadata("exception_string") "Error is raised" ``` **Extracting the value of specific local variables** To extract the value of specific local variable(s), use the `SaveframeReader.get_variables` method. Example: ``` >> reader.get_variables('var1') {2: var1_value2, 4: var1_value4} >> reader.get_variables('var1', frame_idx=4) var1_value4 >> reader.get_variables('var2') var2_value3 >> reader.get_variables(['var1', 'var3']) {2: {'var1': var1_value2, 'var3': var3_value2}, 4: {'var1': var1_value4}, 5: {'var3': var3_value5}} >> reader.get_variables(['var1', 'var3'], frame_idx=2) {'var1': var1_value2, 'var3': var3_value2} ``` **NOTE:** Raw data can be extracted using `SaveframeReader.data` property. Request: PyInf#13916
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This commit adds a new utility named 'saveframe' in pyflyby.
This utility can be used to save information for debugging / reproducing an issue.
Usage:
If you have a piece of code that is currently failing due to an issue originating from upstream code, and you cannot share your private code as a reproducer, use this utility to save relevant information to a file. Share the generated file with the upstream team, enabling them to reproduce and diagnose the issue independently.
This utility is provided with 2 interfaces: a script and a function.
Script location:
pyflyby/bin/saveframe
Function location:
pyflyby.saveframe
(from pyflyby import saveframe
)For more information on the
savefrane
script, checkout the help message usingpyflyby/bin/saveframe --help
For more information on the
saveframe
function, checkout the doc ofpyflyby.saveframe
.