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

Add option for hidden stack frame alignment #22

Merged
merged 8 commits into from
Oct 31, 2018

Conversation

goto-bus-stop
Copy link
Contributor

@goto-bus-stop goto-bus-stop commented Oct 31, 2018

This is a bit tough to explain so I've got words here and images down below 👇

In 0x, hidden stack frames still take up space. That's visible as empty
space between different stacks: one of the stacks is a child of a hidden
stack frame. This is the easiest thing to do d3 wise and has the nice
benefit that stack frames only move vertically when you toggle frame
visibility.

This PR adds a collapseHiddenNodeWidths: true option to change that
behaviour. Hidden stack frames don't take up horizontal space when this
option is set. That means that child stacks of hidden stack frames are
bunched up next to each other without empty space in between. The
benefit of this approach is that, combined with heatBars: true, the
heat bars will be one contiguous block, and the size of this block is
directly proportional to the time that frame was at the top of the stack.
Without this option, heat bars are seen through all the gaps where
hidden stack frames are taking up space, and only the colour is
proportional to the heat.

Visually:

collapseHiddenNodeWidths: false

image
image

Here, the _GI__ frame is a C++ frame. It's a child of a V8 frame. When the V8 frames are hidden, the C++ frame is aligned to the left of the V8 frame it's in, because the other hidden V8 frame widths still push it to the right.

collapseHiddenNodeWidths: true

image
image

With this option enabled, the C++ frame is aligned to the left of the closest visible frame, rather than its direct parent.


This also fixes an unrelated issue that got in the way while testing this, where very narrow stack frames were not drawn at all. Now, very narrow frames are drawn at 1px width.

In 0x, hidden stack frames still take up space. That's visible as empty
space between different stacks: one of the stacks is a child of a hidden
stack frame. This is the easiest thing to do d3 wise and has the nice
benefit that stack frames only move vertically when you toggle frame
visibility.

This PR adds a `collapseHiddenNodeWidths: true` option to change that
behaviour. Hidden stack frames don't take up horizontal space when this
option is set. That means that child stacks of hidden stack frames are
bunched up next to each other without empty space in between. The
benefit of this approach is that, combined with `heatBars: true`, the
heat bars will be one contiguous block, and the size of this block is
directly proportional to the time that frame was at the top of the stack.
Without this option, heat bars are seen through all the gaps where
hidden stack frames are taking up space, and only the colour is
proportional to the heat.

It's quite a mouthful for a fairly small code change...
})
.sort(doSort)

// Make "all stacks" as wide as every visible stack.
data.value = data.children ? data.children.reduce(sumChildValues, 0) : 0
data.value = data.children
? data.children.reduce((acc, node) => acc + node.value, 0)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sumChildValues only accidentally worked here, here we're dealing with d3 node wrappers whereas sumChildValues expects 0x-style node data

Copy link
Contributor

@AlanSl AlanSl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM in terms of feature and functionality.

Just one nit in the readme, and general comment that I don't think this is as niche or edge-case-y an option as you think - our specific reason for needing it now is, but in general it's pretty valid / understandable that some flamegraph users might want there to not be gaps left over from things that are hidden.

readme.md Show resolved Hide resolved
@goto-bus-stop
Copy link
Contributor Author

I don't think this is as niche or edge-case-y an option as you think

Possibly … I guess I just needed a lot of words to make it clear to myself, so I thought it'd maybe be quite difficult to understand for others!

@AlanSl
Copy link
Contributor

AlanSl commented Oct 31, 2018

LGTM

@mcollina mcollina merged commit dffafde into davidmarkclements:master Oct 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants