Skip to content

Commit ff3c545

Browse files
committed
Rename flamegraph "Invert" button
We've adding a `--inverted` mode to `memray flamegraph` causing stacks to be added to the flame graph in reverse order, so that the children of the root are functions that performed allocations and the leaves are thread entry points. Because of this change, we need a different name for the "Invert" button that flips the entire flame graph upside down. This commit introduces a new toggle button for switching between our default "icicle graph" view (with the root at the top and allocations dangling from it) and the traditional "flame graph" view (with the root at the bottom and allocations rising up from it). The toggle button also gives a visual indication of what mode you're in. Signed-off-by: Matt Wozniski <[email protected]>
1 parent bb9c0db commit ff3c545

10 files changed

+54
-18
lines changed
5.15 KB
Loading

docs/_static/images/invert_button.png

-1.37 KB
Binary file not shown.

docs/flamegraph.rst

+17-12
Original file line numberDiff line numberDiff line change
@@ -196,19 +196,24 @@ checkbox:
196196
Note that allocations in these frames will still be accounted for
197197
in parent frames, even if they're hidden.
198198

199-
Inverted View
200-
-----------------
201-
202-
Although the flame graphs explained above show the calling functions below
203-
and memory allocating functions above, flame graphs can be inverted
204-
so that the calling functions are at the top, while memory allocating
205-
functions are at the bottom. In this view, look for wide ceilings
206-
instead of wide plateaus to find functions with the largest allocation
207-
of memory.
208-
209-
To invert the flame graph, press the *Invert* button:
199+
Flames versus Icicles
200+
---------------------
210201

211-
.. image:: _static/images/invert_button.png
202+
The flame graphs explained above show each function above its caller,
203+
with the root at the bottom. This is what's traditionally called
204+
a "flame graph", because the wide base with narrowing columns above it
205+
looks sort of like a burning log with flames leaping into the air above
206+
it. Memray also supports what's sometimes called an "icicle graph",
207+
which has the root at the top. In an icicle graph, each function is
208+
below its caller, and there is a wide ceiling that thinner columns
209+
descend from, like icicles hanging from a roof. Whichever of these modes
210+
you choose, the data shown in the table is the same, just mirrored
211+
vertically.
212+
213+
You can switch between showing a flame graph and an icicle graph with
214+
this toggle button:
215+
216+
.. image:: _static/images/icicle_flame_toggle.png
212217
:align: center
213218

214219
.. _memory-leaks-view:

src/memray/reporters/assets/flamegraph.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ function main() {
7777
}
7878

7979
// Setup event handlers
80-
document.getElementById("invertButton").onclick = onInvert;
80+
document.getElementById("icicles").onchange = onInvert;
81+
document.getElementById("flames").onchange = onInvert;
8182
document.getElementById("resetZoomButton").onclick = onResetZoom;
8283
document.getElementById("resetThreadFilterItem").onclick = onFilterThread;
8384
let hideUninterestingCheckBox = document.getElementById("hideUninteresting");

src/memray/reporters/assets/flamegraph_common.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export function handleFragments() {
7575

7676
// For the invert button
7777
export function onInvert() {
78-
chart.inverted(!chart.inverted());
78+
chart.inverted(this === document.getElementById("icicles"));
7979
chart.resetZoom(); // calls onClick
8080
}
8181

src/memray/reporters/assets/temporal_flamegraph.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,8 @@ function main() {
323323
}
324324

325325
// Setup event handlers
326-
document.getElementById("invertButton").onclick = onInvert;
326+
document.getElementById("icicles").onchange = onInvert;
327+
document.getElementById("flames").onchange = onInvert;
327328
document.getElementById("resetZoomButton").onclick = onResetZoom;
328329
document.getElementById("resetThreadFilterItem").onclick = onFilterThread;
329330
let hideUninterestingCheckBox = document.getElementById("hideUninteresting");

src/memray/reporters/templates/assets/flamegraph.css

+8
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,11 @@
8888
background-color: rgba(0, 0, 0, 0.5); /* semi-transparent black */
8989
z-index: 99; /* make sure it's on top of other elements */
9090
}
91+
92+
.flamegraph-icon {
93+
display: flex;
94+
align-items: center;
95+
justify-content: center;
96+
}
97+
98+
.flipped svg { transform: scale(1,-1); }

src/memray/reporters/templates/assets/flamegraph.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/memray/reporters/templates/assets/temporal_flamegraph.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/memray/reporters/templates/flamegraph.html

+22-1
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,29 @@
2121
title="Hide frames related to the Python import system" >
2222
<label class="form-check-label text-white bg-dark">Hide Import System Frames</label>
2323
</div>
24+
<div class="btn-group btn-group-toggle mr-3" data-toggle="buttons">
25+
<label class="btn btn-outline-light shadow-none">
26+
<input type="radio" name="flames/icicles" id="flames" autocomplete="off">
27+
<div class="flamegraph-icon flipped">
28+
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" stroke-width="1" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
29+
<path d="M 1 1 h 22 Z M 11 6 h 10 Z M 1 6 h 7 Z M 11 11 h 7 Z M 1 11 h 4 Z M 11 16 h 4 Z M 1 16 h 2 Z M 11 21 h 2 Z"/>
30+
</svg>
31+
</div>
32+
&nbsp;
33+
Flames
34+
</label>
35+
<label class="btn btn-outline-light active shadow-none">
36+
<input type="radio" name="flames/icicles" id="icicles" autocomplete="off" checked/>
37+
Icicles
38+
&nbsp;
39+
<div class="flamegraph-icon">
40+
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" stroke-width="1" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
41+
<path d="M 1 1 h 22 Z M 11 6 h 10 Z M 1 6 h 7 Z M 11 11 h 7 Z M 1 11 h 4 Z M 11 16 h 4 Z M 1 16 h 2 Z M 11 21 h 2 Z"/>
42+
</svg>
43+
</div>
44+
</label>
45+
</div>
2446
<button id="resetZoomButton" class="btn btn-outline-light mr-3">Reset Zoom</button>
25-
<button id="invertButton" class="btn btn-outline-light mr-3">Invert</button>
2647
{% endblock %}
2748

2849
{% block content %}

0 commit comments

Comments
 (0)