Repository navigation
gh-159560: Add a command-line interface to tracemalloc - #159563
Open
vadim-smal wants to merge 2 commits into
Open
vadim-smal wants to merge 2 commits into
vadim-smal wants to merge 2 commits into
Conversation
Documentation build overview
4 files changed± library/cmdline.html± library/tracemalloc.html± whatsnew/3.16.html± whatsnew/changelog.html |
This file contains hidden or 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
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.
Why make this change
Today, to check memory allocations of a script with
tracemallocyou have to modify the script itself. This addspython -m tracemalloc, so it can be used the same way ascProfile, without touching the code. Discussed in https://discuss.python.org/t/run-tracemalloc-module-as-a-script/50821.What will change
_main()toLib/tracemalloc.pywith options-o,-t,--cumulative,-n,-land-mrunpy, sosys.argv,__name__andsys.path[0]are the same as when it runs directly. Directories and zip files work toorunpy/tracemallocframes from the tracebacks, so--cumulativeand-t tracebackshow only the frames of the traced program-X tracemallocorPYTHONTRACEMALLOC, otherwise-nis silently ignored-o, dumped snapshots usetracemalloc.Snapshot( not__main__.Snapshot), so they can be loaded withSnapshot.load()Known limitations, same as
cProfile:-mmodule raisesImportErrorwith a traceback. Checking it before tracing would import its parent packages untraced--right after the target is removed byargparse( same inprofiling.sampling)