Skip to content

Commit

Permalink
Console renderer: dont bother printing groups with 0 or 1 hidden frames
Browse files Browse the repository at this point in the history
  • Loading branch information
joerick committed Oct 7, 2024
1 parent 17ce4c4 commit d9a084b
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions pyinstrument/renderers/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,26 @@ def render_preamble(self, session: Session) -> str:
return "\n".join(lines)

def should_render_frame(self, frame: Frame) -> bool:
if not frame.group:
return True
if frame.group and not self.should_ignore_group(frame.group):
return self.should_render_frame_in_group(frame)
return True

def should_render_frame_in_group(self, frame: Frame) -> bool:
# Only render the root frame, or frames that are significant
if (
assert frame.group
return (
frame.group.root == frame
or frame.total_self_time > 0.2 * self.root_frame.time
or frame in frame.group.exit_frames
):
return True
return False
)

def should_ignore_group(self, group: FrameGroup) -> bool:
"""
If a group is ignored, its frames are all printed - they're not hidden.
"""
hidden_frames = [f for f in group.frames if not self.should_render_frame_in_group(f)]
# don't bother printing groups with one/zero hidden frames
return len(hidden_frames) < 2

def group_description(self, group: FrameGroup) -> str:
hidden_frames = [f for f in group.frames if not self.should_render_frame(f)]
Expand Down Expand Up @@ -156,7 +166,11 @@ def render_frame(self, frame: Frame, indent: str = "", child_indent: str = "") -
else:
indents = {"├": "|- ", "│": "| ", "└": "`- ", " ": " "}

if frame.group and frame.group.root == frame:
if (
frame.group
and frame.group.root == frame
and not self.should_ignore_group(frame.group)
):
result += f"{child_indent} {self.group_description(frame.group)}"
for key in indents:
indents[key] = " "
Expand Down

0 comments on commit d9a084b

Please sign in to comment.