Skip to content

Commit

Permalink
Hide IPython internal frame by default.
Browse files Browse the repository at this point in the history
This should help with joerick#313

In most case it should have no effects as anyway all the root of the
tree is removed as there is no time spent in it. Though with some
compiled code and threads, some time may be affected to the root.
  • Loading branch information
Carreau committed Jul 29, 2024
1 parent b364e53 commit dba6761
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
13 changes: 13 additions & 0 deletions pyinstrument/processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,3 +294,16 @@ def is_runpy_frame(frame: Frame):
result.remove_from_parent()

return result


def group_ipython_frames_processor(frame, options: ProcessorOptions) -> Frame | None:
"""
In some case the IPython's magic show all the internal IPython frames, which makes
traces hard to read.
This will collapse most of IPython internal frames.
"""
return group_library_frames_processor(
frame,
{"hide_regex": ".+((IPython)|(ipykernel.zmqshell)|(pyinstrument.magic.magic))"},
)
1 change: 1 addition & 0 deletions pyinstrument/renderers/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ def default_processors(self) -> ProcessorList:
processors.remove_irrelevant_nodes,
processors.remove_first_pyinstrument_frames_processor,
processors.group_library_frames_processor,
processors.group_ipython_frames_processor,
]

class colors_enabled:
Expand Down
1 change: 1 addition & 0 deletions pyinstrument/renderers/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,5 @@ def default_processors(self) -> ProcessorList:
processors.remove_irrelevant_nodes,
processors.remove_first_pyinstrument_frames_processor,
processors.group_library_frames_processor,
processors.group_ipython_frames_processor,
]
5 changes: 5 additions & 0 deletions pyinstrument/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ def root_frame(self, trim_stem: bool = True) -> Frame | None:
if trim_stem:
root_frame = self._trim_stem(root_frame)

group_library_frames_processor(
root_frame,
{"hide_regex": ".+((IPython)|(ipykernel.zmqshell)|(pyinstrument.magic.magic))"},
)

return root_frame

def _trim_stem(self, frame: Frame):
Expand Down

0 comments on commit dba6761

Please sign in to comment.