Skip to content

Commit cbc0851

Browse files
gh-138122: Improve bytecode panel (#142910)
The bytecode panel appears when a user generates a heatmap with --opcodes and clicks the button to unfold a line and display the bytecode instructions. Currently, an empty space appears on the left where the line number, self, and total columns are displayed. This area should instead extend those columns, rather than leaving a gap.
1 parent 8b64dd8 commit cbc0851

File tree

3 files changed

+91
-10
lines changed

3 files changed

+91
-10
lines changed

Lib/profiling/sampling/_heatmap_assets/heatmap.css

Lines changed: 73 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,6 +1141,10 @@
11411141
.line-samples-cumulative {
11421142
padding: 0 4px;
11431143
}
1144+
1145+
.bytecode-panel {
1146+
margin: 8px 10px 8px 160px;
1147+
}
11441148
}
11451149

11461150
.bytecode-toggle {
@@ -1172,13 +1176,77 @@
11721176
}
11731177

11741178
.bytecode-panel {
1175-
margin-left: 90px;
1176-
padding: 8px 15px;
1177-
background: var(--bg-secondary);
1178-
border-left: 3px solid var(--accent);
1179+
background: var(--bg-primary);
1180+
border: 1px solid var(--border);
1181+
border-radius: 8px;
1182+
box-shadow: var(--shadow-md);
11791183
font-family: var(--font-mono);
11801184
font-size: 12px;
1181-
margin-bottom: 4px;
1185+
color: var(--text-primary);
1186+
line-height: 1.5;
1187+
word-wrap: break-word;
1188+
overflow-wrap: break-word;
1189+
padding: 0;
1190+
margin: 8px 10px 8px 250px;
1191+
position: relative;
1192+
z-index: 1;
1193+
overflow-y: auto;
1194+
max-height: 500px;
1195+
flex: 1;
1196+
transition: padding 0.3s cubic-bezier(0.4, 0, 0.2, 1);
1197+
}
1198+
1199+
.bytecode-panel.expanded {
1200+
padding: 14px;
1201+
}
1202+
1203+
.bytecode-wrapper {
1204+
position: relative;
1205+
display: flex;
1206+
overflow: visible;
1207+
max-height: 0;
1208+
opacity: 0;
1209+
transition: max-height 0.4s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s ease-in-out;
1210+
}
1211+
1212+
.bytecode-wrapper.expanded {
1213+
max-height: 600px;
1214+
opacity: 1;
1215+
transition: max-height 0.5s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.4s ease-in-out;
1216+
}
1217+
1218+
/* Column backdrop matching table header columns (line/self/total) */
1219+
.bytecode-columns {
1220+
display: none;
1221+
position: absolute;
1222+
left: 0;
1223+
overflow: hidden;
1224+
pointer-events: none;
1225+
z-index: 0;
1226+
}
1227+
1228+
.bytecode-wrapper.expanded .bytecode-columns {
1229+
display: flex;
1230+
top: 0;
1231+
bottom: 0;
1232+
}
1233+
1234+
.bytecode-panel::-webkit-scrollbar {
1235+
width: 8px;
1236+
}
1237+
1238+
.bytecode-panel::-webkit-scrollbar-track {
1239+
background: var(--bg-secondary);
1240+
border-radius: 4px;
1241+
}
1242+
1243+
.bytecode-panel::-webkit-scrollbar-thumb {
1244+
background: var(--border);
1245+
border-radius: 4px;
1246+
}
1247+
1248+
.bytecode-panel::-webkit-scrollbar-thumb:hover {
1249+
background: var(--text-muted);
11821250
}
11831251

11841252
/* Specialization summary bar */

Lib/profiling/sampling/_heatmap_assets/heatmap.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -542,20 +542,23 @@ function toggleBytecode(button) {
542542
const lineId = lineDiv.id;
543543
const lineNum = lineId.replace('line-', '');
544544
const panel = document.getElementById(`bytecode-${lineNum}`);
545+
const wrapper = document.getElementById(`bytecode-wrapper-${lineNum}`);
545546

546-
if (!panel) return;
547+
if (!panel || !wrapper) return;
547548

548-
const isExpanded = panel.style.display !== 'none';
549+
const isExpanded = panel.classList.contains('expanded');
549550

550551
if (isExpanded) {
551-
panel.style.display = 'none';
552+
panel.classList.remove('expanded');
553+
wrapper.classList.remove('expanded');
552554
button.classList.remove('expanded');
553555
button.innerHTML = '▶'; // Right arrow
554556
} else {
555557
if (!panel.dataset.populated) {
556558
populateBytecodePanel(panel, button);
557559
}
558-
panel.style.display = 'block';
560+
panel.classList.add('expanded');
561+
wrapper.classList.add('expanded');
559562
button.classList.add('expanded');
560563
button.innerHTML = '▼'; // Down arrow
561564
}

Lib/profiling/sampling/heatmap_collector.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -978,7 +978,17 @@ def _build_line_html(self, line_num: int, line_content: str,
978978
f'data-spec-pct="{spec_pct}" '
979979
f'onclick="toggleBytecode(this)" title="Show bytecode">&#9654;</button>'
980980
)
981-
bytecode_panel_html = f' <div class="bytecode-panel" id="bytecode-{line_num}" style="display:none;"></div>\n'
981+
# Wrapper contains columns + content panel
982+
bytecode_panel_html = (
983+
f' <div class="bytecode-wrapper" id="bytecode-wrapper-{line_num}">\n'
984+
f' <div class="bytecode-columns">'
985+
f'<div class="line-number"></div>'
986+
f'<div class="line-samples-self"></div>'
987+
f'<div class="line-samples-cumulative"></div>'
988+
f'</div>\n'
989+
f' <div class="bytecode-panel" id="bytecode-{line_num}"></div>\n'
990+
f' </div>\n'
991+
)
982992
elif self.opcodes_enabled:
983993
# Add invisible spacer to maintain consistent indentation when opcodes are enabled
984994
bytecode_btn_html = '<div class="bytecode-spacer"></div>'

0 commit comments

Comments
 (0)