-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
gh-125855: pstats.Stats: Allow sorting/filtering by caller/callee #125856
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
base: main
Are you sure you want to change the base?
Conversation
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
Lib/pstats.py
Outdated
| if isinstance(callers_sort_key, str): | ||
| callers_sort_key = (callers_sort_key,) | ||
| sort_tuple, sort_type = self.get_sort_tuple_and_type(*callers_sort_key) | ||
| print(" Callers ordered by: " + sort_type + "\n") |
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.
Does it have to be preceded by a space?
print(f"Callers ordered by: {sort_type}")
(print default line break)
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.
-
Yes, it matches indentation with the lines printed before it. See below.
-
I prefer f-strings but thought it would be better to follow existing style. Should I use f-strings anyway?
-
Existing output style puts a blank line before the call heading below, like:
Ordered by: internal time List reduced from 965 to 1 due to restriction <'\\(has\\)'> Callers ordered by: internal time Function was called by... [...]I can replace the
'\n'with aprint()if that is better?The blank line before "Callers" I would like to remove but that would require more mostly-unrelated changes.
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.
Any opinion on my changes to this?
|
@Zannick Please don't force push, it makes reviewing much more difficult. Everything is squash merged at the end. |
Sorry, thought it would be okay to amend a whitespace issue out of the last commit within a few minutes. Bad habit, I admit. |
This PR adds new keyword arguments
callers_sort_keyandcallers_filtertopstats.Stats.print_callers, and similar topstats.Stats.print_callees, and documents them in the profiling doc. The sorting and filtering are accomplished via use of similar code inpstats.Stats, now refactored to be shared, though unlikesort_statsthe sorting is not sticky.This produces something like:
📚 Documentation preview 📚: https://cpython-previews--125856.org.readthedocs.build/
print_callersandprint_callees#125855