Skip to content
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

InformaionScreen can update with the sample_index and sample_unit now. #62

Merged
merged 3 commits into from
Oct 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion flameshow/pprof_parser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def render_detail(self, sample_index: int, sample_unit: str):
)
frame = frame.parent

return Text.assemble(*detail), len(detail)
return Text.assemble(*detail)

def render_title(self) -> str:
return self.display_name
Expand Down
9 changes: 8 additions & 1 deletion flameshow/render/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ async def watch_sample_index(self, sample_index):
self.flamegraph_widget.sample_index = sample_index
self.frame_detail.sample_index = sample_index

if self.show_information_screen:
information_screen = self.query_one("InformaionScreen")
information_screen.sample_index = sample_index

async def watch_view_frame(self, old, new_frame):
logger.debug(
"view info stack changed: old: %s, new: %s",
Expand Down Expand Up @@ -237,7 +241,10 @@ def action_information_screen(self):
else:
self.push_screen(
InformaionScreen(
self.view_frame, self.sample_index, self.sample_unit
self.view_frame,
self.sample_index,
self.sample_unit,
self.profile,
)
)
self.show_information_screen = not self.show_information_screen
Expand Down
40 changes: 27 additions & 13 deletions flameshow/render/framedetail.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,9 +340,7 @@ def compose(self):
FrameStatAll(self.frame, self.profile, self.sample_index),
id="stat-container",
)
content, *_ = self.frame.render_detail(
self.sample_index, self.sample_unit
)
content = self.frame.render_detail(self.sample_index, self.sample_unit)
span_detail = Static(
content,
id="span-detail",
Expand All @@ -363,11 +361,8 @@ def _rerender(self):
except NoMatches:
return
span_stack_container.border_title = self.frame.render_title()
content, height = self.frame.render_detail(
self.sample_index, self.sample_unit
)
content = self.frame.render_detail(self.sample_index, self.sample_unit)
span_detail.update(content)
span_detail.styles.height = height

try:
frame_this_widget = self.query_one("FrameStatThis")
Expand Down Expand Up @@ -402,35 +397,54 @@ class InformaionScreen(Screen):
BINDINGS = [
Binding("escape", "exit_screen", "Close detail screen", show=True),
]
sample_index = reactive(None, init=False)

class InformaionScreenPopped(Message):
pass

def __init__(
self, frame, sample_index, sample_unit, *args, **kwargs
self, frame, sample_index, sample_unit, profile, *args, **kwargs
) -> None:
self.composed = False
super().__init__(*args, **kwargs)
self.frame = frame
self.sample_index = sample_index
self.sample_unit = sample_unit
self.profile = profile

def compose(self):
center_text = "Stack detail information"
yield FlameshowHeader(center_text)
content, height = self.frame.render_detail(
self.sample_index, self.sample_unit
)
content = self.frame.render_detail(self.sample_index, self.sample_unit)
span_detail = Static(
content,
id="span-detail",
)
span_detail.styles.height = height
span_stack_container = VerticalScroll(
span_detail, id="span-stack-container"
)
span_stack_container.border_title = self.frame.render_title()
yield span_stack_container
yield Footer()
self.composed = True

def action_exit_screen(self):
self.post_message(self.InformaionScreenPopped())

def watch_sample_index(self, new_sample_index):
logger.info("sample index change: %s", new_sample_index)
self._rerender()

def _rerender(self):
if not self.composed:
return
content = self.frame.render_detail(self.sample_index, self.sample_unit)
try:
span_detail = self.query_one("#span-detail")
except NoMatches:
logger.warning("Didn't found #span-detail")
return
span_detail.update(content)

@property
def sample_unit(self):
return self.profile.sample_types[self.sample_index].sample_unit
2 changes: 1 addition & 1 deletion tests/test_profile_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ def test_render_detail_when_parent_zero():
s1.line.function.name = "asdf"

detail = s1.render_detail(0, "bytes")
assert " asdf: 0.0B\n , line 0" in detail[0]
assert "asdf: 0.0B" in str(detail)
Loading